0

我在我的项目中添加了一个 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()
}

我在方法中调用这个方法,viewDidAppear但它显示了这个。 截屏

4

1 回答 1

2
 let path : String = Bundle.main.path(forResource: "charlie", ofType: "mp4")!
 let movieurl : URL = URL(fileURLWithPath: path)
 let movie : AVPlayerViewController = AVPlayerViewController()
 movie.view.frame = self.view.bounds

 let player : AVPlayer = AVPlayer(url: movieurl)
 movie.player = player

 self.view.addSubview(movie.view)
 player.play()
于 2017-01-13T13:07:19.527 回答