从文档目录中检索视频,但应用无法找到位置

时间:2017-08-02 22:05:32

标签: ios swift xcode video core-data

我已经实现了Core Data,以便在我的应用程序中保存字符串格式的URL。这些URL是他们录制的视频的URL。

我使用了核心数据,因为我希望视频在退出应用后仍可供他们使用。我能够保存和检索URLS。但是,当我使用它们来获取视频缩略图时,它不起作用。

这是我声明视频文件位置的地方:

let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
    let cropUniqueId = NSUUID().uuidString
    let outputPath = "\(documentsPath)/\(cropUniqueId).mov"

然后我将其转换为字符串并将数据保存到核心数据:

 arrayOfStringPaths.append(outputPath)
    stringOfArrayPaths = stringOfArrayPaths + arrayOfStringPaths.joined(separator: ",")
    saveData(arrayPath: stringOfArrayPaths)



 func saveData(arrayPath: String) {

    let savedVideo = VideoPath(context: context)
    savedVideo.fileLocations = arrayPath
    appDelegate.saveContext()
    print("Saved")

}

到目前为止一切正常。它保存了URL,就像它们一样,我用各种打印语句检查它们。

现在,当用户打开应用程序时,我会检索信息。

var data = [VideoPath]()

    func fetchSavedData() {
    do {
        data = try context.fetch(VideoPath.fetchRequest())


        for each in data {
            // I append each url to the array. 
            videosArray.append(URL(fileURLWithPath: each.fileLocations!))

            // They all print out correctly 
            print(each.fileLocations!)
        }

        for video in videosArray {
            print("This is in video array")
            // This prints out correctly as the URL i recorded earlier
            print(video) 

            // This is where everything messes up
            let thumbnail = getThumbnail(video)
            thumbnails.append(thumbnail)

        }

    } catch {
        print("There was an error")
    }

}

当我尝试获取视频的缩略图时,它会在此处显示此错误:

  

“在此服务器上找不到请求的网址。” UserInfo = {NSLocalizedDescription =在此服务器上找不到请求的URL。,NSUnderlyingError = 0x17064c330 {错误域= NSPOSIXErrorDomain代码= 2“没有这样的文件或目录”}}:file /Library/Caches/com.apple.xbs/Sources /swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift

0 个答案:

没有答案