我正在尝试使用glimpse来录制UIView。它成功将其保存到应用程序的文档文件夹中,但是我还需要它保存到用户的相机胶卷。它没有保存到相机胶卷,我收到警报,允许该应用访问我的相机胶卷,但它没有保存在任何相册中。
我尝试过相当数量的代码:
[self.glimpse startRecordingView:self.view onCompletion:^(NSURL *fileOuputURL) {
NSLog(@"DONE WITH OUTPUT: %@", fileOuputURL.absoluteString);
UISaveVideoAtPathToSavedPhotosAlbum(fileOuputURL.absoluteString,nil,nil,nil);
}];
对此:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:fileOuputURL
completionBlock:^(NSURL *assetURL, NSError *error){NSLog(@"hello");}];
日志打印但不会将视频保存到相机胶卷。
如果有人对我有任何想法这不起作用请告诉我! 谢谢!
答案 0 :(得分:11)
问题在于提供的视频路径。提供网址的相对路径。
if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileUrl.relativePath) {
UISaveVideoAtPathToSavedPhotosAlbum(fileUrl.relativePath, nil, nil, nil)
}
如果您已添加此 UIVideoAtPathIsCompatibleWithSavedPhotosAlbum ,请检查编译器是否会向您显示该文件的问题。
答案 1 :(得分:4)
问题是您作为网址提供的视频路径,因此您必须检查您的网址路径是否可以保存在视频中,如果您想在camara roll中保存视频,那么只需传递网址并按照以下代码操作:
-(void)saveVideo:(NSString *)videoData withCallBack:(void(^)(id))callBack{
library = [[ALAssetsLibrary alloc] init];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *yourVideoData=[NSData dataWithContentsOfURL:[NSURL URLWithString:videoData]];
if (yourVideoData) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"video.mp4"];
if([yourVideoData writeToFile:filePath atomically:YES])
{
NSURL *capturedVideoURL = [NSURL URLWithString:filePath];
//Here you can check video is compactible to store in gallary or not
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:capturedVideoURL]) {
// request to save video in photo roll.
[library writeVideoAtPathToSavedPhotosAlbum:capturedVideoURL completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
callBack(@"error while saving video");
NSLog(@"error while saving video");
} else{
callBack(@"Video has been saved in to album successfully !!!");
}
}];
}
}
}
});
}