其他分享
首页 > 其他分享> > Swift5 AVPlayerViewController的基本使用

Swift5 AVPlayerViewController的基本使用

作者:互联网

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()
        }
        
    }
}

标签:基本,AVPlayerViewController,url,self,player,playerVc,let,Swift5
来源: https://www.cnblogs.com/Johnson-Swift/p/15857003.html