【发布时间】:2020-12-10 17:44:52
【问题描述】:
Swift 新手!我试图让应用程序在按下按钮时播放我的资源中的视频。我的 ViewController 中有这个方法:
if let path = Bundle.main.path(forResource: "Cypress", ofType: "mov") {
let player = AVPlayer(url: URL(fileURLWithPath: path))
// Create a new AVPlayerViewController and pass it a reference to the player.
let controller = AVPlayerViewController()
controller.player = player
// Modally present the player and call the player's play() method when complete.
self.present(controller, animated: true) {
player.play()
}
}
但是,当视频开始播放时,它是黑屏,但音频可以正常播放。有什么快速解决方法吗?我正在使用 Xcode 12.2 版。任何建议将不胜感激谢谢:)
【问题讨论】:
-
问题可能出在视频文件本身/编码上。 stackoverflow.com/questions/27753755/…
-
是的!视频必须是 mp4 而不是 mov。谢谢!
标签: ios swift xcode video avplayer