0.倒入框架
import AVFoundation
import AVKit
1.懒加载创建视频播放器
lazy var playerVC : AVPlayerViewController = {
let tempPlayerVC = AVPlayerViewController()
// 设置画中画
tempPlayerVC.allowsPictureInPicturePlayback = true
let url = URL(string: "http://v1.mukewang.com/3e35cbb0-c8e5-4827-9614-b5a355259010/L.mp4")
let player = AVPlayer(url: url!)
tempPlayerVC.player = player
return tempPlayerVC
}()
2.弹出视频播放器并且播放视频
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
// 在弹出完成之后开始播放
present(playerVC, animated: true) {
self.playerVC.player?.play()
}
}