Streaming audio with spotty network access

I am working on an iOS app that, among other things, plays streaming audio from an internet source and I am wondering if there are ways to deal with a spotty network that reflects the actual state of the network.


Right now, I am using AVPlayer (initialized with the URL of the source). Mostly, it works OK, but it has problems dealing with areas with no network connectivity and transitioning back to areas with connectivity. After entering the area of no network connectivity and then re-entering areas with connectivity, the player does not resume playing. The status of the player remains ReadyToPlay. I have tried toggling pause/play and the player does not resume playing. When I detect that the player gets into this state, I will destroy the AVPlayer object and create a new one.


BTW, the Reachability bit in the SCNetworkReachability flag remains set, despite being in a spot with no connectivity.


Is there a better way to handle this?


alan

I have seen this behavior when trying to stream an HLS audio file. What we found is that the AVPlayer seems to stop grabbing additional TS files once connectivity is regained. We fixed this by using Reachability and observing AVPlayerItemPlaybackStalledNotification. When you come back online, try calling

player.seekToTime(player.currentTime)

instead of calling

player.play()

. I think calling seekToTime forces the player to start loading resources again, which resumes playback. Hopefully this at least helps get you on the right track.

Im developing a player using AVPlayer and I hit the same problem... I tried the "player.seekToTime(player.currentTime) " ideia but din't work out . Can you you help with another ideia. I cant make start grabbing additional TS files 😟

Streaming audio with spotty network access
 
 
Q