Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS -how could UISaveVideoAtPathToSavedPhotosAlbum return the saved video path?

Tags:

ios

iphone

video

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];


    //get the videoURL 
    NSString *tempFilePath = [videoURL path];


    if ( UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath))
    {
      // Copy it to the camera roll.
      UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(video:didFinishSavingWithError:contextInfo:), tempFilePath);
    } 
}

I use UISaveVideoAtPathToSavedPhotosAlbum to save video recorded. And I want to know the absolute path in the album where I saved the recorded video.

How could I get the saved Path? UISaveVideoAtPathToSavedPhotosAlbum does not return any.

and in the callback function video:didFinishSavingWithError:contextInfo: there is still not path info.

like image 553
lingzhao Avatar asked Nov 04 '22 22:11

lingzhao


1 Answers

As far as I know.. You cannot get the path for the videos saved in the Photo album. If you want the files list to be replayed from your app. You can have all the videos inside your application.

Following is your sample code to put inside didFinishPickingMedia to store the videos in side documents.. So that you can keep track of it.

   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d", 1]];
    NSString *fileName = [NSString stringWithFormat:@"%@ :%@.%@", itsIncidentType, [dateFormatter stringFromDate:incidentDate], @"mp4"];
    [dateFormatter release];
    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
        [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder
    NSURL *videoURL = [imageInfo objectForKey:UIImagePickerControllerMediaURL];
    NSData *webData = [NSData dataWithContentsOfURL:videoURL];
    self.itsVideoName = fileName;
    [webData writeToFile:[NSString stringWithFormat:@"%@/%@",dataPath,fileName] atomically:TRUE];

Hope this helps you..

like image 143
Dilip Rajkumar Avatar answered Nov 15 '22 06:11

Dilip Rajkumar