简体   繁体   中英

Removing the QuickTime icon from AVPlayerViewController

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:

在此处输入图片说明

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?

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),
            ])

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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