idofilus / flutter_audio

Flutter Audio Plugin
MIT License
15 stars 14 forks source link

exception when I go out without stopping the reproduction #10

Closed mramirez11 closed 5 years ago

mramirez11 commented 5 years ago

When I reproduce audio and want go out to another widget, ide show me Exception has occurred. PlatformException (PlatformException(error, null, null))

This happenend Exactly with the metod onPause onPause() { audioPlayer.pause(); }

The console says E/MethodChannel#audio( 9848): Failed to handle method call E/MethodChannel#audio( 9848): java.lang.IllegalStateException E/MethodChannel#audio( 9848): at android.media.MediaPlayer.isPlaying(Native Method) E/MethodChannel#audio( 9848): at com.idofilus.audio.AudioPlayer.pause(AudioPlayer.java:201) E/MethodChannel#audio( 9848): at com.idofilus.audio.AudioPlugin.onMethodCall(AudioPlugin.java:58) E/MethodChannel#audio( 9848): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201) E/MethodChannel#audio( 9848): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:88) E/MethodChannel#audio( 9848): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:219) E/MethodChannel#audio( 9848): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#audio( 9848): at android.os.MessageQueue.next(MessageQueue.java:323) E/MethodChannel#audio( 9848): at android.os.Looper.loop(Looper.java:136) E/MethodChannel#audio( 9848): at android.app.ActivityThread.main(ActivityThread.java:6077) E/MethodChannel#audio( 9848): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#audio( 9848): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) E/MethodChannel#audio( 9848): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

dispose method @override void dispose() { try { if (audioPlayer.state == AudioPlayerState.PLAYING) { audioPlayer.release(); _playerStateSubscription.cancel(); _playerPositionController.cancel(); _playerBufferingSubscription.cancel(); _playerErrorSubscription.cancel(); onPause(); print(widget.url); super.dispose(); } } on Exception { print(Exception); } }

mramirez11 commented 5 years ago

in the dispose method remove call to function audioPlayer.release () and add call to function onStop ()

The method should be like this

` @override void dispose() { try { _playerStateSubscription.cancel(); _playerPositionController.cancel(); _playerBufferingSubscription.cancel(); _playerErrorSubscription.cancel(); onStop(); print(widget.url); super.dispose();

} on Exception {
  print(Exception);
}

} `