URL for video selected from camera roll - iphone

I am able to launch camera roll from my app. I want to get the URL of the video when it is selected by a user, because I want to use it for asset reading/writing.
Is it possible to get the URL of the selected video from camera roll ? If yes, how ?
Thanks.

Set the UIImagePickerControllerDelegate to your class and use this code to retrieve the url.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[self dismissModalViewControllerAnimated:YES];
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
}
This is a good resource:Accessing the Camera and Photo Library from an iOS 4 iPhone Application

Related

Get video from photo album & save it to image view in app

Currently I am developing an app in which I want to get photo album saved video and then show selected
video in image view & then later on send this video to Facebook. I successfully open the photo album
but now how can i save selected video in image view of app.
I think you have used UIImagePickerController to open the photo album (mediaType will be kUTTypeMovie)
Use the below UIImagePickerController delegate to get the videoUrl and Its thumbnail
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *videoURL = [info valueForKey:UIImagePickerControllerReferenceURL];
UIImage *videoThumbnail = [info valueForKey:UIImagePickerControllerOriginalImage];
You can save the videoURL and retrieve the Video later using ALAsset_Class or even you can set the url to moviePlayer. [moviePlayer setContentURL:movieURL];
You can use the videoThumbnail to deal with UiImages
Finally, do a Google search to Share video to Facebook.

iPhone: How to find the duration of the album video?

I am picking video from photo album programmatically. I don't have any issues on that. I am able to retrieve the video path etc from the following delegate method.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
But, i want to find out the duration of the video here. Is it possible to find out the duration of that video which i have chosen from photo album?
Please advise!
Thank you!

Storing a reference to an image saved in the Camera Roll

I've been working on a simple application which allows the user to take a photo and store it in the camera roll for later use. To do this, I am using a UIImagePickerController, and the method UIImageWriteToSavedPhotosAlbum, which is working perfectly.
My question is: Is there any way to store the path to the image in the Camera Roll so that I can use that to call the image again later? Or, do I have to save the image in the app in order to use it again later?
It would be great if there was a simple way to do this, as there is with a video where you just store the NSUrl for the particular video, and then call MPMoviePlayerController to do everything for you.
Any help would be much appreciated!
It turns out that it is actually not that hard to do this. In the UIImagePickerDelegate method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
the NSDictionary "info" actually contains the url to the image or the movie which is stored on the Camera Roll. You need only check:
if([[info valueForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeMovie]){ // If the user took a video,
movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] retain];// Get the URL of where the movie is stored.
UISaveVideoAtPathToSavedPhotosAlbum([movieURL path], nil, nil, nil); // Save the movie to the photo album.
}
and this will save the movie to the Camera Roll, as well as record the url. Doing it for a photo is analogous, just replace the "kUTTypeMovie" with "kUTTypeImage", and replace
movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] retain];// Get the URL of where the movie is stored.
UISaveVideoAtPathToSavedPhotosAlbum([movieURL path], nil, nil, nil); // Save the movie to the photo album.
with
UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
If you need to store the UIImage not on the Camera Roll, there is a great post on stackoverflow Saving UIImage with NSCoding that you can use to store the image in your app. Hope that helps someone!

Image editing on iphone

In my app i need to select a image from photos library and then user should be able to crop or scale the the image. Can any one please help me?
UIImagePickerController should do the trick.
UIImagePickerController *picker = [UIImagePickerController new];
picker.delegate = self;
picker.allowsEditing = YES;
[yourViewController presentModalViewController:picker];
Then we need to implement the delegate method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
}
You can use a UIImagePickerController to let the user select an image from the photos library.
#denizen
The
[yourViewController presentModalViewController:picker]; needs an animated:BOOL.
Like: [yourViewController presentModalViewController:picker animated:YES];
You can also have a look at SSPhotoCropperViewController. It’s a custom view controller that provides a simple, configurable and easy-to-use UI for cropping and scaling photos in iPhone & iPod Touch apps.
For picking photos from the Photo Library, UIImagePickerController does well. However you cannot use it for the photos you get from another sources, say Flickr, FB etc.
Here is the tutorial and the source code on GitHub for SSPhotoCropperViewController.

copy video from iphone using the UIImagePickerController?

Hey, I know that when a user selects a Video I do get a URL for the video.... but can you direct me to a proper implementation because my App just sticks there when I click choose in the simulator and I cannot navigate away from the Video Player page....
Any good tutorial on this?
Once you select the video - execution flows to the following function:
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
.... code here .....
//get the videoURL
NSString* videoURL= [info objectForKey:UIImagePickerControllerMediaURL];
//IMPORTANT: remember to test that the video is compatible for saving to the photos album
UISaveVideoAtPathToSavedPhotosAlbum(videoURL, self, #selector(video:didFinishSavingWithError:contextInfo:), nil);
.... code here .....
}
Take a look into 'UISaveVideoAtPathToSavedPhotosAlbum' specifically. This allows saving to the camera roll.