视频播放ios后放回ipad屏幕

时间:2017-04-01 11:43:06

标签: swift airplay avplayerviewcontroller

场景:我正在Apple TV上镜像iPad应用。点击按钮开始播放视频。视频通过电视上的Airplay播放。

    let playerViewController = AVPlayerViewController()
    let player = AVPlayer(url: videoURL as URL)

    playerViewController.player = player
    playerViewController.videoGravity = AVLayerVideoGravityResizeAspect
    self.present(playerViewController, animated: true) {
        self.playerViewController.player!.play()
    }

我添加了一个观察者来移除AVPlayerViewController()

NotificationCenter.default.addObserver(self, selector: #selector(ViewController.videoEnded), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: self.videoplayer)

视频结束后,此方法会触发。

func videoEnded()  {
    print("Video Ended")
    logoButton.isHidden        = false
    longPressGesture.isEnabled = false
    scanImageView.isHidden     = true
    scanImageView.image        = UIImage(named: "scan")
    logoButton.isEnabled       = true
    self.view.backgroundColor = UIColor.white


    self.playerViewController.dismiss(animated: true, completion: nil)


}

问题: 当视频结束时,苹果电视显示黑屏,而不是应用程序。一旦视频结束,我该如何重新启动镜像?

0 个答案:

没有答案