简体   繁体   中英

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.

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.

You would be able to store the video data in sqlite as raw data BUT I would strongly recommend AGAINST this. The performance would be awful. Better to save the video to the documents directory and then a path to that in the DB.

If you are working with sqlite then you should look at CoreData, it makes managing persistence a lot easier... download the source code for my core data tutorial as it contains a nice storage service wrapper... tutorial here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM