[英]Removing the QuickTime icon from AVPlayerViewController
I am building a screen where users can play audio files using an AVPlayerViewController.我正在构建一个屏幕,用户可以在其中使用 AVPlayerViewController 播放音频文件。 The problem is that I can't get rid of the QuickTime logo in the player view, see screenshot:问题是我无法摆脱播放器视图中的 QuickTime 标志,请看截图:
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.我试过使用controller.contentOverlayView?.addSubView()
添加 UIImageView ,但我无法正确居中。 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
): 示例(我的av
是您的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:如果您只想删除“Q”标志而不用任何东西替换它,您可以通过这种方式摆脱:
(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.但是,至少对我来说,“Q”标志通常只在我设置播放器视图控制器后大约 2 秒出现。 So you might need to use a timer to get the above code to run about 2 seconds after creating the player.因此,您可能需要使用计时器使上述代码在创建播放器后运行约 2 秒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.