ryanheise / just_audio

Audio Player
1.05k stars 674 forks source link

just_audio_background does not cover all errors #518

Open sh4msi opened 3 years ago

sh4msi commented 3 years ago

Which API doesn't behave as documented, and how does it misbehave? This happened when I disconnected from the Internet and waited for the buffer to finish playing and try to play the next song. In this case, I do not receive any errors by listening to playbackEventStream for error handling, while I receive UnknownHostException on the console.

Minimal reproduction project The example (just_audio_background + just_audio)

To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:

  1. Run code on the device
  2. Playlist play
  3. Internet disconnection
  4. Wait like until the end of the playback of the buffer and auto go to the next song
  5. Wait for it to try to load the next music
  6. See error in console, no listener reaction to error

Error messages

E/ExoPlayerImplInternal(20476): Playback error
E/ExoPlayerImplInternal(20476):   UnknownHostException (no network)
E/AudioPlayer(20476): TYPE_SOURCE: java.net.UnknownHostException: Unable to resolve host "cdn.***.com": No address associated with hostname
E/flutter (20476): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(0, Source error, null, null)

Expected behavior Listen to all errors

Screenshots error

Desktop (please complete the following information):

Smartphone (please complete the following information):

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.5.0, on Microsoft Windows [Version 10.0.17763.2183], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.2)
[√] VS Code (version 1.60.1)
[√] Connected device (3 available)

• No issues found!
ryanheise commented 3 years ago

I need to know the minimal reproduction project to test these steps on. If the example exhibits the bug, please write "the example" under that section as per the instructions.

sh4msi commented 3 years ago

I run and checked the official example (example_playlist.dart)

Run code on the device
Playlist play
Internet disconnection
Wait like until the end of the playback of the buffer and auto go to the next song
Wait for it to try to load the next music
See error in console, no listener reaction to error

error2

sh4msi commented 3 years ago

I can not ask this question and suggestion here or in separate issues Or in Stack Overflow

Now, by default, when the Internet is down or there is a problem loading the file (404, invalid url ...), it is automatically redirected to the next song, and this process continues until the last playlist item. Of course, after fixing the reported bug, it can be controlled by handling error But I wanted to know if there is a parameter to control this at the moment? Or is it not better to add such a feature? (Two parameters, 1. was separate for disconnecting the Internet, 2. Other cases)

ryanheise commented 3 years ago

Hmm, I just tried to reproduce this on a Pixel 3a, Android 11, Flutter 2.5, but it was working correctly for me:

E/ExoPlayerImplInternal(20390): Playback error
E/ExoPlayerImplInternal(20390):   UnknownHostException (no network)
E/AudioPlayer(20390): TYPE_SOURCE: java.net.UnknownHostException: Unable to resolve host "s3.amazonaws.com": No address associated with hostname
I/flutter (20390): A stream error occurred: PlatformException(0, Source error, null, null)

Just to confirm, are you testing the latest version in git?

ryanheise commented 3 years ago

But wait, according to your screenshot, it's also working correctly for you too. The error is being caught by Flutter and is being printed out.

sh4msi commented 3 years ago

Yes, as I wrote in the description, it will be printed on the console, but it will not show any reaction in playbackEventStream, so I can not control it.

I want to be able to handle this error when it occurs

ryanheise commented 3 years ago

You wrote in the description:

In this case, I do not receive any errors by listening to playbackEventStream for error handling, while I receive UnknownHostException on the console.

But that's not true according to both my test and your screenshot.

sh4msi commented 3 years ago

But I think it's true and playbackEventStream shows no reaction to UnknownHostException

Was it different for you? Do you get an error about UnknownHostException or disconnected internet by listening to playbackEventStream?

sh4msi commented 3 years ago

I can not ask this question and suggestion here or in separate issues Or in Stack Overflow

