AVPlayer无法在iOS 8上播放文档目录中的视频

时间:2014-09-09 11:12:34

标签: ios swift ios8 avplayer ios7.1

我正在尝试让我的应用播放已下载到文档目录的视频。

我的代码在iOS 7.1模拟器上测试时有效,但在iOS 8.0设备或iOS 8.0模拟器上没有。没有任何错误,AVPlayer不播放视频并显示黑视图。

我还使用XCode的管理器检查了设备的Document文件夹,该文件似乎已成功下载。

以下是我的代码的简化版本。

// 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);

还有其他人遇到过这个吗?谢谢你的时间!

1 个答案:

答案 0 :(得分:2)

所以问题是每次启动应用程序时应用程序文档文件夹路径都会更改,而我正在存储视频文件的绝对路径。

根据这篇文章: http://pinkstone.co.uk/where-is-the-documents-directory-for-the-ios-8-simulator/,这就是现在在iOS 8中的情况,这就是为什么我的方法在iOS7中运行时却在iOS8设备和模拟器上失败了。谢谢@RoboticCat指出我正确的方向!