audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

Constant crash on android 6.0.1

Open ehtiqamar opened this issue 1 year ago • 4 comments

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

After the update to audioplayers 5.2.1, there is constant crash of IlllegalStateException on Android 6.0.1 devices.

Expected behaviour

The player should play the audio from assets.

Steps to reproduce

  1. Execute flutter run on the code sample
  2. ...
  3. ...

Code sample

Future play(String fileName, {bool loop = false}) async { if (_audioPlayer.state == PlayerState.disposed) { _audioPlayer = AudioPlayer(); } await _audioPlayer.release(); _audioPlayer.play(AssetSource('sounds/$fileName'), volume: _volume); if (loop) { _audioPlayer.setReleaseMode(ReleaseMode.loop); } }

Affected platforms

Android

Platform details

Platform: Android 6.0.1

AudioPlayers Version

5.2.1

Build mode

release

Audio Files/URLs/Sources

No response

Screenshots

No response

Logs

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(AndroidAudioError, null, java.lang.IllegalStateException at android.media.MediaPlayer.prepareAsync(Native Method) at n9.i.d() at n9.o.N() at m9.m.J() at m9.m.n() at m9.m$b.b() at m9.m$b.invoke() at m9.m$d.invokeSuspend() at kotlin.coroutines.jvm.internal.a.resumeWith() at d9.d1.run() at kotlinx.coroutines.internal.n.run() at kotlinx.coroutines.scheduling.k.run() at kotlinx.coroutines.scheduling.a.M() at kotlinx.coroutines.scheduling.a$c.d() at kotlinx.coroutines.scheduling.a$c.n() at kotlinx.coroutines.scheduling.a$c.run() , null) at StandardMethodCodec.decodeEnvelope(message_codecs.dart:652) at MethodChannel._invokeMethod(platform_channel.dart:310) at AudioPlayer.stop(audioplayer.dart:226) at AudioPlayer.release(audioplayer.dart:242) at AudioPlayer.dispose(audioplayer.dart:405) at AudioManager._disposeMusic(audio_manager.dart:112) at AudioManager.dispose(audio_manager.dart:99)

Related issues / more information

No response

Working on PR

no way

ehtiqamar avatar Dec 12 '23 07:12 ehtiqamar

Try to set the release mode before playing. Also use await before setReleaseMode and play.

See also #1526

Gustl22 avatar Dec 12 '23 08:12 Gustl22

Try to set the release mode before playing. Also use await before setReleaseMode and play.

See also #1526

Ok, I'll try with await, but I don't think that would be cause since this only happens on Android 6.0.1

ehtiqamar avatar Dec 12 '23 09:12 ehtiqamar

@ehtiqamar did you find a solution? I am also struggling with this for Android 6 devices in specific

tkortekaas avatar Jan 13 '24 08:01 tkortekaas

@ehtiqamar did you find a solution? I am also struggling with this for Android 6 devices in specific

nope, I tried the above solution but it is still crashing

ehtiqamar avatar Jan 22 '24 11:01 ehtiqamar