1

I built an app to display several short movies for an exhibition, the app is fully functional on the iPad, but on external display the video will stay at the last frame. We want to use the iPad as external control for the display, but users should always see the video selection gui when no video is played

That is the snippet to start a video

let playerItem = AVPlayerItem(URL: NSURL(fileURLWithPath: videoPath!))
let player = AVPlayer(playerItem: playerItem)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(VideoCollectionViewController.playerDidReachEnd(_:)), name: AVPlayerItemDidPlayToEndTimeNotification, object: playerItem)

playerController.player = player
self.presentViewController(playerController, animated: true) {
    self.playerController.player!.play()
}

And here is the function called when it reaches the end.

func playerDidReachEnd(notification: NSNotification) {
    NSNotificationCenter.defaultCenter().removeObserver(self)

    playerController.player?.currentItem
    playerController.dismissViewControllerAnimated(true, completion: nil)
}

It does also not fall back to the app screen if the video is stopped using the "Done" button of the player

Is there any trick to make it dismiss the AVPlayerController so it would fall back to my app directly on every display?

1 Answers1

1

I totally forgot to post my answer here, in case anybody else might come to that problem.

The following code is to be placed in the playerDidReachEnd, not much different, but it removed the player from all screens.

playerController.dismissViewControllerAnimated(true, completion: nil)
playerController.view.removeFromSuperview()
self.presentedViewController?.dismissViewControllerAnimated(true, completion: nil)