即使使用fileURLWithPath,AVURLAsset也不会在文档文件夹上加载视频

时间:2016-02-21 04:15:22

标签: ios swift avfoundation avurlasset avkit

过去几个小时一直在努力解决这个问题,希望有人在此之前遇到过这个问题

我将文件从服务器下载到我的文档文件夹

文件存在且有效(在设备上使用iExplorer和模拟器的本地目录进行检查)。将每个文件移动到我的桌面并播放没有问题。

奇怪的是,当文件(同一视频)被添加到捆绑包中时,完全相同的代码可以正常工作。

代码:

print("video url string   :   \(video.urlString)")   
// prints: /var/mobile/Containers/Data/Application/47AC756B-7A00-4FAE-9348-214972BE61BD/Documents/demo-reel.mp4
// file IS there

let asset = AVURLAsset(URL: NSURL(fileURLWithPath: video.urlString))
let keys = ["tracks","playable","duration"]

asset.loadValuesAsynchronouslyForKeys(keys, completionHandler: { () -> Void in
                var error : NSError? = nil
            let status = asset.statusOfValueForKey("tracks", error: &error)

            switch status {
            case .Failed:
                print("failed \(error?.localizedDescription)")
            case .Loaded:                  
                print("loaded \(error?.localizedDescription)")
            case .Loading:
                print("loading \(error?.localizedDescription)")
            case .Cancelled:
                print("cancelled \(error?.localizedDescription)")
            case .Unknown:
                print("unknown \(error?.localizedDescription)")


            }

prints: failed Optional("The requested URL was not found on this server.")
我错过了什么吗?感谢帮助

0 个答案:

没有答案