有没有办法从文件中访问视频数据?打开视频文件的唯一方法是创建AVAsset.但这对我来说还不够.
我知道了
func requestExportSessionForVIDeo(_ asset: PHAsset!,options options: PHVIDeoRequestoptions!,exportPreset exportPreset: String!,resultHandler resultHandler: ((AVAssetExportSession!,[NSObject : AnyObject]!) -> VoID)!) -> PHImageRequestID
但在我的情况下,我只是想将视频上传到我不想做的服务:
>首先通过导出到我的本地应用数据来复制视频
>然后将数据发送到我们的服务.
>删除数据.
上面这种方法使用了大量额外的空间和时间,用户使用完整的16GB iPhone无法正常工作.
好的,这是我到目前为止使用URL尝试的
var anAcces = sourceURL?.startAccessingSecurityScopedResourceif !NSfileManager.defaultManager().fileExistsAtPath(sourceURL!.path!) { NSLog("not exist")}var afileCoordinator = NSfileCoordinator(filePresenter:nil)var anError: NSError?afileCoordinator.coordinateReadingItemAtURL(sourceURL!,options:.ForUploading,error:&anError,byAccessor: { (newURL: NSURL!) -> VoID in var data = NSData(contentsOfURL: newURL) })if let unError = anError { NSLog("Error \(unError)")}sourceURL?.stopAccessingSecurityScopedResource
这记录以下内容:
2015-02-08 16:20:01.947 Cameo[15706:2288691] not exist2015-02-08 16:20:01.991 Cameo[15706:2288691] Error Error Domain=NSCocoaErrorDomain Code=257 "The operation Couldn’t be completed. (Cocoa error 257.)" UserInfo=0x170876480 {NSURL=file:///var/mobile/Media/DCIM/100APPLE/img_0155.MOV,NSfilePath=/var/mobile/Media/DCIM/100APPLE/img_0155.MOV,NSUnderlyingError=0x17005a9a0 "The operation Couldn’t be completed. Operation not permitted"}解决方法 感谢保罗的建议我明白了:
您必须在该块中创建一个PHImageManager requestAVAssetForVIDeo会话,您可以访问该文件并从该URL读取其数据.
let imageManager = PHImageManager.defaultManager() let vIDeoRequestoptions = PHVIDeoRequestoptions() vIDeoRequestoptions.deliveryMode = .HighQualityFormat vIDeoRequestoptions.version = .Current vIDeoRequestoptions.networkAccessAllowed = true vIDeoRequestoptions.progressHandler = { (progress: Double,error: NSError!,stop: UnsafeMutablePointer<ObjCBool>,[NSObject : AnyObject]!) -> VoID in NSLog("Progress: %@",progress.description) } vIDeoRequestoptions.progressHandler = { (progress: Double,progress.description) } imageManager.requestAVAssetForVIDeo(nextAsset,options: vIDeoRequestoptions,resultHandler: { (avAsset: AVAsset!,avAudioMix: AVAudioMix!,info: [NSObject : AnyObject]!) -> VoID in if let nextURLAsset = avAsset as? AVURLAsset { let sourceURL = nextURLAsset.URL if NSfileManager.defaultManager().fileExistsAtPath(sourceURL.path!) { NSLog("exist file") } var data = NSData(contentsOfURL: sourceURL) if let aData = data { NSLog("length : <\(aData.length)") } else { NSLog("no data read.") } } }总结
以上是内存溢出为你收集整理的iOS Photo Library读访问权限全部内容,希望文章能够帮你解决iOS Photo Library读访问权限所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)