Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Error when pausing/stopping media player in API 23 #1714

Open
2 tasks done
marc7garcia opened this issue Nov 27, 2023 · 4 comments
Open
2 tasks done

[Android] Error when pausing/stopping media player in API 23 #1714

marc7garcia opened this issue Nov 27, 2023 · 4 comments
Labels
bug platform-android Affects the android platform

Comments

@marc7garcia
Copy link

Checklist

  • I read the troubleshooting guide before raising this issue
  • I made sure that the issue I am raising doesn't already exist

Current bug behaviour

In API 23, when I pause or stop Media Player running with loop mode, I get the next error and player never stops:

E/MediaPlayer( 3828): pause called in state 8
E/MediaPlayer( 3828): error (-38, 0)
E/MediaPlayer( 3828): Attempt to call getDuration without a valid mediaplayer
E/MediaPlayer( 3828): error (-38, 0)
E/MediaPlayer( 3828): Attempt to call getDuration without a valid mediaplayer
E/MediaPlayer( 3828): error (-38, 0)
E/MediaPlayer( 3828): Attempt to perform seekTo in wrong state: mPlayer=0x7654172180, mCurrentState=0
E/MediaPlayer( 3828): error (-38, 0)
E/MediaPlayer( 3828): Error (-38,0)
E/MediaPlayer( 3828): Error (-38,0)
E/MediaPlayer( 3828): Error (-38,0)
E/MediaPlayer( 3828): Error (-38,0)
I/flutter ( 3828): AudioPlayers Exception: AudioPlayerException(
I/flutter ( 3828): AssetSource(path: sounds/alert.mp3),
I/flutter ( 3828): PlatformException(AndroidAudioError, MEDIA_ERROR_UNKNOWN {what:-38}, MEDIA_ERROR_UNKNOWN {extra:0}, null)

Expected behaviour

Stop playing audio in API 23. It works well in API < 23.

Steps to reproduce

  1. Play an audio file in loop mode.
  2. Stop/pause Media Player.

Code sample

Code sample
audioPlayer = AudioPlayer();
await audioPlayer?.setSource(AssetSource(soundPath));
audioPlayer?.setReleaseMode(ReleaseMode.loop);
...
audioPlayer?.resume();
...
audioPlayer?.stop();

Affected platforms

Android

Platform details

Android 6 (API 23), Android Emulator

AudioPlayers Version

5.2.1

Build mode

debug

Audio Files/URLs/Sources

No response

Screenshots

No response

Logs

No response

Related issues / more information

No response

Working on PR

no way

@marc7garcia
Copy link
Author

I discovered that if I use lowLatency Player Mode it works well.

audioPlayer?.setPlayerMode(PlayerMode.lowLatency);

@newproplus
Copy link

newproplus commented Dec 18, 2023

I use Android 12, and audioplayers has the same issue. it works, thankyou @marc7garcia .
But for long media files or streams, lowLatency has some limitations.

@BirgitPohl
Copy link

BirgitPohl commented Jan 26, 2024

I get the same error. Not running it in loop mode. But simply re-initiating the player and setting a different source.
Running on Android 14.

So, I simply call _audioPlayer.setSourceUrl(_currentAudioLesson.audioUrl!);

audioPlayer?.setPlayerMode(PlayerMode.lowLatency);

It seems, this causes trouble with audio position and audio duration. The values are 0 when I use this line.

@Gustl22 Gustl22 added the platform-android Affects the android platform label Mar 24, 2024
@Gustl22
Copy link
Collaborator

Gustl22 commented Mar 24, 2024

Thank you for the report. It is hard for us to support all devices. We're happy if you could help us fix this. Keep in mind, that we're currently working on using Exoplayer instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug platform-android Affects the android platform
Projects
None yet
Development

No branches or pull requests

4 participants