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.
Related
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.
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
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!
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!
While the following code is saving the image I took from my application into the camera roll. I am trying to figure out how to update the thumbnail image that displays in the left corner next to the take image button when you first launch the camera to be the image that I saved. Shouldn't it always be the last image added to the camera roll? Here is how I am saving it:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *originalImage = [info valueForKey:UIImagePickerControllerOriginalImage];
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(originalImage, nil, nil, nil);
}
}
I'm pretty sure there's nothing you can do to change that thumbnail; it's the Camera app's business what goes in there. At any rate, I think it is defined to contain a thumbnail of the last photo you took using the camera app.
I just tried this:
Launch Camera. Take a photo.
Launch Safari. Save an image from a page.
Launch Camera. The thumbnail is the photo I took, not the saved image.
I say either let it be or file a bug with Apple if you feel the behavior is incorrect.