iPhone - picking a video... URL with two bars? - iphone

I have a UIPickerController to select videos in my App and it is crashing when selecting videos using the picker. When I feed the MPMoviePlayerController with the URL directly it works fine, but when the URL comes from the UIPickerController, it loads the movie correctly but crashes when the thumbnails are being created.
I have dumped the URL to the console, just after the file is selected and this is what I see
file://localhost/private/var/mobile/Applications/FA667F85-B009-46FA-A0B9-A7345A072651/tmp//trim.Ir0gqx.MOV
first question: why is the double bar before the file name?
second question: why the file name comes with a trim prefix if I have editing NO on the picker?
this is the picker code:
- (void) selectMovie:(id) sender {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
picker.delegate = self;
picker.allowsEditing = NO;
picker.videoQuality = UIImagePickerControllerQualityTypeHigh; // I've added this trying to make it stop compressing the video, but it won't... any clues?
UIPopoverController *aPopover =
[[UIPopoverController alloc] initWithContentViewController:picker];
aPopover.delegate = self;
CGRect myRect = [sender frame];
[aPopover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ( [ mediaType isEqualToString:#"public.movie" ]){
movieURL = [info objectForKey:UIImagePickerControllerMediaURL];
}
NSLog(#"%#", movieURL);
[self loadMovie:movieURL];
}

My thought is that your app does not have permission to generate thumbnails in the location where the movie is stored. Try copying the movie file out of the photo albums and into your documents directory:
NSFileManager *fm = [NSFileManager defaultManager];
[fm moveItemAtURL:fromURL toURL:toURL error:&error];
Assuming you have a toURL pointing to a filename in your docs directory.

I only know about the first one, because you need to feed to MPMoviePlayerController a url, a url has to start with a scheme, http://, smtp://, kind of that. file:// is also a scheme for file url

Related

how to get video from iphone Library

i want to pick a Video from Library. here is my code.
picker1 = [[UIImagePickerController alloc] init];
picker1.delegate = self;
NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
picker1.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker1.mediaTypes = mediaTypesAllowed;
[self presentModalViewController:picker1 animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
if ([picker isEqual:picker1])
{
NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:#"public.movie"]){
NSLog(#"%#",info);
}
}
problem is when i select video from Library, simulator getting hanged. Even delegate method didFinishPickingMediaWithInfo not calling
Thanks in advance.
Try This
myImagePickerController.mediaTypes =
[[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
or refer this
UIImagePickerControllerMediaType
Hope this helps u

UIImagePickerController with camera source with allows editing yes : video trimming doesn't work

I am using UIImagePickerController to record a video with the sourceType set to UIImagePickerControllerSourceTypeCamera.
I have set allowsEditing to true.
After capturing video I edit the video using the trimming interface and press "Use", I only get back the original recording not the trimmed version. What am I doing wrong?
I am using iOS 5.
-(void)shootvideo {
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker.view addSubview:test];
[imagePicker.view addSubview:test2];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
imagePicker.showsCameraControls = YES;
imagePicker.navigationBarHidden = NO;
imagePicker.toolbarHidden = NO;
imagePicker.wantsFullScreenLayout = YES;
imagePicker.allowsEditing=YES;
[self presentModalViewController:imagePicker animated:YES];
}
-(void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo)
{
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
//NSLog(#"%#",moviePath);
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
[self dismissModalViewControllerAnimated:YES];
}
I want to use that trimmed video for further processing according to my application.
Where I am going wrong?
Is there any other way to achieve this task?
allowsEditing : A Boolean value indicating whether the user is allowed to edit a selected still image or movie.
#property (nonatomic) BOOL allowsEditing
Discussion
If you allow the user to edit still images or movies, the delegate may receive a dictionary with information about the edits that were made. The protocol for the delegate is described in UIImagePickerControllerDelegate Protocol Reference.
I Think this will be helpful.
you need to grab the info[UIImagePickerControllerEditedImage] from the - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
I believe.

Emailing photo taken with ImagePickerController?

In my app I want to:
a.) Present camera to user to take picture
b.) Create email and attach picture taken
I figured out how to take the picture. But, I don't know how to attach it to the email. In the examples I've seen the filename is known. This is one example.
picker.mailComposeDelegate = self;
[picker setSubject:#"I have a pencil for you"];
UIImage *roboPic = [UIImage imageNamed:#"RobotWithPencil.jpg"];
NSData *imageData = UIImageJPEGRepresentation(roboPic, 1);
[picker addAttachmentData:imageData mimeType:#"image/jpg" fileName:#"RobotWithPencil.jpg"];
NSString *emailBody = #"This is a cool image of a robot I found. Check it out!";
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
I am getting the image from the callback method and it does get stored in the camera roll.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[picker dismissModalViewControllerAnimated:TRUE];
[picker release];
}
But from there, I'm not sure how to attach the image to the email? Mainly because I don't know what the filename is when a photo is added to the camera roll when the UIImagePickerController camera source is used to obtain it?
So, I guess I need to either:
a.) Find a way to get the name of the image file once it is saved OR
b.) Another way to attach UIImage data as an email attachment.
Any help appreciated.
maybe I don't understand what you are trying to do UI wise, but why would this not work from your code provide:
EDIT: (changed code to use a delegate)
- (void)imagePickerController:(UIImagePickerController *)imagepicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
if([delegate respondsToSelector:#selector(didSelectImage:)])
[delegate didSelectImage:image];
}
this goes in your header file (usually above your class declaration):
#protocol PostHelperDelegate <NSObject>
#optional
- (void)DimissModal;
//image data for image selected
- (void)DidSelectImage:(UIImage*)image;
#end
also you need to create this property in your class
#property(nonatomic,assign)id<PostHelperDelegate>* delegate; //don't forgot to synthizie
then in the class implementing the delegate you will assign the delegate your class:
Poster = [[delegateclass alloc] init];
Poster.delegate = self;
then just add the delegate function:
- (void)DidSelectImage:(UIImage*)image
{
//handle image here
}
I simplify this quite a bit, let me know if you have any trouble getting it working
http://www.roostersoftstudios.com/2011/04/12/simple-delegate-tutorial-for-ios-development/
BEFORE UPDATE:
personally I would use a delegate to notify that the image has been picked and than launch the mail picker, but that is another thing. As far as the UIImage, I don't know a way or have never found a way to name/or get a name from the UIImagePicker as I do not believe they are named anything meaningful. Any questions on the delegate or further explanation let me know.
use bellow code
-(void)yourmethodname_clicked{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
else{
UIAlertView *altnot=[[UIAlertView alloc]initWithTitle:#"Camera Not Available" message:#"Camera Not Available" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[altnot show];
[altnot release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
MFMailComposeViewController *mailpicker = [[MFMailComposeViewController alloc] init];
[mailpicker.navigationBar setTintColor:[UIColor blackColor]];
mailpicker.mailComposeDelegate = self;
[mailpicker setSubject:#"set your subject"];
NSArray *toRecipients = [NSArray arrayWithObjects: nil];
[mailpicker setToRecipients:toRecipients];
UIImage *picture = [info objectForKey:#"UIImagePickerControllerOriginalImage"]];;
NSData *imageData = UIImagePNGRepresentation(picture);
[mailpicker addAttachmentData:imageData mimeType:#"image/png" fileName:#"set your file name"];
NSString *emailBody = #"set your body string";
[mailpicker setMessageBody:emailBody isHTML:YES];
[mailpicker setSubject:#"set your subject"];
mailpicker.title = #"Email";
[self presentModalViewController:mailpicker animated:YES];
[mailpicker release];
}
may this help you

How to retrieve a video from the UISaveVideoAtPathToSavedPhotosAlbum

In my APP im saving the video to photolibrary using UISaveVideoAtPathToSavedPhotosAlbum. I am getting the path of the video but i am not able to play this video. Can any 1 help me with this on how to retrieve the saved video.Thanks in advance.I used the Code shown below.
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
} else {
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, #selector(video:didFinishSavingWithError:contextInfo:), nil);
NSLog(#"temp path %#",tempFilePath);
[picker dismissModalViewControllerAnimated:YES];
}
NSURL *url = [NSURL fileURLWithPath:tempFilePath];
and Play the url using: "MPMoviePlayerController"
The path that is returned by this function needs a suffix. try this
NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSURL *videoURL = [NSURL URLWithString:[NSString stringWithFormat:#"file://localhost%#", videoPath]];

Capture Video as well as Images in iPhone

I am using ImagePickerController for Video Capturing. I need to save the capturing video as image also.
So I selected AVCaptureSession for capturing Images. I'm not able to run AVCaptureSession as well as ImagePickerController. So I need to give the ImagePickerController as input to the AVCaptureSession.
But I don't know how to do that. Please Help me.. and suggest me for the right way.
I found only these two. Hope its helps.
http://www.iphonedevsdk.com/forum/iphone-sdk-development/24025-uiimagepickercontroller-videorecording-iphone-3gs.html
UIImagePickerController: Getting image capture from video
I was having same issue.. I did work on image and video and used below code for image capturing:
- (void) snapImage: (id) sendern
{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.delegate = self;
ipc.allowsImageEditing = YES;
[self presentModalViewController:ipc animated:YES];
}
And for video recording i used below code:
- (void) recordVideo: (id) sender
{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.delegate = self;
ipc.allowsEditing = YES;
ipc.videoQuality = UIImagePickerControllerQualityTypeMedium;
ipc.videoMaximumDuration = 30.0f; // 30 seconds
ipc.mediaTypes = [NSArray arrayWithObject:#"public.movie"];
// ipc.mediaTypes = [NSArray arrayWithObjects:#"public.movie", #"public.image", nil];
[self presentModalViewController:ipc animated:YES];
}
Hope will help you both code snippets.
- (IBAction) useCamera: (id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker
animated:YES];
newMedia = YES;
}
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.popoverController dismissPopoverAnimated:true];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = image;
if (newMedia)
UIImageWriteToSavedPhotosAlbum(image, self,
#selector(image:finishedSavingWithError:contextInfo:),nil);
}
}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Save failed"
message: #"Failed to save image"
delegate: self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
The Apple docs and sample code related to AVFoundation has several mistakes. See iOS 4: Take photos with live preview using AVFoundation for code that actually captures images from a live preview.