我尝试使用以下代码显示视频:
self.videoPlayer = AVPlayer.init(url: videoUrl as URL)
let playerLayer = AVPlayerLayer.init(player: self.videoPlayer)
self.videoPlayerView.layer.addSublayer(playerLayer)
playerLayer.frame = self.videoPlayerView.layer.bounds
self.videoPlayer.play()
但它没有出现在UIView内(即self.videoPlayerView)。它只是在屏幕中间显示一个瘦Rect,如屏幕截图所示。我该如何解决? screen shot
答案 0 :(得分:1)
试试这个...... 将图层的框架设置为等于视图的框架
self.videoPlayer = AVPlayer.init(url: videoUrl as URL)
let playerLayer = AVPlayerLayer.init(player: self.videoPlayer)
self.videoPlayerView.layer.addSublayer(playerLayer)
playerLayer.frame = self.videoPlayerView.frame
self.videoPlayer.play()
答案 1 :(得分:0)
首先代码是Swift not Obective-C,我会改变那个标签!其次,如何定义videoPlayerView框架?第三,你已经添加了playerLayer的框架。因此框架不会在视觉上改变!在将其添加为subLayer之前设置框架。希望有所帮助。