2
林創建一個簡單的應用程序的視頻數據到錄製的視頻上傳到Web API。在應用程序錄制視頻後,我可以順利播放應用程序內的視頻,但我掙扎訪問視頻進行上傳。檢索從本地文件系統
視頻是assets-library://asset/asset.MOV?id=3AFCEC9B-17DE-4D75-9B87-0AD50BAB9BFF&ext=MOV
,可以使用MPMoviePlayerController(contentURL: url)
,所以我知道它的存在有被加載。
我試過沒有成功以下幾個方法:
方法1
let url = NSURL(fileURLWithPath: thisNote.url!)
println("This url = \(thisNote.url)")
let videoData = NSData(contentsOfURL: url!, options: nil, error: &e)
錯誤= The operation couldn’t be completed. No such file or directory
方法2
let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let docsDir = dirPaths[0] as! String
let videoFilePath = docsDir.stringByAppendingPathComponent(Constants.Directories.appFolder)
let filePath = NSBundle.pathForResource(thisNote.fileName, ofType: "video/quicktime", inDirectory: Constants.Directories.appFolder)
文件路徑= nil
方法3
var video:NSData = NSData()
ALAssetsLibrary().assetForURL(url, resultBlock: { (asset : ALAsset!) -> Void in
if let rep : ALAssetRepresentation = asset.defaultRepresentation(){
var error: NSError?
let length = Int(rep.size())
let from = Int64(0)
let data = NSMutableData(length: length)!
let numRead = rep.getBytes(UnsafeMutablePointer(data.mutableBytes), fromOffset: from, length: length, error: &error)
video = data
self.uploadNote(video, note: thisNote)
}
}){ (error : NSError!) -> Void in
println("Asset library error: \(error)")
}
結果塊未到達,也不是印刷錯誤。
任何幫助,將不勝感激。
什麼是AssetLibraryHelper也是一樣的? –