Search code examples
iosswiftavplayertvosavplayerviewcontroller

AVPlayerViewController inside a view is not showing the playback controls


I am working with apple tv. I have a UIView inside my UIViewController. I am adding AVPlayerViewController as subview of my UIView. UIView's frame is CGRect(x: 50, y: 50, width: 1344, height: 756). I am setting AVPlayerViewController frame equals to my UIView's frame.

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.

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.


Solution

  • 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. 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