fethica / FRadioPlayer

A simple radio player framework for iOS, macOS, tvOS.

Home Page:https://fethica.github.io/FRadioPlayer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Player keeps playing when remote stream ends

shaksp opened this issue · comments

HI,

I'm building an app using FRRadioPlayer to play various streams from a remote icecast server which is streaming in mp3 format.

The streams are not always live. Many streams are on for 1-2 hours per day.
The app has code to check the stream is live and only shows the player when live.

The issue I'm experiencing is that when the stream ends, the player keeps playing a dead stream. The icecast server is no longer publishing the mount so the url should give a 404 error. However FRRadioPlayer thinks its still live.

FRadioPlaybackState keeps saying "Player is playing"
playerState says "Loading is finished"
isplaying shows true (playing)

I've checked all the published values and none of them appear to change. I need the player to stop playing when the stream ends.

When the stream starts again and if the url hasn't changed, the new stream doesn't play either. If the player was stopped when the stream ended and then the user started again the stream then it would be OK as it would reload the url but as the player never seems the stream stop, the UI keeps showing playing and the app never reloads the url.

@shaksp, if you put the stream URL in a browser when no one is streaming, does it gives you error 404?

@shaksp, if you put the stream URL in a browser when no one is streaming, does it gives you error 404?

Hi, correct, icecast does appear to let the device know the stream is ending and then after that, the url gives a 404 error. Browsers correctly handle this and show the stream is about to end. Also exoplayer on Android does the same.

I had a look into this further and AVPlayer does send a notification- NSNotification.Name.AVPlayerItemDidPlayToEndTime.
The FRadioPlayer.swift file has a remove observer for this but not an add observer.

I have amended this file to add an observer and also added a playbackstate of ended and this seems to work fine and the status correctly changes but haven't tested if there are any other downsides to this e.g. if this affects audio interruptions. FRadioPlayer.Swift file attached.

FRadioPlayer.swift.txt