UIImagePickerController and videorecording on iPhone 3GS
Hello,
I guess the following is a pretty simple task. When tapping on a button, I want to allow the user to record a video. However, when I call the UIImagePickerController it launches with the still camera and not with the video camera.
Here is a quote from Apple's docs:
Quote:
To record video, you must first check that the camera source type (UIImagePickerControllerSourceTypeCamera) is available and that the movie media type (kUTTypeMovie) is available for the camera. Depending on the media types you assign to the mediaTypes property, the picker can directly display the still camera or the video camera, or a selection interface that lets the user choose.
Now my question is (and sorry if it's a stupid one): How and what mediaType do I assign, so UIImagePickerController directly launches with the video camera?
The documentation is not at all clear on how to do this, but it's fairly straightforward.
Add the MobileCoreServices framework to your project
Add #import <MobileCoreServices/UTCoreTypes.h> to the header file where you will reference the picker. Alternately, you can add the import to your precompiled header file (.pch) so the UTCoreTypes constants are available throughout the project.
Now, before calling the UIImagePickerController, just set the mediaTypes property to the movie type, kUTTypeMovie. Or, if you wanted to only display photos you would use kUTTypeImage:
Keep in mind that you should check if the device supports video recording before setting the sourceType, as setting it to a movie type on a device that does not support video recording will cause all sorts of havoc. You do that by looking at the available source types:
Code:
NSArray *sourceTypes =
[UIImagePickerController availableMediaTypesForSourceType:myImagePickerController.sourceType];
if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){
// no movie type supported...add code to handle that here.
}
Quote:
Originally Posted by NewiPhoneDeveloper
Hello,
Now my question is (and sorry if it's a stupid one): How and what mediaType do I assign, so UIImagePickerController directly launches with the video camera?
__________________
Michael Emmons
Founder, App Apps, LLC http://app-apps.com
I have the similar project.I have tried to add the Framework MobileCoreServices,and it shows there is nothing like this instead CoreServices.
Whethere this will work or not?
Again I tried to add this and it become red in my Project framework.I can't understand why it is.Is there any problem with the Xcode installation?Or it is something else?
Please help me out from this problem.Its very important.Please....
Hi, I have done video recording and i would like to get the thumbnail image(preview) of the recorded video. i tried the below code in the delegate function,
The value for the key 'UIImagePickerControllerEditedImage' is nil. Is there any other way to get the thumbnail image or any changes to be done in the above function?
Hi, I have done video recording and i would like to get the thumbnail image(preview) of the recorded video. i tried the below code in the delegate function,
The value for the key 'UIImagePickerControllerEditedImage' is nil. Is there any other way to get the thumbnail image or any changes to be done in the above function?
thanks,
sumanth
Hi sumanth,
I want to do the same. Are you able to get Thumbnail image for Library stored videos? I can get thumbnail image for Captured videos.
I want to do the same. Are you able to get Thumbnail image for Library stored videos? I can get thumbnail image for Captured videos.
Any help would be appreciated.
Many thanks
Pratik
The thumbnail gets created in your apps /temp folder within its appspace,
anytime you pick a video or record a video. so in theory all you gotta do is:
Each time you import or record a video, have your app search the temp dir for the latest file created with the "jpg" extension.
Im working on this myself, ill post code if i figure it out
The thumbnail gets created in your apps /temp folder within its appspace,
anytime you pick a video or record a video. so in theory all you gotta do is:
Each time you import or record a video, have your app search the temp dir for the latest file created with the "jpg" extension.
Im working on this myself, ill post code if i figure it out
Okay my bad= the jpg only gets created when you record a video with the app, & NOT when importing from library.
Apparently there's a way to do it with ffmeg library though so I'll look into this
and here is supposedly how you'd get it from a recording:
Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
*// e.g.
*NSString *tempFilePath = [(NSURL *)[info valueForKey:UIImagePickerControllerMediaURL] absoluteString];
*NSLog(@"didFinishPickingMediaWithInfo: %@",tempFilePath);
*// e.g. /private/var/mobile/Applications/D1E784A4-EC1A-402B-81BF-F36D3A08A332/tmp/capture/capturedvideo.MOV
*tempFilePath = [[tempFilePath substringFromIndex:16] retain];
*NSLog(@"didFinishPickingMediaWithInfo: %@",tempFilePath);
*NSLog(@"===Try to save video to camera roll.===");
*NSLog(@"UIVideoAtPathIsCompatibleWithSavedPhotosAlbum: %@",UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath)? @"YES":@"NO");
*// Check if the video file can be saved to camera roll.
* * if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath)){
* // YES. Copy it to the camera roll.
* UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(video:didFinishSavingWithError:contextInfo:), tempFilePath);
*}
*[self dismissModalViewControllerAnimated:YES];
}
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(NSString *)contextInfo{
*NSLog(@"didFinishSavingWithError--videoPath in camera roll:%@",videoPath);
*NSLog(@"didFinishSavingWithError--videoPath in temp directory:%@",contextInfo);
*// The thumbnail jpg should located in this directory.
*NSString *thumbnailDirectory = [[contextInfo stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
*// Debug info. list all files in the directory of the video file.
*// e.g. /private/var/mobile/Applications/D1E784A4-EC1A-402B-81BF-F36D3A08A332/tmp/capture
*NSLog([contextInfo stringByDeletingLastPathComponent]);
*NSLog([[[NSFileManager defaultManager] contentsOfDirectoryAtPath:[contextInfo stringByDeletingLastPathComponent] error:nil] description]);
*// Debug info. list all files in the parent directory of the video file, i.e. the "~/tmp" directory.
*// e.g. /private/var/mobile/Applications/D1E784A4-EC1A-402B-81BF-F36D3A08A332/tmp
*NSLog(thumbnailDirectory);
*NSLog([[[NSFileManager defaultManager] contentsOfDirectoryAtPath:thumbnailDirectory error:nil] description]);
*///////////////////
*// Find the thumbnail for the video just recorded.
*NSString *file,*latestFile;
*NSDate *latestDate = [NSDate distantPast];
*NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:[[contextInfo stringByDeletingLastPathComponent]stringByDeletingLastPathComponent]];
*// Enumerate all files in the ~/tmp directory
*while (file = [dirEnum nextObject]) {
* // Only check files with jpg extension.
* if ([[file pathExtension] isEqualToString: @"jpg"]) {
* *NSLog(@"***latestDate:%@",latestDate);
* *NSLog(@"***file name:%@",file);
* *NSLog(@"***NSFileSize:%@", [[dirEnum fileAttributes] valueForKey:@"NSFileSize"]);
* *NSLog(@"***NSFileModificationDate:%@", [[dirEnum fileAttributes] valueForKey:@"NSFileModificationDate"]);
* *// Check if current jpg file is the latest one.
* *if ([(NSDate *)[[dirEnum fileAttributes] valueForKey:@"NSFileModificationDate"] compare:latestDate] == NSOrderedDescending){
* * latestDate = [[dirEnum fileAttributes] valueForKey:@"NSFileModificationDate"];
* * latestFile = file;
* * NSLog(@"***latestFile changed:%@",latestFile);
* *}
* }
*}
*// The thumbnail path.
*latestFile = [NSTemporaryDirectory() stringByAppendingPathComponent:latestFile];
*NSLog(@"****** The thumbnail file should be this one:%@",latestFile);
*// Your code ...
*// Your code ...
*// Your code ...
}
that was from another post I found, havnt had time to test yet