2014-04-01 24 views
1

我是新來的客觀C,因此在新手上犯的錯誤讓我無法接受。不能將保存的.mov文件移動到照片卷

因此,我有一個錄製視頻並將其保存到iPad的庫。保存後,我想將其移入照片庫中,但無法使其工作。

BOOL success = [videoWriter finishWriting]; 
     if (!success) { 
      NSLog(@"finishWriting returned NO"); 
     } 

    [self cleanupWriter]; 

    id delegateObj = self.delegate; 
    NSString *outputPath = [[NSString alloc] initWithFormat:@"%@/%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0], @"output.mov"]; 
    NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath]; 

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
    if([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputURL]){ 
    [library writeVideoAtPathToSavedPhotosAlbum:outputURL completionBlock:^(NSURL *assetURL, NSError *error){ 
     if(error){ 
      NSLog(@"Failed to save movie"); 
     } 
     else{ 
      NSLog(@"Saved movie"); 
     } 
    }]; 
    } 
    else{ 
     if(UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(outputPath)){ 
      UISaveVideoAtPathToSavedPhotosAlbum(outputPath, nil, nil, nil); 
     } 
     else{ 
      NSLog(@"Didn't save movie"); 
     } 
    } 

這將永遠返回沒有保存電影。這表示視頻不兼容放入視頻中。問題是,我看不出它有什麼問題,因爲我在iOS上運行它之前,無法查看視頻,直到它出現在視頻中。

我一直堅持這一段時間,我希望有人能給我一些指針。

回答

0

試試這個代碼 -

NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; 

    if (CFStringCompare((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) 
    { 
     NSString *moviePath = [[info objectForKey: UIImagePickerControllerMediaURL] path]; 

     if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) 
     { 
      UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil); 
     } 
    } 
+0

感謝您的快速回復。你的代碼給了我一個'使用未聲明的標識符'信息''NSString * moviePath = [[info 任何想法爲什麼? – user3484356

+0

在 - (無效)imagePickerController:(UIImagePickerController *)選擇器didFinishPickingMediaWithInfo:(NSDictionary *)上面的代碼中寫入信息 – Viper

+0

嗯我不認爲這是在我當前的項目中進行的回調...我沒有用戶選擇一個視頻,但我的圖書館記錄屏幕並將其保存到文件。我如何強制調用該方法? – user3484356