audioplayers
audioplayers copied to clipboard
[Android] Error when pausing/stopping media player in API 23
Checklist
- [X] I read the troubleshooting guide before raising this issue
- [X] 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
- Play an audio file in loop mode.
- 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
I discovered that if I use lowLatency Player Mode it works well.
audioPlayer?.setPlayerMode(PlayerMode.lowLatency);
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.
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.
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.