效果图
添加播放器步骤
//定义一个视频文件路径
let filePath = Bundle.main.path(forResource: "video", ofType: "mp4")
let videoURL = URL(fileURLWithPath: filePath!)
//定义一个视频播放器,通过本地文件路径初始化
playerView = AVPlayer(url: videoURL)
//设置大小和位置(全屏)
let playerLayer = AVPlayerLayer(player: playerView)
playerLayer.frame = self.view.bounds
//添加到界面上
// self.view.layer.addSublayer(playerLayer)
playViewController.player = playerView
self.present(playViewController, animated: true) {
self.playViewController.player?.play()
}