Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-23-2009, 04:37 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 459
Default 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?

Any help appreciated. Thanks in advance.
NewiPhoneDeveloper is offline   Reply With Quote
Old 08-20-2009, 05:05 PM   #2 (permalink)
http://app-apps.com
 
Join Date: Jun 2009
Location: Los Angeles, CA
Posts: 446
Lightbulb

The documentation is not at all clear on how to do this, but it's fairly straightforward.
  1. Add the MobileCoreServices framework to your project
  2. 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:
Code:
myImagePickerController.mediaTypes =  
   [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
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 View Post
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



VideoBot | Audiotorium Notes | Thought Bubbles
MichaelE is offline   Reply With Quote
Old 10-07-2009, 05:19 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 1
Default

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....

Waiting for your assistance......

Thanx
subha is offline   Reply With Quote
Old 10-08-2009, 11:33 AM   #4 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 2
Default POP up picker

Can I piggy back off that question? How can you get the popup that slides up asking what you want to do:

Take Video:
Take Picture:
Choose from Library:

Everything I find has separate buttons. Kinda like in the facebook app when you click on the camera button you get this picture.

http://skitch.com/bharned3/nnmei/photo.jpg

Last edited by bharned3; 10-10-2009 at 06:22 PM. Reason: spelling
bharned3 is offline   Reply With Quote
Old 10-27-2009, 03:01 AM   #5 (permalink)
Registered Member
 
sumanth's Avatar
 
Join Date: Jul 2009
Location: India
Posts: 78
Default

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,

Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
	UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage];
	imagvid.image=image;
}
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
sumanth is offline   Reply With Quote
Old 11-15-2009, 11:47 PM   #6 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 2
Default Sample code for video recording

Hi Sumanth,

I am new to iphone development and I need some sample code for video recording. Please help.

Regards,
Susanta
xchangingiphone is offline   Reply With Quote
Old 11-16-2009, 12:39 AM   #7 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,890
Default

Quote:
Originally Posted by bharned3 View Post
Can I piggy back off that question? How can you get the popup that slides up asking what you want to do:

Take Video:
Take Picture:
Choose from Library:

Everything I find has separate buttons. Kinda like in the facebook app when you click on the camera button you get this picture.

Skitch.com > bharned3 > photo.jpg
That is called an UIActionSheet
__________________
I really do this.
Bertrand21 is offline   Reply With Quote
Old 11-16-2009, 07:36 AM   #8 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: michigan
Posts: 185
Default

Quote:
Originally Posted by Bertrand21 View Post
That is called an UIActionSheet
read this blog article , any questions pm me.

Recorded video from iphone 3gs - Life in The Clouds
michelle is offline   Reply With Quote
Old 03-18-2010, 12:46 AM   #9 (permalink)
iGuru
 
Join Date: Oct 2009
Location: India
Posts: 12
Send a message via Yahoo to pratikgoswami Send a message via Skype™ to pratikgoswami
Default

Quote:
Originally Posted by sumanth View Post
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,

Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
	UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage];
	imagvid.image=image;
}
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.

Any help would be appreciated.

Many thanks
Pratik
pratikgoswami is offline   Reply With Quote
Old 04-01-2010, 01:17 AM   #10 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 22
Default

Quote:
Originally Posted by pratikgoswami View Post
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.

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
mrburns05 is offline   Reply With Quote
Old 04-01-2010, 12:16 PM   #11 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 22
Default

Quote:
Originally Posted by mrburns05 View Post
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
mrburns05 is offline   Reply With Quote
Old 04-02-2010, 10:22 AM   #12 (permalink)
Registered Member
 
sumanth's Avatar
 
Join Date: Jul 2009
Location: India
Posts: 78
Default

simple, i got the screen shot image as soon i use the video . Here is the code,

Code:
 - (void)imagePickerController:(UIImagePickerController *)picker1 didFinishPickingMediaWithInfo:(NSDictionary *)info
 {
	 
	 CGSize sixzevid=CGSizeMake(picker1.view.bounds.size.width,picker1.view.bounds.size.height-100);
	 UIGraphicsBeginImageContext(sixzevid);
	 [picker1.view.layer renderInContext:UIGraphicsGetCurrentContext()];
	 UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
	 UIGraphicsEndImageContext();
	 imagvid.image=viewImage;
 }
You will ge the image in imagvid, use it where ever you need
sumanth is offline   Reply With Quote
Old 04-02-2010, 11:43 AM   #13 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 22
Default

That's genious! Thanks!
mrburns05 is offline   Reply With Quote
Old 05-06-2010, 07:04 AM   #14 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 3
Smile Video Recording

Hi,
I am very new to iphone app.
will u please forward me the source code to record video using UIImagePickerController.
Thanx in advance
subhashmaxnet is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 247
14 members and 233 guests
ADY, CKAmike, Dani77, dessicant, Duncan C, HemiMG, jakerocheleau, nick.keroulis, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:23 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0