简体   繁体   English

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

[英]AVPlayerViewController inside a view is not showing the playback controls

I am working with apple tv. 我正在和苹果电视一起工作。 I have a UIView inside my UIViewController. 我的UIViewController中有一个UIView。 I am adding AVPlayerViewController as subview of my UIView. 我将AVPlayerViewController添加为UIView的子视图。 UIView's frame is CGRect(x: 50, y: 50, width: 1344, height: 756). UIView的框架为CGRect(x:50,y:50,宽度:1344,高度:756)。 I am setting AVPlayerViewController frame equals to my UIView's frame. 我设置AVPlayerViewController框架等于我的UIView框架。

Issue is that video plays fine in its frame but the controls like pause, play, forward etc. are hidden and not working. 问题是视频在其帧中播放正常,但是诸如暂停,播放,前进等控件被隐藏并且无法正常工作。 But when I set frame as CGRect(x: 0, y: 0, width: 1920, height: 1080), controls are visible and working. 但是,当我将frame设置为CGRect(x:0,y:0,width:1920,height:1080)时,控件是可见的并且可以工作。

My code is as per below: 我的代码如下:

    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()

Please help. 请帮忙。

This is an expected behaviour: 这是预期的行为:

AVPlayerViewController is designed such that when in full screen, the full playback experience (scrubbing, info panel access, etc) are all available. AVPlayerViewController的设计使全屏播放时,所有播放体验(擦洗,信息面板访问等)均可用。 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. 在小于全屏的空间中,假设它只是屏幕上几个交互元素之一,因此视图不应吸收所有触摸表面事件作为传输控制。

You can read more about this on this thread: https://forums.developer.apple.com/thread/19526 您可以在此线程上阅读有关此内容的更多信息: https : //forums.developer.apple.com/thread/19526

I managed to solve this using this code: 我设法使用以下代码解决了这个问题:

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);

Now AVPlayerViewController shows most playback controls even as child to a uiview. 现在,AVPlayerViewController甚至可以将大多数回放控件显示为uiview的子控件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM