Reputation: 2100
I'm trying to add a play button on top of my AVPlayerLayer
but it's not showing up.
I have a UIView
called playerView
as an IBOutlet.
Here's how I create the player
and a corresponding playerLayer
, and put it in the 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)
The problem is that the playVideoButton
doesn't show up on top of the the playerLayer
(the button is added in the storyboard). I tried hiding the playerLayer
and the button still doesn't show up underneath, so it seems the button's not even in the view hierarchy.
Upvotes: 3
Views: 2079
Reputation: 71
Maybe this can help
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)
Upvotes: 1