简体   繁体   English

AVPlayer无法在iOS8上播放NSDocuments目录中的视频

[英]AVPlayer unable to play video from NSDocuments Directory on iOS8

I'm trying to get my app to play a video that has been downloaded to the Documents Directory. 我正在尝试让我的应用播放已下载到“文档目录”中的视频。

My code works when tested on the iOS 7.1 simulator but not on iOS 8.0 devices or the iOS 8.0 simulator. 我的代码在iOS 7.1模拟器上进行测试时有效,但在iOS 8.0设备或iOS 8.0模拟器上却无效。 There isn't any error, AVPlayer does not play the video and shows a Black View. 没有任何错误,AVPlayer不播放视频,而是显示黑场。

I also checked the Document's folder of my device with XCode's Organizer and the file appears to be successfully downloaded. 我还使用XCode的管理器检查了设备的文档文件夹,文件似乎已成功下载。

Here is a simplified version of my code. 这是我的代码的简化版本。

// file_path is a string that stores the path to the video file a println of it shows
// "/var/mobile/Containers/Data/Application/83C7837C-59B5-4767-A579-7CE758A93C6F/Documents/og4gr.mp4"
var path:NSURL = NSURL.fileURLWithPath(file_path, isDirectory: false);
_player = AVPlayer(URL: path);

Has anyone else encountered this? 有人遇到过这种情况么? Thank you for your time! 感谢您的时间!

So the problem was that the Application Documents Folder Path changes every time you launch the app and I was storing the absolute path of the video file. 因此,问题在于,每次启动应用程序时,“应用程序文档文件夹路径”都会更改,而我正在存储视频文件的绝对路径。

According to this article here: http://pinkstone.co.uk/where-is-the-documents-directory-for-the-ios-8-simulator/ , this is how it is now in iOS 8, which is why while my method worked in iOS7 it was failing on iOS8 devices and Simulators. 根据此处的这篇文章: http : //pinkstone.co.uk/where-is-the-documents-directory-for-the-ios-8-simulator/ ,这就是iOS 8中的情况,这就是为什么虽然我的方法在iOS7中有效,但在iOS8设备和模拟器上却失败了。 Thank you @RoboticCat for pointing me in the right direction! 谢谢@RoboticCat为我指出正确的方向!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM