0
let url:NSURL = NSURL(string: jsonSession[indexPath.row].link)!
        let player = AVPlayer(URL: url)
        player.allowsExternalPlayback = true
        player.usesExternalPlaybackWhileExternalScreenIsActive = true
        let playerViewController = AVPlayerViewController()
        playerViewController.player = player
        self.presentViewController(playerViewController, animated: true) {
            playerViewController.player!.play()
        }

this is my code and i try to recommend if a playback end, to play the next movie :-)

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Fabian Boulegue
  • 6,476
  • 14
  • 47
  • 72

1 Answers1

0

Easiest option is to use AVQueuePlayer

let items:[AVPlyerItem] = []
for session in jsonSession {
  guard let url = NSURL(string:session.link) else { continue }
  let item = AVPlayerItem(URL:url)
  items.add(item)
}
let player = AVQueuePlayer(items: items)
//now you have the player, do what you were doing before

Second option is to do Key-Value Observing on AVPlayer. It could do something like

let url:NSURL = NSURL(string: jsonSession[indexPath.row].link)!
let player = AVPlayer(URL: url)
NSNotiicationCenter.defaultCenter().addObserver(self, selector#Selector(ViewController.itemDidFinishPlaying), name: AVPlayerItemDidPlayToEndTimeNotification, object: player.currentItem)
//I assume your ViewController class has a method called itemDidFinishPlaying

These are rough code samples, interpret as required.

Max
  • 3,371
  • 2
  • 29
  • 30
  • What error? These are written on top of the head, didn't check for compile error, but it should give you an idea on how to do this – Max Jun 06 '16 at 00:03