FRadioPlayer
FRadioPlayer copied to clipboard
Cannot stop radio while it's loading
I seem to not be able to stop the radio from playing while it's still loading. Is there anyway to cancel loading and keep it from starting to play while it's in the loading state?
Hi @fahlout , when the player is stopped in the loading state, the playbackStateDidChange
gets called with FRadioPlaybackState.stopped
, and yes the player state stays in FRadioPlayerState.loading
, I should add another state to handle this case, in the meantime you could reset your UI using playbackStateDidChange
method when the player is stopped!
Thanks for reporting the issue.
The problem I am having, however, is that when calling stop on the radio while in the loading state it will still start playing once it is done loading instead of suspending the loading process of the radio stream. It seems to ignore the stop call while in loading state.
Thanks for looking into this for me!
On Oct 21, 2018, at 7:36 PM, Fethi El Hassasna [email protected] wrote:
Hi @fahlout , when the player is stopped in the loading state, the playbackStateDidChange gets called with FRadioPlaybackState.stopped, and yes the player state stays in FRadioPlayerState.loading, I should add another state to handle this case, in the mean time you could reset your UI using playbackStateDidChange method when the player is stopped!
Thanks for reporting the issue.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
I found the problem! Thanks, I will try to implement a proper solution to this issue.
Perfect! Looking forward to the update.
Hey Fethi! Nice player! Great work! Have you solved this issue?
I'm having an issue when the player.radioURL is changed fast, the previous is played. Let's say I have 3 streams: a, b and c. When I change from a->b->c, b is played. I'm trying to call stop before i change the radioUrl, but with no success.
Any thoughts?
Hey @raskri ,
Yes it's the same bug, there is an async call for setting the playerItem causing this issue, I will try to fix it in the next release!
So changing the radioURLDidChange function to this solved my problem:
private func radioURLDidChange(with url: URL?) {
resetPlayer()
guard let url = url else { state = .urlNotSet; return }
state = .loading
player = AVPlayer()
self.theUrlToPlay = url.absoluteString
preparePlayer(with: AVAsset(url: url)) { (success, asset) in
guard success, let asset = asset else {
self.resetPlayer()
self.state = .error
return
}
// still on same url?
if(self.theUrlToPlay == url.absoluteString){
self.playerItem = AVPlayerItem(asset: asset)
}
}
}
It works
Provided solutions did not work for me. However, Upon further investigation, the slow loading stations set the station playback state to .loading and when you quickly switch to another station, when the .loadingFinished state is done, even though the player.radioURL object is printed as the latest selected station, it was playing the station that was lastly in the .loading state
So I created a variable loadingForStationURL And set its value to the loading radio stations URL. If this variable does not match the .loadingFinished's url, I reset the radioUrl and played again.
func radioPlayer(_ player: FRadioPlayer, playerStateDidChange state: FRadioPlayerState) {
if state == .loading {
loadingForStationURL = player.radioURL
}
if state == .loadingFinished {
if player.radioURL != loadingForStationURL {
player.stop()
playStation(url: player.radioURL!)
}
}
}
Hope this solution works for you all :)