Discussion Forums  >  Uncategorized

Replies: 16    Views: 323

rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
10/24/11 07:34 AM (14 years ago)

Launch camera for video

All I want to do is launch native video camera in the app for user to capture video and send through email. This seems simple but I can only find the option for images and not video. Thanks
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
10/24/11 10:46 AM (14 years ago)
There is not a built-in buzztouch screen for capturing video. However...you could... a) Copy the BT_screen_imageEmailer.m and .h files and rename them BT_screen_videoEmail.m and .h. You'll need to rename the classes themselves after renaming the files. Do this by changing the text in both files to the new name. When you're done you'll have two new files in your Xcode project. b) In your control panel, use the Custom Plugin option and enter BT_screen_video as the Class Name. Connect this to a menu item. When you run the app your newly created class file will load. It looks the same as the image emailer at this point because you havn't customized it. Now that it's loading you can freely adjust the code without breaking anythign else in the project. Try to get your head around the image capture logic and see if you can capture video. It's been awhile since I've worked with the video logic so I'm not much help there. Like you said, once the screen is loading (step a and b) getting video instead of still can't be that tough.
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/24/11 05:15 PM (14 years ago)
Thanks David. I just can not tell you how much I appreciate everyone here. The customer service, quick responses and genuine concern is very refreshing and is one of the major missing pieces with many businesses these days. Apple is another one of the few businesses that also project this quality. Thanks again... Ross
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/24/11 11:20 PM (14 years ago)
Got the plugin working.. I can take video or I can choose now from the camera roll too for video, but once I stop the video and select Use, I don't get the option to email... same with selecting from camera roll, it compresses but then next screen no option to email... I think I am very close. Any ideas? Maybe email is looking for an image and not a video... thanks, Ross
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
10/25/11 10:10 PM (14 years ago)
Great news! I'm thinking the issue is the file that we need to email. Two things are happening in the BT_screen_imageEmailer.m file. First, the user selects (or snaps) a photo. When this happens we need to 'remember' the name of the image that the device saved. iOS saves this image to a temporary location on the device. You can see in the didFinishPickingMediaWithInfo method where we are figuring out what iOS named this new image. At this point this is a file on the iOS file system, we need to remember the name of the file so we can attach the file to the email when the email compose sheet opens. On line 334 you'll see: [self setImageFileName:imageName]; This is where we are 'remembering' the image name. So, this repeats over and over again each time the user selects or snaps a new photo. When they do, we show the photo so they know what they selected. We also remember the image itself. Not just the image name, the actual image. We do this in the setImage method on line 387. So, we have the name of the image, and the image itself. We need the image so we can get to it's data when it's time to email it. Next, when they are done messing around with photos, the actual emailing takes place. We know the user is done with the image stuff when the popoverControllerDidDismissPopover method is fired. This method fires when the user finishes image stuff. So, when this happens we show a list of options. When the click the Emal Image button the [self emailImage] method is fired. This is on line 177. Sidenote: I see a typo, in a comment on line 258 it reads //upload image when it should read //email image, funny. Fixed for next update. Ok....the emailImage method in this class is only doing a few things. It checks to make sure we have an image name, then the actual image. If we have both of these it calles the: +(void)sendEmailWithScreenData:(BT_item *)theScreenData:(UIImage *)imageAttachment:(NSString *)imageAttachmentName method in the BT_viewControllerManager.m class. This methods takes a bunch of arguments, one of which is an actual image. If we call this method with an image included in the argument it will add the image as an attachment. Thats how we do it here. Remember that other parts of the program may also call this method but when they do they do not include an image so no attachment is included in the email compose sheet. So, call the method, pass an image, it's attached. This is where are problem is.... You want to attach a video, not an image. I can think of a few different ways to do this. First, you'll need to figure out what the heck iOS has saved the video file as and it's location. Not sure abou this, maybe you already figured this out. I would just copy the entire method name in the BT_viewControllerManager.h and .m files that we are using to email images. Paste in a new method name in the .h and the actual method in .m. Name your new method something like... +(void)sendEmailWithVideoAttachment:(BT_item *)theScreenData:(UIImage *)imageAttachment:(NSString *)imageAttachmentName On line 295 (or so depending on what you changed) call your new method and pass the video as an argument so it's included in the email as an attachment. If you're not confused already, take a deep breath, you will be soon. This stuff is hard to figure out unless you've messed with it. Don't worry, you're close. If you're having trouble getting to the video file, have a look at this for some tips on how to save the video, get it into another object (NSData) suitable for emailing, etc. I'm thinking my comments and the comments at the URL below, together with the code you have in front of you will get it done. http://stackoverflow.com/questions/1065628/uploading-video-with-iphone
 
