AVPlayerViewController 不播放本地视频

AVPlayerViewController doesn't play local videos

我在我的项目中添加了一个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 方法中调用这个方法,但它显示了这个。

 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()