react-native-track-player icon indicating copy to clipboard operation
react-native-track-player copied to clipboard

PlaybackError event doesn't trigger on iOS when connection is lost

Open gavrichards opened this issue 2 years ago • 9 comments

Describe the Bug On Android, if the connection is lost, the "playback-error" event is triggered with code "playback-source". You could then use that to handle auto-reconnecting.

But on iOS this doesn't happen. I get a "playback-state" event with the state "paused" and then that's it. The "paused" state makes little sense, particularly for live streams.

If you want to handle reconnecting on iOS, you have to listen for the "paused" event, then check if there's a connection using a package like @react-native-community/netinfo, and then start attempting to reconnect.

This was previously mentioned in issue #421, but it was closed without a fix.

gavrichards avatar Mar 16 '22 12:03 gavrichards

@gavrichards what version of the library are you using?

jspizziri avatar Apr 14 '22 13:04 jspizziri

@jspizziri 2.1.2

gavrichards avatar Apr 14 '22 13:04 gavrichards

@gavrichards thanks! After taking a quick look I'm guessing that this is actually a bug in SwiftAudioEx as this package simply observes state and failure events from the player provided by that package.

With that said, it definitely sounds like something that needs to be fixed. With that in mind, I have a few questions:

  1. Can you create a list of reproducible steps that most easily create the issue to help us resolve it?
  2. If possible could you create a fork of this project and create a repro in the example project?
  3. Do you have the ability (with help from contributors) to take a crack at digging into the native side and trying to fix it?

jspizziri avatar Apr 14 '22 13:04 jspizziri

  1. You can use this library's useTrackPlayerEvents hook and check for an event.type of Event.PlaybackError. You'll see that if you lose connection while playing, this is only triggered on Android.
  2. I'm afraid I'm not in a position to do that at the moment unfortunately.
  3. I don't know anything about native code I'm afraid so I won't be much help there.

gavrichards avatar Apr 14 '22 13:04 gavrichards

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jul 19 '22 02:07 github-actions[bot]

Same issue on 3.0.0 but android too

TheTarasik avatar Aug 12 '22 16:08 TheTarasik

Looking through the SwiftAudioEx source code, I am unable to spot a bug.

RNTP will emit an playback-error whenever the underlying AVPlayer code encounters AVPlayer.Status.failed - https://developer.apple.com/documentation/avfoundation/avplayer/status/failed

The playback state observing implementation follows this example code to the T: https://developer.apple.com/documentation/avfoundation/media_playback/observing_playback_state

I do however see mentions of this issue with AVPlayer on old SO posts, so this might be an AVPlayer bug: https://stackoverflow.com/questions/27556521/avplayer-connection-loss-restarting

puckey avatar Sep 01 '22 18:09 puckey

@TheTarasik @gavrichards can either of you create a reproduction of this based on the example project?

jspizziri avatar Sep 15 '22 12:09 jspizziri

@gavrichards @TheTarasik pinging you here.

jspizziri avatar Sep 20 '22 14:09 jspizziri

Closing until a repro is provided.

jspizziri avatar Sep 22 '22 17:09 jspizziri