Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to capture video in iPhone

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 save direct video in SQLite database? Is is possible, or I have to store path of video? If I have to save path in SQLite database, then how can I do this? Please help in this problem.

like image 684
Rocky Avatar asked Jun 08 '11 08:06

Rocky


1 Answers

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.

like image 179
amavi Avatar answered Sep 26 '22 14:09

amavi