我在我的项目中添加了一个 DemoVideo.mp4 并将其添加到复制资源文件中。但是当我运行该应用程序时,它不会播放我的视频。这是我的方法。
private func setUpAndPlayVideo() {
guard let videoPath = Bundle.main.path(forResource: "DemoVideo.mp4", ofType: nil) else {
return
}
let videoURL = NSURL(string: videoPath)
let player = AVPlayer(url: videoURL! as URL)
playerViewController = AVPlayerViewController()
playerViewController.player = player
playerViewController.view.frame = self.videoPlayerView.bounds
self.videoPlayerView.addSubview(playerViewController.view)
playerViewController.showsPlaybackControls = false
playerViewController.player?.play()
}