我是 iOS开发的新手。现在我正在制作视频录制应用程序。但我的应用有时录制视频。有时它关闭相机给我警告
UIImagePickerController: ignoring request to stop video capture; camera is not currently capturing video.
答案 0 :(得分:1)
我正在以这种方式捕获视频并存储在文档目录中: -
-(IBAction)cameraLibraryButtonClick:(id)sender{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *videoRecorder = [[UIImagePickerController alloc]init];
videoRecorder.delegate = self;
NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:videoRecorder.sourceType];
NSLog(@"Available types for source as camera = %@", sourceTypes);
if (![sourceTypes containsObject:(NSString*)kUTTypeMovie] ) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:@"Device Not Supported for video Recording." delegate:self
cancelButtonTitle:@"Yes"
otherButtonTitles:@"No",nil];
[alert show];
[alert release];
return;
}
videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
videoRecorder.mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeMovie];
videoRecorder.videoQuality = UIImagePickerControllerQualityTypeLow;
videoRecorder.videoMaximumDuration = 120;
self.imagePicker = videoRecorder;
[videoRecorder release];
[self presentModalViewController:self.imagePicker animated:YES];
newMedia = YES;
}
else {
[self displaysorceError];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
//self.fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory , NSUserDomainMask, YES);
NSString *ZipLibrary = [paths objectAtIndex:0];
NSString *FileFullPath = [ZipLibrary stringByAppendingPathComponent:@"%@.mp4"];
NSLog(@"Ziplinrnr oadfjaidfjidfjidjfid %@",FileFullPath);
[videoData writeToFile:FileFullPath atomically:YES];
[self dismissModalViewControllerAnimated:YES];
}
-(void)displaysorceError{
UIAlertView *alt = [[UIAlertView alloc]
initWithTitle:@"Error"
message:@"Camera Image Sorce Not Available"
delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alt show];
[alt release];
}