PlatformException Not Captured By Audio Service Plugin
Which API doesn't behave as documented, and how does it misbehave? Name here the specific methods or fields that are not behaving as documented, and explain clearly what is happening.
Minimal reproduction project Provide a link here using one of two options:
- Fork this repository and modify the example to reproduce the bug, then provide a link here.
- If the unmodified official example already reproduces the bug, just write "The example". The Example Project To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:
- Run the Example Project
- Click on 'Audioplayer Button'
- Once the media starts playing Switch off Data
- You can see the Platform Exception thrown by Exoplayer which is not propagated to Audio Service. Audio service processing state gets stuck on Buffering state.
Error messages
E/flutter (30797): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(0, Source error, null, null)
E/flutter (30797):
E/ExoPlayerImplInternal(30797): Playback error
E/ExoPlayerImplInternal(30797): UnknownHostException (no network)
If applicable, copy & paste error message here, within the triple quotes to preserve formatting.
Expected behavior This error should be flow down to audio service plugin so that this can be handled properly.
Screenshots If applicable, add screenshots to help explain your problem.
Runtime Environment (please complete the following information if relevant):
- Device: [e.g. Samsung Galaxy Note 8]
- OS: [e.g. Android 8.0.0]
Flutter SDK version
insert output of "flutter doctor" here
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.1, on Microsoft Windows [Version 10.0.19042.867], locale en-IN)
Additional context Add any other context about the problem here.
I have fixed the root cause in just audio which I'll commit when I am able to. Then in terms of the audio service example it will be a matter of listening to the errors on just audio's playback event stream.
This is now fixed in just_audio. I have updated the just_audio example to show how to listen to errors during playback:
_player.playbackEventStream.listen((event) {},
onError: (Object e, StackTrace stackTrace) {
print('An error occurred: $e');
});
I've just had a play around with how to handle a network interruption and it appears you need to call stop and play to retry the connection, at least on the ExoPlayer side. It looks like there may be some features of ExoPlayer I could eventually support to automatically retry a given number of times before giving up with an error, but that is not there for now.
I am not sure if I will complicate the example with this logic, but hopefully this comment helps in terms of implementing retry logic.