varbgView=UIView()
var palyerItem :AVPlayerItem?
varplayer:AVPlayer?
var playerLayer :AVPlayerLayer?
//创建媒体资源管理对象
self.palyerItem = AVPlayerItem(url: URL.init(fileURLWithPath: urlString))
//创建ACplayer:负责视频播放
self.player = AVPlayer.init(playerItem: self.palyerItem!)
self.player?.rate = 1.0//播放速度 播放前设置
//创建显示视频的图层
self.playerLayer?.backgroundColor = UIColor.init(hex: "#FFFFFF").cgColor
self.playerLayer = AVPlayerLayer.init(player: self.player)
self.playerLayer?.borderColor = UIColor.init(hex: "#FFFFFF").cgColor
playerLayer?.shadowColor = UIColor.init(hex: "#FFFFFF").cgColor
self.playerLayer?.videoGravity = .resizeAspect
if zIsiPad {
self.playerLayer?.frame = CGRect.init(x: 0, y: 0, width: 700, height: 900)
} else {
self.playerLayer?.frame = CGRect.init(x: 0, y: 0, width: 375, height: 500)
}
self.playerLayer?.shouldRasterize = true
self.playerLayer?.rasterizationScale = UIScreen.main.scale
self.bgView.layer.addSublayer(self.playerLayer!)
//播放
self.player?.play()
网友评论