问题描述
我有一个Video文件,如NSData.如何将NSData文件作为Video写入Photolibrary/SavedPhotosAlbum?
我通过以下代码使用UIimage完成了此操作.我有一个UiImage作为 myNsData (NSData)
UIImage * viewImage = [UIImage imageWithData:myNsData];ALAssetsLibrary * library = [[ALAssetsLibrary alloc] init];//请求将图像保存到相机胶卷[图书馆writeImageToSavedPhotosAlbum:[viewImage CGImage]方向:(ALAssetOrientation)[viewImage imageOrientation]完成块:^(NSURL * assetURL,NSError * error){}
我该如何为视频执行相同的功能.
我在NSData calss中搜索了.
我发现只有两种方法.他们是 (void)writeVideoAtPathToSavedPhotosAlbum:(NSURL *)videoPathURLcompleteBlock:(ALAssetsLibraryWriteVideoCompletionBlock)completionBlock;-(BOOL)videoAtPathIsCompatibleWithSavedPhotosAlbum:(NSURL *)videoPathURL;
其中两个正在使用URL.实际上,除了Photolibrary/SavedPhotosAlbum中的任何地方,我都不想写NSData文件.
我需要像保存图像一样直接将NSData文件写入到Photolibrary/SavedPhotosAlbum中.该怎么办?有没有人可以帮助我?
您需要使用视频AVAssetWriterInput创建一个AVAssetWriter并将您的数据添加到输入中.
创建AVAssetWriter时,需要指定资产的URL.
在您可以使用ALAssetsLibrary(writeVideoAtPathToSavedPhotosAlbum:completionBlock :)将资产与上面创建的资产的URL写入照片库后.
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.
这篇关于如何将NSData文件作为Video写入Photolibrary/SavedPhotosAlbum?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!