iOS Swift App AVPlayerController dismiss 无法在外部显示器上运行
iOS Swift App AVPlayerController dismiss not working on external display
我构建了一个应用程序来显示展览的几部短片,该应用程序在 iPad 上功能齐全,但在外部显示器上,视频将停留在最后一帧。
我们想使用 iPad 作为显示的外部控制,但是当没有视频播放时,用户应该总是看到视频选择 gui
这是开始视频的片段
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()
}
这是到达末尾时调用的函数。
func playerDidReachEnd(notification: NSNotification) {
NSNotificationCenter.defaultCenter().removeObserver(self)
playerController.player?.currentItem
playerController.dismissViewControllerAnimated(true, completion: nil)
}
如果使用播放器的 "Done" 按钮停止视频,它也不会返回到应用程序屏幕
是否有任何技巧可以让它关闭 AVPlayerController,以便在每个显示器上直接回退到我的应用程序?
我完全忘了 post 我的答案,以防其他人可能会遇到这个问题。
下面的代码是要放在playerDidReachEnd中的,差别不大,但是它把播放器从所有屏幕上移除了。
playerController.dismissViewControllerAnimated(true, completion: nil)
playerController.view.removeFromSuperview()
self.presentedViewController?.dismissViewControllerAnimated(true, completion: nil)
我构建了一个应用程序来显示展览的几部短片,该应用程序在 iPad 上功能齐全,但在外部显示器上,视频将停留在最后一帧。 我们想使用 iPad 作为显示的外部控制,但是当没有视频播放时,用户应该总是看到视频选择 gui
这是开始视频的片段
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()
}
这是到达末尾时调用的函数。
func playerDidReachEnd(notification: NSNotification) {
NSNotificationCenter.defaultCenter().removeObserver(self)
playerController.player?.currentItem
playerController.dismissViewControllerAnimated(true, completion: nil)
}
如果使用播放器的 "Done" 按钮停止视频,它也不会返回到应用程序屏幕
是否有任何技巧可以让它关闭 AVPlayerController,以便在每个显示器上直接回退到我的应用程序?
我完全忘了 post 我的答案,以防其他人可能会遇到这个问题。
下面的代码是要放在playerDidReachEnd中的,差别不大,但是它把播放器从所有屏幕上移除了。
playerController.dismissViewControllerAnimated(true, completion: nil)
playerController.view.removeFromSuperview()
self.presentedViewController?.dismissViewControllerAnimated(true, completion: nil)