google / flutter.plugins

BSD 3-Clause "New" or "Revised" License
117 stars 55 forks source link

PlatformException: Called pause on an unloaded player #84

Open volgin opened 4 years ago

volgin commented 4 years ago

I see the following exception in the logs. It's from a user - I don't know if it was noticeable or happened quietly in the background. In either case, it would be nice to avoid these exceptions. If plugin knows that a player is unloaded, it should not make a native call to pause it. If plugin does not know that, it should catch the exception so it does not bubble up to the app.

PlatformException(AudioPluginError, Called pause on an unloaded player: a42a0b90-8251-444d-a26e-90842bb7ddd1, null)

message_codecs.dart in StandardMethodCodec.decodeEnvelope at line 572 platform_channel.dart in MethodChannel._invokeMethod at line 161 Called from: audiofileplayer.dart in Audio._sendMethodCall at line 751 Called from: audiofileplayer.dart in Audio._pauseNative at line 676 Called from: audiofileplayer.dart in Audio.pause at line 574 Called from: player_controller_audiofileplayer.dart in PlayerControllerAudioFilePlayer.stop at line 395

wellbranding commented 4 years ago

@volgin Have you managed to solve it? Experiencing a similar issue: https://github.com/google/flutter.plugins/issues/90

monkeyswarm commented 3 years ago

Do you have sample code?

In theory, you should be able to call load and play (in a row, syncronously) without waiting for the load to complete. However, does awaiting the load make this issue go away?

volgin commented 3 years ago

I have made sure that I call pause only on players that actually play music. This is inconvenient, as I have to keep a separate flag ("bool canPausePlayer"). I believe that Audio object should keep its own state, and have a method like "isPlaying", or, even better, simply ignore pause() call if it cannot be executed.

However, today I received another error:

PlatformException(AudioPluginError, Called release on an unloaded player

audiofileplayer.dart in Audio._sendMethodCall at line 751 within audiofileplayer
Called from: <asynchronous suspension>
audiofileplayer.dart in Audio._releaseNative at line 732 within audiofileplayer
Called from: <asynchronous suspension>
audiofileplayer.dart in Audio.dispose at line 481 within audiofileplayer

I hope it does not mean that now I have to keep another flag ("bool canDisposePlayer") :(

I hope that dispose().catchError() will be enough to avoid any problems, but I have not tested it yet.