我正在我的应用中播放本地视频。应用程序在模拟器上运行良好,但应用程序未在实际设备上显示视频,仅播放声音并且显示控件的其余部分为黑色。以下是我正在使用的代码:
@IBAction func play_video(_ sender: Any) {
guard let path = Bundle.main.path(forResource: "app_tutorial", ofType: "mp4") else {
return
}
let videoURL = NSURL(fileURLWithPath: path)
// Create an AVPlayer, passing it the local video url path
let player = AVPlayer(url: videoURL as URL)
let controller = AVPlayerViewController()
let audioSession = AVAudioSession.sharedInstance()
do
{
try audioSession.setCategory(AVAudioSessionCategoryPlayback, with: .duckOthers)
}
catch
{
print("AVAudioSession cannot be set")
}
controller.player = player
present(controller, animated: true) {
// player.play()
DispatchQueue.main.async {
player.play()
}
}
}
如果缺少什么,请指导我。 预先感谢