December 2012
Intermediate to advanced
834 pages
27h
English
You want to allow your users to shoot a video using their iOS device, and you would like to be able to use that video from inside your application.
Use UIImagePickerController
with the UIImagePickerControllerSourceTypeCamera source
type and the kUTTypeMovie media
type:
-(void)viewDidLoad{[superviewDidLoad];if([selfisCameraAvailable]&&[selfdoesCameraSupportTakingPhotos]){UIImagePickerController*controller=[[UIImagePickerControlleralloc]init];controller.sourceType=UIImagePickerControllerSourceTypeCamera;NSString*requiredMediaType=(__bridgeNSString*)kUTTypeMovie;controller.mediaTypes=[[NSArrayalloc]initWithObjects:requiredMediaType,nil];controller.allowsEditing=YES;controller.delegate=self;[self.navigationControllerpresentModalViewController:controlleranimated:YES];}else{NSLog(@"Camera is not available.");}}
The isCameraAvailable
and doesCameraSupportShootingVideos methods used
in this sample code are implemented and discussed in Recipe 13.1.
We will implement the delegate methods of the image picker controller like so:
-(void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary*)info{NSLog(@"Picker returned successfully.");NSLog(@"%@",info);NSString*mediaType=[infoobjectForKey:UIImagePickerControllerMediaType];if([mediaTypeisEqualToString:(__bridgeNSString*)kUTTypeMovie]){NSURL*urlOfVideo=[infoobjectForKey:UIImagePickerControllerMediaURL ...
Read now
Unlock full access