Search code examples
iosswiftavplayerxcode-storyboardavplayerviewcontroller

Presenting UIView on AVPlayerViewController Fullscreen View


Problem: I need to add a UIView on top of an AVPlayer in a way that it is still user-interactive. When I try to add it as Overlay Content, any user interactive button will not fire anymore (as it is behind the video control layer).

Desired effect: I'd like to be able to add an UIView on top of an AVPlayer so that it is kept on top of the whole view at all times even when it enters fullscreen mode.

Sample Code:

var view = UIView = {
  let view = UIView()
  view.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
  view.backgroundColor = .red
  return view
}

var player = AVPlayer(url: http://somewhere.com/video.format)
let controller = AVPlayerViewController()
controller.player = player


Solution

  • Apparently, the best way to solve this issue was just adding a touchable element into the AVPlayerController, which redirected any touch event to the respective selector.