how can i write a NSData file as Video in to Photolibrary/SavedPhotosAlbum?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 12:28:56

问题


i have a Video file as NSData.how can i write the NSData file as Video in to Photolibrary/SavedPhotosAlbum?

i done it with UIimage through the following code. i had a UiImage as myNsData(NSData)

UIImage *viewImage = [UIImage imageWithData:myNsData];    

  ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];  
  // Request to save the image to camera roll  
  [library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
}

how can i do it the same functionality for Video.

i searched in NSData calss .

i found only two ways. they are

(void)writeVideoAtPathToSavedPhotosAlbum:(NSURL *)videoPathURL completionBlock:(ALAssetsLibraryWriteVideoCompletionBlock)completionBlock;

- (BOOL)videoAtPathIsCompatibleWithSavedPhotosAlbum:(NSURL *)videoPathURL;

two of them are using URL.actually i didn't want to write the NSData file any where except in Photolibrary/SavedPhotosAlbum.

i need to write the NSData file directly in to the Photolibrary/SavedPhotosAlbum like i saved an image.How can do that?can any one Help me?


回答1:


You need to create an AVAssetWriter with a video AVAssetWriterInput and add your data into the input.

When you create the AVAssetWriter, you need to specify an URL for the asset.

After you can use the ALAssetsLibrary (writeVideoAtPathToSavedPhotosAlbum:completionBlock:) to write the asset to the photo library, with the url of the asset created above.



来源:https://stackoverflow.com/questions/7290385/how-can-i-write-a-nsdata-file-as-video-in-to-photolibrary-savedphotosalbum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!