2012-06-07 271 views
5
- (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); 
    } 
} 

我使用UISaveVideoAtPathToSavedPhotosAlbum保存錄制的視頻。我想知道我保存錄制的視頻的專輯的絕對路徑。IOS如何能UISaveVideoAtPathToSavedPhotosAlbum返回保存的視頻路徑?

我怎麼能得到保存的路徑? UISaveVideoAtPathToSavedPhotosAlbum不返回任何。

並在回調函數video:didFinishSavingWithError:contextInfo:仍然沒有路徑信息。

回答

2

據我所知..你不能得到保存在相冊中的視頻的路徑。如果你想從你的應用程序重播文件列表。您可以在應用程序中包含所有視頻。

以下是將您的示例代碼放在didFinishPickingMedia中以將視頻存儲在輔助文檔中..以便您可以跟蹤它。

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

希望這有助於你..