how to capture video in iPhone

后端 未结 2 1238
一整个雨季
一整个雨季 2021-02-06 14:54

I am creating application for video app in iPhone, but I don\'t know how to capture a video in iPhone; and I want to store them in SQLite database, but I have one problem: can I

2条回答
  •  渐次进展
    2021-02-06 15:06

    Only iPhone 3GS and above support video recording.so you should first check if recording is supported and then start camera with desired values set for properties,using following code.
    You will have "MobileCoreServices/MobileCoreServices.h" to run this code.

                if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {              
                    UIImagePickerController *videoRecorder = [[UIImagePickerController alloc]init];         
                    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;
                    videoRecorder.delegate = self;
                    self.recorder_ = videoRecorder;                 
                    [videoRecorder release];
                    [self presentModalViewController:self.recorder_ animated:YES];                  
                }
    

    Then you should implement following delegate method to save the captured video.Storing video path in SQL/coredata would be ideal instead of storing entire video file in it.

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
     if ([type isEqualToString:(NSString *)kUTTypeVideo] || 
        [type isEqualToString:(NSString *)kUTTypeMovie]) { // movie != video
        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
        NSData *videoData = [NSData dataWithContentsOfURL:videoUrl];
        NSString *videoStoragePath;//Set your video storage path to this variable
        [videoData writeToFile:videoStoragePath atomically:YES];
        //You can store the path of the saved video file in sqlite/coredata here.
    }
    }
    

    Hope this helps.

提交回复
热议问题