ThomasB
Lost but trying
Profile
Posts: 162
Reg: Jun 23, 2011
Palo Alto
3,270
like
10/26/11 10:10 AM (14 years ago)
+following this topic
 
EBBApps
I hate code!
Profile
Posts: 5
Reg: Dec 31, 2011
Alpharetta
50
like
01/03/12 01:32 PM (14 years ago)
following this topic
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
01/31/12 11:50 PM (14 years ago)
After 2 months of searching and taking pieces from here and there (and learning xcode) this code will open the video camera only, capture video (retake or use) if use is chosen it automatically attaches the video to the email, hit send. Wow this was tough but I learned a ton about coding. here it is. Dave or someone else here that knows should check it out for bugs but it works! - (void) useCamera { UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeMovie,nil]; imagePicker.allowsEditing = NO; [self presentModalViewController:imagePicker animated:YES]; } - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:@UIImagePickerControllerMediaURL]; [self dismissModalViewControllerAnimated:YES]; [self performSelector:@selector(emailImage:) withObject:image afterDelay:1.0]; [picker release]; } - (void)emailImage:(UIImage *)image { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setSubject:@Golf Swing Analysis - DUPLESSISGOLF]; [picker setToRecipients:[NSArray arrayWithObjects:@[email protected], nil]]; [picker setCcRecipients:[NSArray arrayWithObject:@]]; [picker setBccRecipients:[NSArray arrayWithObject:@]]; NSString *emailBody = @I will reply to you once I've received your swing videos. Thank you.; [picker setMessageBody:emailBody isHTML:NO]; NSData *data = [NSData dataWithContentsOfURL:(NSURL *)image]; [picker addAttachmentData:data mimeType:@video/MOV fileName:@MySwingVideo.mov]; [self presentModalViewController:picker animated:YES]; [picker release]; } - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { [self dismissModalViewControllerAnimated:YES]; } can be modified easily to access the camera roll instead... hope this helps someone.
 
ThomasB
Lost but trying
Profile
Posts: 162
Reg: Jun 23, 2011
Palo Alto
3,270
like
02/01/12 11:01 AM (14 years ago)
Wow, congrats! Ross that is a big effort to learn the language and build this at the same time. And, integrated photo support is a signficant feature for so many customer uses. Where did you end up inserting the above code, was it in the line as discussed by David, or elsewhere?
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
02/01/12 12:02 PM (14 years ago)
well, I learned enough (maybe) using the storyboard to lay out the app in the sdk and have another page that calls out to streaming sample video and am about to try to submit it to iTunes to see if it will fly outside of BT for the first time. I think I know just enough to be dangerous haha. I made this so golfers can send me their golf swings from the driving range and I analyze their swing videos. I would have used the BT server if it had a Streaming Video plugin... I'm having the best time learning and BT got it all going for me... you guys are the best.
 
