Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot stop radio while it's loading #12

Open
fahlout opened this issue Oct 17, 2018 · 9 comments
Open

Cannot stop radio while it's loading #12

fahlout opened this issue Oct 17, 2018 · 9 comments

Comments

@fahlout
Copy link

fahlout commented Oct 17, 2018

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?

@fethica
Copy link
Owner

fethica commented Oct 22, 2018

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.

@fahlout
Copy link
Author

fahlout commented Oct 22, 2018 via email

@fethica
Copy link
Owner

fethica commented Oct 23, 2018

I found the problem! Thanks, I will try to implement a proper solution to this issue.

@fahlout
Copy link
Author

fahlout commented Oct 23, 2018

Perfect! Looking forward to the update.

@raskri
Copy link

raskri commented Mar 26, 2019

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?

@fethica
Copy link
Owner

fethica commented Mar 29, 2019

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!

@raskri
Copy link

raskri commented Sep 13, 2019

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)
    }
  }
}

@aleeherasimiuk
Copy link

It works
Captura de Pantalla 2020-03-22 a la(s) 23 11 45

@sharingisnice
Copy link

sharingisnice commented Oct 31, 2021

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants