开发者

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

开发者 https://www.devze.com 2023-04-02 08:09 出处:网络
i have a Video file as NSData.how can i write the 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.actu开发者_C百科ally 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消