Powered By Blogger
Showing posts with label UIImagePickerController. Show all posts
Showing posts with label UIImagePickerController. Show all posts

Wednesday, April 25, 2012

Video recording in iPhone SDK

Hi,
Here is the integration code for Video Recording in your application. Please check it and follow the steps for integration of it.
You have to add "MobileCoreServices" framework in to your project source.

#import <UIKit/UIKit.h>


@interface AddVideoViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    UIImagePickerController *imagepicker;
}

-(IBAction)startRecording:(id)sender;
@end



#import "AddVideoViewController.h"

#include <MobileCoreServices/UTCoreTypes.h>
#include <MobileCoreServices/UTType.h>

@implementation AddVideoViewController


#pragma mark -
#pragma mark UIView life - cycle


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}

#pragma mark -
#pragma mark UIImagePickerController delegate methods


-(IBAction)startRecording:(id)sender
{
    imagepicker = [[UIImagePickerController alloc]init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagepicker.videoMaximumDuration = 10.0; // you can add more time limit for automatic record end
        imagepicker.delegate = self;
        imagepicker.allowsEditing = YES;
        imagepicker.showsCameraControls = YES;
        imagepicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
        imagepicker.videoQuality =  UIImagePickerControllerQualityTypeMedium;
        [self presentModalViewController:imagepicker animated:YES];
    }
    else
    {
        imagepicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        imagepicker.delegate = self;
        [imagepicker setAllowsEditing:YES];
        imagepicker.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentModalViewController:imagepicker animated:YES];
    }
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSURL *urlString = [info valueForKey:UIImagePickerControllerMediaURL];
    NSData *videoData = [NSData dataWithContentsOfURL:urlString];
    NSArray *Path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [Path objectAtIndex:0];
    NSString *filePath = [documentDirectory stringByAppendingPathComponent:@"video.mov"];
    [videoData writeToFile:filePath atomically:YES];
    UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, @selector(video:didFinishSavingWithError:contextInfo:), filePath);
    [self dismissModalViewControllerAnimated:YES];
}

- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
   
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
   
}

#pragma mark -
#pragma mark memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc. that aren't in use.
}


- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc
{
    [super dealloc];
}

@end


If any one has query then place you it over here.

Thanks and Regards,
Nilesh Prajapati