Monte
Code is Art
Profile
Posts: 5
Reg: Jan 16, 2012
La Jolla
50
like
02/03/12 08:10 PM (14 years ago)
Hi Ross, I'm in the process of building an app that will need to do precisely what you just accomplished...record a video and then email it. Would you be open to sharing a little more detail on how you structured your solution? Did you base it on copied versions of BT_screen_imageEmailer as David mentioned or from scratch? I have a java background but just now getting into objective-c so the syntax is still a bit foreign. Thanks!
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
02/03/12 10:33 PM (14 years ago)
It is still pretty foreign to me too. At this point I am not using BT and have put it altogether in the sdk. I was finding it more difficult to fit it into the BT structure because I am still learning, so I just built the app in the sdk. I think if you look at the code logically, now that I have the missing pieces, you might pick up where I left off and get it to work in the BT_screen_imageEmailer. I wish I could be more helpful but the objective c light bulb is just starting to glow. FYI, Since I posted the code above, I've added a few more lines of code to check to see that the device has a camera and an alert if not... and, if the device can send email and an alert for that as well. Here is the updated version (still might have bugs but it works): #import ViewController.h @implementation ViewController - (void) useCamera{ if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { NSArray *media = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera]; if ([media containsObject:(NSString*)kUTTypeMovie] == YES) { UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; [imagePicker setMediaTypes:[NSArray arrayWithObject:(NSString *)kUTTypeMovie]]; imagePicker.delegate = self; [self presentModalViewController:imagePicker animated:YES]; } else { UIAlertView *alertCamera = [[UIAlertView alloc] initWithTitle:@Unsupported! message:@Camera does not support photo capturing. delegate:nil cancelButtonTitle:@OK otherButtonTitles:nil]; [alertCamera show]; [alertCamera release]; } } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@Unavailable! message:@This device does not have a camera. delegate:nil cancelButtonTitle:@OK otherButtonTitles:nil]; [alert show]; [alert release]; } } - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:@UIImagePickerControllerMediaURL]; [self dismissModalViewControllerAnimated:YES]; [self performSelector:@selector(emailImage:) withObject:image afterDelay:1.0]; [picker release]; } - (void)emailImage:(UIImage *)image { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; if ([MFMailComposeViewController canSendMail]){ picker.mailComposeDelegate = self; [picker setSubject:@Golf Swing Analysis - DUPLESSISGOLF]; [picker setToRecipients:[NSArray arrayWithObjects:@[email protected], nil]]; [picker setCcRecipients:[NSArray arrayWithObject:@]]; [picker setBccRecipients:[NSArray arrayWithObject:@]]; NSString *emailBody = @I will reply to you once I've received your swing videos. Thank you.; [picker setMessageBody:emailBody isHTML:NO]; NSData *data = [NSData dataWithContentsOfURL:(NSURL *)image]; [picker addAttachmentData:data mimeType:@video/MOV fileName:@MySwingVideo.mov]; [self presentModalViewController:picker animated:YES]; [picker release]; } else { UIAlertView *alertEmail = [[UIAlertView alloc] initWithTitle:@Sorry, can not send email! message:@This device does can not send email. delegate:nil cancelButtonTitle:@OK otherButtonTitles:nil]; [alertEmail show]; [alertEmail release]; } } - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { [self dismissModalViewControllerAnimated:YES]; } @end
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
02/04/12 01:19 AM (14 years ago)
@ rossideas: Very proud of you and super stoked that you stuck with this long enough to see it through. FOOOOOORE. When we get done doing the mundane (building the new site and creating tons of training vids) we'll get back to creating plugins...this for sure is on the list thanks to you.
 
Monte
Code is Art
Profile
Posts: 5
Reg: Jan 16, 2012
La Jolla
50
like
02/04/12 10:15 AM (14 years ago)
Ross - this is great, it'll be a huge help. thanks! David - you have an awesome tool here. I'd be more than happy to work on putting this function into a plugin if you're open to contributions
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
02/09/12 01:39 PM (14 years ago)
I just uploaded to iTunes my Golf Swing Analysis app (my first solo no BT app) that uses the above code and we'll see if it passes. FYI - I wasted 2.5 hours last night trying to upload and getting an error about the Icon.png being 0 x 0 and needs to be 57x57 (which it was) and could not validate and come to find out it is an uploader issue in the last Lion update.. but there is a workaround download that fixed it. Here is the link http://blog.manbolo.com/2012/02/02/macosx-10.7.3-update-breaks-ios-app-validation if anyone is having the same problem.
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
02/09/12 04:13 PM (14 years ago)
Nice work. I'll try this myself
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
02/15/12 11:06 PM (13 years ago)
FYI for those that have been following this post... my app Golf Swing Analysis that contains the above code pass review 1st time ... I had changed the code some to also put a copy of the video to be emailed on the camera roll for backup for the user.. Thanks again David and everyone that helped.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.