Search code examples
objective-cios4video-capture

How to capture video from iphone app?


I open the video mode while press the record button. Then i can capture the video. After capture the video record has to be stop. Now below the screen display retake button in the left side and use button in the right side. Here is my problem started, If I press use button, How can I save the video different name in a specific folder?. And How can I access that videos from that specific folder?.

Please give idea with sample code to resolve this problem.

Thanks in advance,

Senthilkumar


Solution

  • You will have to implement to become the delegate of the UIImagePickerController object and implement imagePickerController:didFinishPickingMediaWithInfo: like this –

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
        // This is the URL where the movie is stored (in the tmp directory)
        NSURL *movieURL = [info objectForKey:UIImagePickerControllerMediaURL];
    
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"movie.mov"]; // You will have to vary this.
        NSURL *fileURL = [NSURL URLWithString:filePath];
    
        NSError *error;
        if ( [[NSFileManager defaultManager] moveItemAtURL:movieURL toURL:fileURL error:&error] ) {    
            NSLog(@"Error copying: %@", [error localizedDescription]);
        }
    
        [self dismissModalViewControllerAnimated:YES];
    }