3

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 printed 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).

nickygerritsen
  • 325
  • 3
  • 12
  • If you log the contents of the `AVPlayerItem`'s accessLog and errorLog, do they show anything useful? – Phillip Mills Aug 10 '15 at 19:56
  • Are you retaining player or simply instantiating it inside some method and invoking play to it ? Also, if you want to be able to stream videos you should use AVPlayerItem, otherwise it wont work – Sandeep Aug 10 '15 at 19:57
  • @PhillipMills I will log it and see what happens – nickygerritsen Aug 11 '15 at 04:50
  • @GeneratorOfOne I did retain both the player and the view controller (although not shown in my example). I also tried using an AVPlayerItem and even an AVAsset. Both didn't work – nickygerritsen Aug 11 '15 at 04:50
  • I am playing a HLS VIDEO from Dropbox.com. To get the video to play I needed to download it, at least start the process it seems with a switch at the end of my URL. – user3069232 Feb 23 '16 at 06:44

0 Answers0