iPhone video recording: "cameraCaptureMode 1 not available because mediaTypes does contain public.movie"
开发者_JAVA技巧I tried to record a video. The message I got is from the following code on the device:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = YES;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
Any ideas? I think it should be really easy to take a video. When I start the "Camera" app of the phone I have the choice between video and picture. Shouldn't it be available for my app also?
The problem was the way I was trying to set the mode to video mode.
Instead of using this:
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
I changed it to this:
imagePickerController.mediaTypes =
[NSArray arrayWithObject:(NSString *)kUTTypeMovie];
and it worked.
For Swift 3.0, you have to add below line to support both photo and video
import MobileCoreServices
imagePicker.mediaTypes = [kUTTypeMovie as String, kUTTypeImage as String]
Add to above answers, as Micko mentioned, you need to add MobileCoreServices.framework in your project and ref it in your imagePickerController. For those who want to have a switch under the toolbar in your image shooting view, just set the mediaTypes delegate as follows:
imagePC.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
Now, you can have both still image taking and video taking, enjoy!!!
Xcode 9 - Swift 4.x:
Take care about the order of these statements:
imagePickerController.mediaTypes = [kUTTypeMovie as String]
imagePickerController.cameraCaptureMode = .video
And you remember to add to info.plist:
And if you are working with Swift, then you will have to add MobileCoreServices.framework as well as the following Module where you are trying to record the video!
import MobileCoreServices
Then overall your code will something like this
var imag = UIImagePickerController()
imag.delegate = self
imag.sourceType = UIImagePickerControllerSourceType.Camera;
imag.cameraDevice = UIImagePickerControllerCameraDevice.Rear //or Front
imag.mediaTypes = [kUTTypeMovie];
self.presentViewController(imag, animated: true, completion: nil)
This method will opens the library of videos in my ipod 4.Not the video camera of my device.
Will someone tell me how to sort out from the problem ,I have tried the both ways described above.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = YES;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
and
imagePickerController.mediaTypes =
[NSArray arrayWithObject:(NSString *)kUTTypeMovie];
Thanks for your help.
enter code herePlease try this,this will opens the video camera
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *tmp_picker=[[UIImagePickerController alloc]init];
tmp_picker.sourceType=UIImagePickerControllerSourceTypeCamera;
tmp_picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
tmp_picker.delegate=self;
[self presentModalViewController:tmp_picker animated:YES];
[tmp_picker release];
NSLog(@"button index is %i",buttonIndex);
}
精彩评论