import UIKit
import AVKit
class AVPlayerViewVC: UIViewController ,AVPlayerViewControllerDelegate{
lazy var playerVc: AVPlayerViewController = {
let playerVc = AVPlayerViewController()
playerVc.delegate = self
//画中画
playerVc.allowsPictureInPicturePlayback = true
let url = NSURL(string: "https://kvideo01.youju.sohu.com/6c1f5b6d-1c04-47ff-a787-777c32561f0c2_0_0.mp4")
let player = AVPlayer(url: url! as URL)
playerVc.player = player
return playerVc
}()
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if presentedViewController != nil { return }
present(playerVc, animated: true) {
self.playerVc.player?.play()
}
}
}