bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
2k stars 844 forks source link

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

Open marc7garcia opened 10 months ago

marc7garcia commented 10 months ago

Checklist

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 ```dart 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 commented 10 months ago

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

audioPlayer?.setPlayerMode(PlayerMode.lowLatency);

newproplus commented 10 months ago

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 commented 8 months ago

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 commented 7 months ago

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.