How do I know with AVPlayer the URL is invalid?

Hi,


I have a playlist of a radio station, specifically http://audio.glgltz.co.il/glgltz-a-zixief/glgltz-a-zixief.m3u8

If you put that URL in Safari you'll quickly find out it simply unavailable, doesn't work.


However when I am loading that into AVPlayer and by observing, I get Rate == 1.0 on notification "AVPlayerPlaybackViewControllerRateObservationContext", and loaded duration of zero. Which means if I am not mistaken "buffering".


Also the avplayer.status is AVPlayerStatusReadyToPlay rather than AVPlayerStatusFailed


Seems native question, but how do I know with AVPlayer that the URL is unavailable? should I be observing something else?


Thanks..!

Replies

I've noticed the same thing. Even if you use complete giberish for the URL, AVPlayer will report:


avPlayer.status is "AVPlayerStatusReadyToPlay"

avPlayer.rate is 1

avPlayer.currentItem.playbackLikelyToKeepUp is FALSE

avPlayer.currentItem.playbackBufferEmpty is true

avPlayer.error is nil

avPlayer.muted is false


If you find a solution for this, please post. Thanks!

Can you please file a bug on this at bugreporter.apple.com, providing as much detail as possible, and the results you would expect to see as a developer in this situation? Thanks!

I have the same problem. The video fails to load but status reported by the player is 1 (i.e ready). The error property of the player is also nil. Did you manage to fix this?

Here's a workaround:


When you first get the AVAsset from your assetURL, check its length before creating an AVPlayerItem out of it. If its length is zero, you have programmatically determined that you have a malformed URL.


let videoAsset = AVAsset(url: assetURL)

let assetLength = Float(videoAsset.duration.value) / Float(videoAsset.duration.timescale)

if assetLength > 0 {

let playerItem = AVPlayerItem(asset: videoAsset)

} else {

print ("HA!")

}