how to capture video in iPhone

后端 未结 2 1237
一整个雨季
一整个雨季 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:05

    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

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题