2

可能重复:
使用 UIImagePickerController 录制的视频

我是iOS 开发新手。现在我正在开发视频录制应用程序。但我的应用有时会录制视频。有时它会关闭相机给我警告

UIImagePickerController: ignoring request to stop video capture; camera is not currently capturing video.
4

1 回答 1

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];
}
于 2012-11-06T12:12:57.260 回答