4

I am building a screen where users can play audio files using an AVPlayerViewController. The problem is that I can't get rid of the QuickTime logo in the player view, see screenshot:

enter image description here

My code:

do {
    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
    try AVAudioSession.sharedInstance().setActive(true)
    guard let url = URL(string: filePath!) else {
        return
    }

    let player = AVPlayer(url: url)
    let controller = AVPlayerViewController()
    controller.modalPresentationStyle = .overFullScreen
    controller.player = player

    self.present(controller, animated: true) {
        player.play()
    }
} catch {
}

I've tried adding an UIImageView using controller.contentOverlayView?.addSubView(), but I can't center that properly. How do I customize the layout of the player without having to build my own interface from scratch?

matt
  • 515,959
  • 87
  • 875
  • 1,141
jp1987
  • 121
  • 15

2 Answers2

5

What you tried is correct: just add a subview to the content overlay view. But you left out one step: you must give both the subview and the content overlay view constraints, to make them cover the player controller’s view completely.

Example (my av is your controller):

            let iv = UIView()
            iv.backgroundColor = .white
            av.contentOverlayView!.addSubview(iv)
            let v = av.contentOverlayView!
            iv.translatesAutoresizingMaskIntoConstraints = false
            NSLayoutConstraint.activate([
                iv.bottomAnchor.constraint(equalTo:v.bottomAnchor),
                iv.topAnchor.constraint(equalTo:v.topAnchor),
                iv.leadingAnchor.constraint(equalTo:v.leadingAnchor),
                iv.trailingAnchor.constraint(equalTo:v.trailingAnchor),
            ])
            NSLayoutConstraint.activate([
                v.bottomAnchor.constraint(equalTo:av.view.bottomAnchor),
                v.topAnchor.constraint(equalTo:av.view.topAnchor),
                v.leadingAnchor.constraint(equalTo:av.view.leadingAnchor),
                v.trailingAnchor.constraint(equalTo:av.view.trailingAnchor),
            ])
matt
  • 515,959
  • 87
  • 875
  • 1,141
0

If all you want to do is remove the "Q" logo without replacing it with anything, you can get rid of this way:

(avPlayerViewController?.view.subviews.first?.subviews.first as? UIImageView)?.image = nil

But, at least for me, the "Q" logo usually only appears about 2 seconds after I've set up the player view controller. So you might need to use a timer to get the above code to run about 2 seconds after creating the player.

CoolPineapple
  • 275
  • 1
  • 3
  • 11