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
2.02k stars 846 forks source link

[ANDROID] Crash app when play audio in assets: java.lang.IllegalStateException #1726

Open tranhaitrung opened 11 months ago

tranhaitrung commented 11 months ago

Checklist

Current bug behaviour

When I play audio in assets, my app sometime scrash with logCat --------- beginning of crash 12-09 19:00:22.199 6166 6166 E AndroidRuntime: FATAL EXCEPTION: main 12-09 19:00:22.199 6166 6166 E AndroidRuntime: Process: com.example.base_bloc_3.dev, PID: 6166 12-09 19:00:22.199 6166 6166 E AndroidRuntime: java.lang.IllegalStateException 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at android.media.MediaPlayer.getPlaybackParams(Native Method) 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at i5.i.h() 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at i5.i.a() 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at i5.o.z() 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at i5.i.v() 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at i5.i.s() 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at i5.g.onPrepared() 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:3149) 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at android.os.Looper.loop(Looper.java:154) 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6121) 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) 12-09 19:00:22.199 6166 6166 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

Expected behaviour

App play audio

Steps to reproduce

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

Code sample

Code sample Function call ```dart String path = 'audio/vi/voice_normal_task_arrive.mp3'; await PlayerAudio.playAsset(path, releaseMode: ReleaseMode.release); break; ``` ```dart static Future playAsset(String audio, {ReleaseMode? releaseMode}) async { if (_audioPlayer.state == PlayerState.playing) { await Future.wait([ _audioPlayer.stop(), _audioPlayer.release(), ]); // await _audioPlayer.stop(); // await _audioPlayer.release(); } await Future.wait([ _audioPlayer.setPlayerMode(PlayerMode.mediaPlayer), _audioPlayer.setReleaseMode(releaseMode ?? ReleaseMode.stop), _audioPlayer.play(AssetSource(audio)), ]); // await _audioPlayer.setReleaseMode(releaseMode ?? ReleaseMode.release); // await _audioPlayer.play(AssetSource(audio)); } ```

Affected platforms

Android

Platform details

Android 7.1.1

AudioPlayers Version

audioplayers: ^5.2.1

Build mode

No response

Audio Files/URLs/Sources

No response

Screenshots

No response

Logs

--------- beginning of crash
12-09 19:00:22.199  6166  6166 E AndroidRuntime: FATAL EXCEPTION: main
12-09 19:00:22.199  6166  6166 E AndroidRuntime: Process: com.example.base_bloc_3.dev, PID: 6166
12-09 19:00:22.199  6166  6166 E AndroidRuntime: java.lang.IllegalStateException
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at android.media.MediaPlayer.getPlaybackParams(Native Method)
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at i5.i.h()
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at i5.i.a()
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at i5.o.z()
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at i5.i.v()
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at i5.i.s()
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at i5.g.onPrepared()
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:3149)
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:154)
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6121)
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
12-09 19:00:22.199  6166  6166 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

Related issues / more information

No response

Working on PR

no way

Gustl22 commented 11 months ago

This may gets adressed with #1526