How to retrieve a video from the UISaveVideoAtPathToSavedPhotosAlbum - iphone

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]];

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

Attaching multiple image to an email

I am using ELCimagepicker to attach multiple image to an email but I'm not sure how to make every NSData unique so i can attach them to my email.
>
- (void)launchController {
ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] initWithNibName:#"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
[albumController setParent:elcPicker];
[elcPicker setDelegate:self];
[self presentModalViewController:elcPicker animated:YES];
}
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info {
[self dismissModalViewControllerAnimated:YES];
int i = 0;
for(NSDictionary *dict in info) {
i++;
UIImageView *imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]];
NSData *name = UIImageJPEGRepresentation(imageview, 1.0);
}
}
Get the app from this link
https://github.com/elc/ELCImagePickerController
and following changes from the code
using for loop
-(IBAction)launchController
{
ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] initWithNibName:#"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
[albumController setParent:elcPicker];
[elcPicker setDelegate:self];
ELCImagePickerDemoAppDelegate *app = (ELCImagePickerDemoAppDelegate *)[[UIApplication sharedApplication] delegate];
[app.viewController presentModalViewController:elcPicker animated:YES];
[elcPicker release];
[albumController release];
[self buttonPressed];
}
- (void)buttonPressed
{
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// Delegate is self
imagePicker.delegate = self;
// Allow editing of image ?
imagePicker.allowsImageEditing = NO;
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
}
- (void)emailImage:(UIImage *)image
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
// Set the subject of email
[picker setSubject:#"Picture from my iPhone!"];
// Add email addresses
// Notice three sections: "to" "cc" and "bcc"
[picker setToRecipients:[NSArray arrayWithObjects:#"emailaddress1#domainName.com", #"emailaddress2#domainName.com", nil]];
[picker setCcRecipients:[NSArray arrayWithObject:#"emailaddress3#domainName.com"]];
[picker setBccRecipients:[NSArray arrayWithObject:#"emailaddress4#domainName.com"]];
// Fill out the email body text
NSString *emailBody = #"I just took this picture, check it out.";
for (int i=0; i<[imagedelegate.imgarray count]; i++)
{
UIImageView *image=[[UIImageView alloc] init];
image=[imagedelegate.imgarray objectAtIndex:i];
// This is not an HTML formatted email
[picker setMessageBody:emailBody isHTML:NO];
// Create NSData object as PNG image data from camera image
NSData *data = UIImagePNGRepresentation(image);
// Attach image data to the email
// 'CameraImage.png' is the file name that will be attached to the email
[picker addAttachmentData:data mimeType:#"image/png" fileName:#"CameraImage"];
// Show email view
[self presentModalViewController:picker animated:YES];
// Release picker
[picker release];
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// Dismiss the camera
[self dismissModalViewControllerAnimated:YES];
// Pass the image from camera to method that will email the same
// A delay is needed so camera view can be dismissed
[self performSelector:#selector(emailImage:) withObject:image afterDelay:1.0];
// Release picker
[picker release];
}
Download and drag the Objective-Zip, MiniZip and ZLib drag in to your project from this link http://code.google.com/p/objective-zip/downloads/list (Objective-zip).. import the files: ZipFile.h, ZipException.h, FileInZipInfo.h, ZipWriteStream.h, ZipReadStream.h, zlib.h
Use the following code:
NSString *stringPath1 = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]];
NSString *FileName=[stringPath1 stringByAppendingPathComponent:#"Your file name"];
NSString *stringPath=[stringPath1 stringByAppendingPathComponent:[#"Your file name" stringByAppendingFormat:#".zip"]];
NSArray *files = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:FileName error:&error];
ZipFile *zipFile = [[ZipFile alloc]initWithFileName:stringPath mode:ZipFileModeCreate];
for(int i = 0;i<files.count;i++){
id myArrayElement = [files objectAtIndex:i];
NSLog(#"add %#", myArrayElement);
NSString *path = [FileName stringByAppendingPathComponent:myArrayElement];
NSDictionary *attributes = [[NSFileManager defaultManager]attributesOfItemAtPath:path error:&error];
NSDate *Date = [attributes objectForKey:NSFileCreationDate];
ZipWriteStream *streem = [zipFile writeFileInZipWithName:myArrayElement fileDate:Date compressionLevel:ZipCompressionLevelBest];
NSData *data = [NSData dataWithContentsOfFile:path];
[streem writeData:data];
[streem finishedWriting];
}
[zipFile close];

iPhone:import Video from iphone library

i am importing Video from iphone library In my app...but i am unable to do show i studied lots of code on stack over flow but none are working..for me..Basically i am doing sharing on fb and twitter...
..
-(IBAction)showVideoLibrary
{
UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
videoPicker.delegate = self;
videoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
videoPicker.mediaTypes =[[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie,nil];    
if(self.popoverController!=nil)
{
   [self.popoverController release];
}
self.popoverController  = [[UIPopoverController alloc] initWithContentViewController:videoPicker];
popoverController.delegate = self;
popoverController.popoverContentSize=CGSizeMake(320,1000);
[popoverController presentPopoverFromRect:CGRectMake(0,0,10,10) inView:self.view permittedArrowDirections:nil animated:YES];
}
thanks in advance
Try it on a real iPhone device.
Here is the code for picking video from iPhone library which i have used in my project.
Just add video method from selector to your desired button.
-(void)video
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[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];
NSURL *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
// NSLog(#"%#",moviePath);
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
[self dismissModalViewControllerAnimated:YES];
[picker release];
}
Do not forget to add mobile core services framework and to import
#import <MobileCoreServices/UTCoreTypes.h>
the string "moviepath" give you the path of the video in that iPhone then perform any desired thing with that video
You will get video path after compressing is done in string movie pathenter code here
MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: url]; // give here the "videourl"
[[player view] setFrame: [self.view bounds]];
[self.view addSubview: [player view]];
[player play];

To save recorded video

Please can anyone provide any sample code to save video after recording.
I m able to record video using UIImagePickerController.
if (canShootVideo) {
UIImagePickerController *videoRecorder = [[UIImagePickerController alloc] init];
videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
videoRecorder.delegate = self;
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
NSArray *videoMediaTypesOnly = [mediaTypes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"(SELF contains %#)", #"movie"]];
BOOL movieOutputPossible = (videoMediaTypesOnly != nil);
if (movieOutputPossible) {
videoRecorder.mediaTypes = videoMediaTypesOnly;
[self presentModalViewController:videoRecorder animated:YES];
}
[videoRecorder release];
}
but how to save it. Can anyone please tell.
Thanks in advance
- (void)saveVideo:(NSURL *)videoUrl {
NSData *videoData = [NSData dataWithContentsOfURL:videoUrl];
[videoData writeToFile:#"YOUR_PATH_HERE" atomically:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *type = [mediaDict objectForKey:UIImagePickerControllerMediaType];
if ([type isEqualToString:(NSString *)kUTTypeVideo] ||
[type isEqualToString:(NSString *)kUTTypeMovie]) { // movie != video
NSURL *videoURL [mediaDict objectForKey:UIImagePickerControllerMediaURL];
[self saveVideo:videoUrl];
}
}
This is for the case you want to save the video into some file path that you can control. You can save into "Saved Photos" as well

how to show video or movie file into UIImagePickerController?

I am using UIImagePickerController that gives user to be able select an existing photo or use the camera to take an image at that time. And i can show that image in my application with UIImageView.
Now i want to use this ability for movies also. But i couldn't find any way to show the selected movie as an image in my app, just like the Photos app. as you know you can see photos and movies in the same list.
-(IBAction) selectImageSelected : (id)sender
{
actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select Image"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Take Picture", #"Select from gallery", nil];
[actionSheet showInView:self.parentViewController.tabBarController.view];
}
- (void)actionSheet:(UIActionSheet *)_actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex==0)
{
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] )
{
[AlertHandler showAlertMessage:[ErrorMessages getCameraNotFoundMsg] withTitle:#"No Camera Detected"];
return;
}
else
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
}
}
else if(buttonIndex==1)
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
[self presentModalViewController:imagePicker animated:YES];
}
else
{
[actionSheet dismissWithClickedButtonIndex:2 animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:#"public.image"]){
// UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
NSLog(#"found an image");
// [UIImageJPEGRepresentation(image, 1.0f) writeToFile:[self findUniqueSavePath] atomically:YES];
// SETIMAGE(image);
CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:#"/Documents"]]);
}
else if ([mediaType isEqualToString:#"public.movie"]){
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(#"found a video");
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
//NSData *video = [[NSString alloc] initWithContentsOfURL:videoURL];
// [webData writeToFile:[self findUniqueMoviePath] atomically:YES];
CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:#"/Documents"]]);
CGSize sixzevid=CGSizeMake(imagePicker.view.bounds.size.width,imagePicker.view.bounds.size.height-100);
UIGraphicsBeginImageContext(sixzevid);
[imagePicker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
eventButton.imageView.image=viewImage;
// NSLog(videoURL);
}
[picker dismissModalViewControllerAnimated:YES];
}
/*
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo1
{
[imagePicker dismissModalViewControllerAnimated:YES];
imagePicker.view.hidden = YES;
eventButton.imageView.image = image;
imageSelected = YES;
}
*/
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[imagePicker dismissModalViewControllerAnimated:YES];
imageSelected = NO;
}
The -thumbnailImageAtTime:timeOption: method of MPMoviePlayerController looks like it might help you get an image to display.
To have the picker view with only movie files
replace
imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
with
picker.mediaTypes = [NSArray arrayWithObject:#"public.movie"];