I want to play an HLS stream using AVPlayer (in Swift).
This HLS stream plays in Safari, but not when I want to use AVPlayer.
My code:
let hlsLink = 'http://thelinktomyHLSmovie'
let player = AVPlayer(URL: NSURL(string: hlsLink)!)
let playerVC = AVPlayerViewController()
playerVC.player = player
presentViewController(playerVC, animated: true) {
playerVC.player?.play()
}
If I do a CURL to the HLS URL to find out what kind of streams are in it, I get:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2328000,CODECS="avc1.66.30,mp4a.40.2",RESOLUTION=1280x720
chunklist_w1751887550_b2328000.m3u8?smil=1
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=128000,CODECS="mp4a.40.2"
chunklist_w1751887550_b128000_ao.m3u8?smil=1
Which seems OK to me.
If I do the same with some other streams that are smaller and shorter, everything works OK.
I already tried observing the status of the AVPlayer and the AVPlayerItem, but that did not report anything useful.
What am I missing?
Update:
I added a AVPlayerItem, as I already said. I also added a notification observer to the player, player view controller and player item for all notifications and print
ed the output. This gave me the following:
Optional(NSConcreteNotification 0x7fd272bcd600 {name = AVPlayerItemTimebaseChangedNotification; object = <AVPlayerItem: 0x7fd2714f6c40, asset = <AVURLAsset: 0x7fd27144e720, URL = http://hls.streamonecloud.net/vod/amlst:pwlsaeYN1ZuH/playlist.m3u8?smil=1>>})
Optional(NSConcreteNotification 0x7fd272bccaf0 {name = AVPlayerItemBecameCurrentNotification; object = <AVPlayerItem: 0x7fd2714f6c40, asset = <AVURLAsset: 0x7fd27144e720, URL = http://hls.streamonecloud.net/vod/amlst:pwlsaeYN1ZuH/playlist.m3u8?smil=1>>})
Optional(NSConcreteNotification 0x7fd272bcd710 {name = AVPlayerCurrentItemDidChangeNotification; object = <AVPlayer: 0x7fd27157ca60>; userInfo = {
CurrentDuration = {
epoch = 0;
flags = 17;
timescale = 0;
value = 0;
};
ReasonForCurrentItemDidChange = ReasonAdvanceAtEnd;
}})
Optional(NSConcreteNotification 0x7fd271759950 {name = AVPlayerItemTimebaseChangedNotification; object = <AVPlayerItem: 0x7fd2714f6c40, asset = <AVURLAsset: 0x7fd27144e720, URL = http://hls.streamonecloud.net/vod/amlst:pwlsaeYN1ZuH/playlist.m3u8?smil=1>>})
I also inspected the accessLog()
and errorLog()
of the item. The access log contains no entries (but does exist) and the error log is nil.
I'm not sure anymore what to do. My log above contains the URL I want to load if anymore is interested (just Big Buck Bunny on one of our servers).