我正在尝试使用UIImagePickerController
录制两个视频。一切正常,但录制第二个视频时,它似乎覆盖了第一个录制视频的路径
我需要将两个视频上传到服务器,但第一个视频路径在上传和应用程序崩溃时为零。有没有办法在不同的路径上录制第二个视频?
视频路径如下:
/private/var/mobile/Containers/Data/Application/1465EC90-4B57-41FF-996E-0CCB7713ECE7/tmp/50332801315__A883E4DB-ED72-4D31-9564-22FB363779BD.MOV
/private/var/mobile/Containers/Data/Application/1465EC90-4B57-41FF-996E-0CCB7713ECE7/tmp/50332802324__F11733AD-EB62-426D-BA1C-7E87D2BF66D0.MOV
这是我的imagePicker
委托代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
NSURL *videoUrl = (NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
NSString *moviePath = [videoUrl path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
NSLog(@"videoUrl: %@", videoUrl);
NSLog(@"moviePath: %@", moviePath);
// self.moviePath_1 = @"";
// self.moviePath_2 = @"";
NSLog(@"picker.title: %@", picker.title);
if ([picker.title isEqualToString:@"Video_1"]) {
self.moviePath_1 = moviePath;
self.video_1 = YES;
NSLog(@"self.moviePath_1: %@", self.moviePath_1);
self.video_1_Data = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:self.moviePath_1]];
NSLog(@"Video_1 Size: %@",[NSByteCountFormatter stringFromByteCount:self.video_1_Data.length countStyle:NSByteCountFormatterCountStyleFile]);
[self setupAndPlayback:@"Video_1"];
} else {
self.moviePath_2 = moviePath;
self.video_2 = YES;
NSLog(@"self.moviePath_2: %@", self.moviePath_2);
self.video_2_Data = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:self.moviePath_2]];
NSLog(@"Video_2 Size: %@",[NSByteCountFormatter stringFromByteCount:self.video_2_Data.length countStyle:NSByteCountFormatterCountStyleFile]);
[self setupAndPlayback:@"Video_2"];
}
}
[self dismissViewControllerAnimated:YES completion:nil];
}
答案 0 :(得分:0)
将视频保存在不同的路径上。你正在克服这个问题发生的原因。添加时间戳或使用路径增加数字并保存。
self.moviePath_1 = [NSString stringWithFormat: @"%@-%d.png", moviePath, num] ;
num += 1; // for next time