我为我的项目创建了一个页面,其中包含一个循环播放的视频 (2.1 Mb/480p)。该视频在我的模拟器上播放,但当我将应用程序侧载到 iPhone 设备时却无法播放。我已经检查了多个具有相同问题的帖子,但到目前为止,没有一个解决方案对我有用。是什么导致了这个问题?我该如何解决?
我的视频存储在本地。这是播放我的视频的相关源代码:
override func viewDidAppear(animated: Bool) {
let fileUrl = NSURL(fileURLWithPath: "/Users/User/Desktop/Project_XYZ/Pultz/11005472.mp4")
playerView = AVPlayer(URL: fileUrl)
let playerLayer = AVPlayerLayer(player: playerView)
playerLayer.frame = videoContainer.frame
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
//playerViewController.player = playerView
self.view.layer.addSublayer(playerLayer)
playerView.play()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(WorkoutDashboardViewController.restart), name: AVPlayerItemDidPlayToEndTimeNotification, object: self.playerView.currentItem)
}
附言我使用的视频是我从互联网上下载的免费水印视频。这可能是一个可能的原因吗?
最佳答案
试着改变这个:
let fileUrl = NSURL(fileURLWithPath: "/Users/User/Desktop/Project_XYZ/Pultz/11005472.mp4")
与:
let fileUrl = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("11005472", ofType: "mp4"))
在您的 iPhone 中,您有一个不同的文件系统。您不能使用您在计算机/模拟器上使用的相同路径。
关于ios - 视频在 xcode 模拟器上播放但不在设备上播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38609183/