我想在UIView
中播放本地视频 ,没有控件 我已将框架AVFoundation和AVKit导入到我的代码中。我还为UIView
上课,但是,我不确定如何在我的UIView
中播放没有控件的视频。我已经找到了一种从互联网播放视频的方法,这不是我需要的。
答案 0 :(得分:1)
在swift 3.0中,试试这段代码。
//for Playing Video
@IBAction func btnvideoPlayClicked(_ sender:UIButton){
self.videoPlay()
}
func videoPlay()
{
let playerController = AVPlayerViewController()
playerController.delegate = self
let bundle = Bundle.main
let moviePath: String? = bundle.path(forResource: "SoSorry", ofType: "mp4")
let movieURL = URL(fileURLWithPath: moviePath!)
let player = AVPlayer(url: movieURL)
playerController.player = player
self.addChildViewController(playerController)
self.view.addSubview(playerController.view)
playerController.view.frame = self.view.frame
player.play()
}