iOS Swift App AVPlayerController关闭,无法在外部显示器上使用 [英] iOS Swift App AVPlayerController dismiss not working on external display

查看:94
本文介绍了iOS Swift App AVPlayerController关闭,无法在外部显示器上使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个用于显示展览的短片的应用程序,该应用程序在iPad上具有完整功能,但在外部显示器上,视频将保留在最后一帧。
我们想使用iPad作为显示器的外部控件,但用户在没有视频播放时应始终看到视频选择gui

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

是否有任何技巧可以使它关闭AVPlayerController,所以它会直接在每次显示时都退回到我的应用程序吗?

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

推荐答案

我完全忘记了将答案发布在这里,以防其他人

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

以下代码将放置在playerDidReachEnd中,没有太大区别,但是它从所有屏幕上删除了播放器。

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)

这篇关于iOS Swift App AVPlayerController关闭,无法在外部显示器上使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