<分区>
我想在 UIView
中不带控件播放本地视频 我已将框架 AVFoundation 和 AVKit 导入到我的代码中。我还为 UIView
制作了类(class),但是,我不确定如何在没有控件的情况下在 UIView
中播放视频。我已经找到了一种从 Internet 播放视频的方法,但这不是我需要的。
<分区>
我想在 UIView
中不带控件播放本地视频 我已将框架 AVFoundation 和 AVKit 导入到我的代码中。我还为 UIView
制作了类(class),但是,我不确定如何在没有控件的情况下在 UIView
中播放视频。我已经找到了一种从 Internet 播放视频的方法,但这不是我需要的。
最佳答案
在 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()
}
关于ios - 在 UIView 中自动播放本地视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45861411/