我有一个 tvOS 应用程序的以下代码。它可以按我的意愿播放视频,但是我设置的 contentOverlayView 没有出现。从我看过的例子来看,我认为它应该可以工作。有人可以解释我做错了什么吗?
import Foundation
import UIKit
import AVKit
class videoPlayer: AVPlayerViewController {
var thePlayer: AVPlayer?
var movieToPlay: AVPlayerItem?
var movieURL: String?
let theVideoPlayer = AVPlayerViewController()
@IBOutlet weak var videoInfo: UIView!
override func viewDidLoad(){
theVideoPlayer.contentOverlayView?.addSubview(videoInfo)
theVideoPlayer.player = thePlayer
self.view.addSubview(theVideoPlayer.view)
theVideoPlayer.view.frame = self.view.frame
NotificationCenter.default.addObserver(self, selector: #selector(videoPlayer.videoDone), name: NSNotification.Name(rawValue: "AVPlayerItemDidPlayToEndTimeNotification"), object: thePlayer?.currentItem)
playVideo(movieURL!)
}
func playVideo(_ movieURL: String){
let movieToPlay = AVPlayerItem(url: URL(string: movieURL)!)
thePlayer = AVPlayer(playerItem: movieToPlay)
thePlayer!.play()
}
func videoDone(){
dismiss(animated: true, completion: nil)
}
}