简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM