在ios中将NSMutableData转换为NSURL for video

时间:2014-08-20 11:40:02

标签: ios photolibrary

在接收数据的套接字流中,我可以将NSMutableData放入图片并能够保存在照片中但无法将NSMutableData转换为视频

我正在做的图像

UIImage *imagess = [[UIImage alloc]initWithData:received];
//dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    UIImageWriteToSavedPhotosAlbum(imagess, nil, nil, nil);
}); 

有人帮我做同样的视频吗?

1 个答案:

答案 0 :(得分:0)

首先,您需要将视频另存为本地文件。

NSData *receivedData;
…
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"movie.mp4"];
[receivedData writeToFile:path atomically:YES]; 

然后你可以使用UISaveVideoAtPathToSavedPhotosAlbum函数将视频文件保存到Photo roll。

NSURL movieURL=[NSURL fileURLWithPath:path];

if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(movieURL)){
    UISaveVideoAtPathToSavedPhotosAlbum(movieURL, nil, nil, nil);
}