iOS开发笔记-101:Swift5 - 播放视频

var player: AVPlayer?
var playerViewController = AVPlayerViewController()

let urlString: String = videoModel?.videoUrl ?? ""
        player = AVPlayer(url: NSURL(string: urlString)! as URL)
        playerViewController.player = player
        //添加view播放
        playerViewController.view.frame = CGRect(x: 0, y: kNavigationBar64 + 40, width: kScreenW, height: kScreenH - kNavigationBar64 - 40 - kTabbarSafeBottomMargin)
        self.addChild(playerViewController)
        self.view.addSubview(playerViewController.view)

推荐阅读更多精彩内容