我试图在AVPlayerLayer顶部添加一个播放按钮,但未显示。

我有一个名为UIViewplayerView作为IBOutlet。

这是创建player和相应的playerLayer并将其放入playerView的方法:

    player = AVPlayer()
    superLayer = self.playerView.layer
    playerLayer = AVPlayerLayer(player: player)
    playerLayer.frame = self.playerView.bounds
    playerLayer.cornerRadius = 5.0
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
    superLayer.addSublayer(playerLayer)

    self.view.bringSubview(toFront: playVideoButton)


问题在于playVideoButton不会显示在playerLayer的顶部(在情节提要中添加了按钮)。我尝试隐藏playerLayer,但按钮仍然没有显示在下面,因此似乎按钮甚至不在视图层次结构中。

最佳答案

也许这可以帮助

let player = AVPlayer(url: videoURL!)
let playerLayer = AVPlayerLayer(player: player)

let btn = UIButton()
btn.frame = CGRect(x: 23, y: 34, width: 25, height: 30)

playerLayer.addSublayer(btn.layer)
self.view.layer.addSublayer(playerLayer)

10-04 23:38