gpt4 book ai didi

ios - AVPlayerViewController 不播放本地视频

转载 作者:行者123 更新时间:2023-11-28 21:14:56 27 4
gpt4 key购买 nike

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

最佳答案

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

关于ios - AVPlayerViewController 不播放本地视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41634476/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com