Now, by default, when the Internet is down or there is a problem loading the file (404, invalid url ...), it is automatically redirected to the next song, and this process continues until the last playlist item. Of course, after fixing the reported bug, it can be controlled by handling error But I wanted to know if there is a parameter to control this at the moment? Or is it not better to add such a feature? (Two parameters, 1. was separate for disconnecting the Internet, 2. Other cases)

Is there a solution to this issue?

ryanheise commented 3 years ago

It seems like we're dealing with two issues here. One is the original bug report, and another is a feature request. Let's deal here with the bug report.

But I think it's true and playbackEventStream shows no reaction to UnknownHostException

Was it different for you?

Yes, as I already showed you with my logs:

E/ExoPlayerImplInternal(20390): Playback error
E/ExoPlayerImplInternal(20390):   UnknownHostException (no network)
E/AudioPlayer(20390): TYPE_SOURCE: java.net.UnknownHostException: Unable to resolve host "s3.amazonaws.com": No address associated with hostname
I/flutter (20390): A stream error occurred: PlatformException(0, Source error, null, null)

Notice that the last line is printed by the onError handler.

But it also seems that your own screenshot shows the exact same correct behaviour:

I run and checked the official example (example_playlist.dart)

Run code on the device
Playlist play
Internet disconnection
Wait like until the end of the playback of the buffer and auto go to the next song
Wait for it to try to load the next music
See error in console, no listener reaction to error

error2

Since you're posting screenshots rather than text, it's a bit hard for me to point to you which specific line proves that it's working, but you see the part in blue that you've highlighted/selected, the next line after that bit is printed out by your onError handler proving that it does reach your Flutter code.

If you have found in another app that onError isn't being called please submit a minimal reproduction project for that. And if you want to make a feature request, you are welcome to open a separate issue (but please check if the feature has already been requested by searching past issues.)

sh4msi commented 3 years ago

Hi @ryanheise, I am very grateful for the time you left and answered

I just realized where the problem is! error

If you pay attention, the first image also has an error, but it is not printed by playbackEventStream and can not be handled (just_audio_background + just_audio)

error2

But in the second image, the error is printed by playbackEventStream and can be handled (just_audio)

This problem occurs when we use just_audio_background And I'm using it too What is the solution?

ryanheise commented 3 years ago

To start with, please fix your bug report. Skipping on the minimal reproduction project, and then later providing an incorrect claim that the just_audio example exhibits the bug, may seem initially to save you time, but it actually wastes my time, and then indirectly ends up wasting your time too.

The next step for you is either:

  1. Wait for it to be fixed.
  2. Fix it yourself and submit a PR.
  3. Use audio_service directly where you'll be in full control of everything within your own app.
abeyshiferaw0 commented 2 years ago

hi. is there any fix for this issue even if its a work around, i just finished a project i'am working that uses just_audio_background and i didn't discover this issue until i finish the project so @ryanheise please will this be fixed soon.

on ios devices u can also find this issue if you play a concatenating audio source and turn of internet connection, the audio player becomes unresponsive at this point seekToNext(), seekToPrevious() and all methods wont work after this, the only way that it will work is if you stop the player and start again.

so please a work around will be greatly appreciated even if it's not fixed

ryanheise commented 2 years ago

As per my previous comment:

The next step for you is either:

  1. Wait for it to be fixed.
  2. Fix it yourself and submit a PR.
  3. Use audio_service directly where you'll be in full control of everything within your own app.
shadyshrif commented 1 year ago

Hello, Any update on this? For me, it is a big issue! I can't catch an exception

PiotrMitkowski commented 1 year ago

Hello @ryanheise! There has been some great work by @matecode, who has probably found the source of the issue here: https://github.com/ryanheise/just_audio/issues/870#issuecomment-1325076495. If it's fine for you, I'll prepare a fix, that redirects errors from the mentioned catchError to _playbackEventSubject error. If anyone else has other ideas regarding the cause, feel free to share them, so I can test them. I'll also try to prepare a minimal reproducible example on my fork. I'm really commited to fix this issue (receiving errors in playbackEventStream when using just_audio + just_audio_background), as it heavily affects my app.