视图内的 AVPlayerViewController 未显示播放控件

AVPlayerViewController inside a view is not showing the playback controls

我正在使用 Apple TV。我的 UIViewController 中有一个 UIView。我正在添加 AVPlayerViewController 作为我的 UIView 的子视图。 UIView的frame是CGRect(x: 50, y: 50, width: 1344, height: 756)。我将 AVPlayerViewController 帧设置为等于我的 UIView 的帧。

问题是视频在其帧中播放正常,但暂停、播放、前进等控件被隐藏且无法正常工作。但是当我将框架设置为 CGRect(x: 0, y: 0, width: 1920, height: 1080) 时,控件是可见的并且可以工作。

我的代码如下:

    let url = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
    let item = AVPlayerItem(url: url!)        
    self.player = AVPlayer(playerItem: item)
    self.avplayerController = AVPlayerViewController()
    self.avplayerController.player = self.player
    self.avplayerController.view.frame = videoPreviewLayer.frame
    self.avplayerController.showsPlaybackControls = true
    self.avplayerController.requiresLinearPlayback = true

    self.addChildViewController(self.avplayerController)
    self.view.addSubview(self.avplayerController.view)

    self.avpController.player?.play()

请帮忙。

这是预期的行为:

AVPlayerViewController is designed such that when in full screen, the full playback experience (scrubbing, info panel access, etc) are all available. When in a space less than full screen, the assumption is that it is just one of several interactive elements on screen, and thus the view should not absorb all touch surface events as transport control.

您可以在此线程上阅读更多相关信息:https://forums.developer.apple.com/thread/19526

我设法使用以下代码解决了这个问题:

let player = AVPlayer(url: self.videoUrl!)
let avPlayerController = AVPlayerViewController()

avPlayerController.player = player;
avPlayerController.view.frame = self.videoPlayView.bounds;

self.addChildViewController(avPlayerController)
self.videoPlayView.addSubview(avPlayerController.view);

现在 AVPlayerViewController 显示 大多数 播放控件,甚至作为 uiview 的子控件。

礼貌: https://www.techotopia.com/index.php/IOS_8_Video_Playback_using_AVPlayer_and_AVPlayerViewController