2013-03-31 120 views
0

我有一個vidoe應用程序,她所做的就是播放一個.mp4文件。 我想將該文件保存到iPhone中的相機膠捲中,然後播放。 我已經有了代碼,但由於某些原因視頻無法保存。視頻應用保存.mp4到相機膠捲

沒有錯誤,沒有任何東西似乎放錯地方,但仍然沒有保存。 我花了數小時的時間來解決這個問題,但沒有任何幫助。 如果有人可以幫我弄清楚嗎?請?可以嗎? 這裏是保存功能代碼...

- (IBAction)save{ 

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
    // don't forget to link to the AssetsLibrary framework 
    // and also #import <AssetsLibrary/AssetsLibrary.h> 

    NSString *filePathString = [[NSBundle mainBundle] pathForResource:@"video_name" ofType:@"mp4"]; 
    NSURL *filePathURL = [NSURL fileURLWithPath:filePathString isDirectory:NO]; 

    if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:filePathURL]) { 
     [library writeVideoAtPathToSavedPhotosAlbum:filePathURL completionBlock:^(NSURL *assetURL, NSError *error){ 
      if (error) { 
       // TODO: error handling 

      } else { 
       // TODO: success handling 
      } 
     }]; 
    } 
    } 
+0

請我沒有任何idear,它讓我的項目卡住了。所以,如果有人可以幫助我,這將是gratefull – user2229621

+0

這個問題已經被問了一個星期了..仍然沒有答案?這個網站的用途是什麼?只是爲了發佈代碼?或嘗試修復問題... – user2229621

回答

1

對不起沒有人回答了這點。如果你仍然需要幫助,這應該適合你:

- (IBAction)save{ 
    NSString *filePathString = [[NSBundle mainBundle] pathForResource:@"video_name" ofType:@"mp4"]; 
    NSURL *filePathURL = [NSURL fileURLWithPath:filePathString isDirectory:NO]; 

    UISaveVideoAtPathToSavedPhotosAlbum([filePathURL relativePath], self, @selector(video:didFinishSavingWithError:contextInfo:), nil); 
} 

- (void) video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{ 
    if (!error){ 
     // Saved successfully 
    } else { 
     // Error saving 
    } 
} 
+0

嗨,謝謝你的回答,但它不工作...它不保存到照片庫...不知道爲什麼? – user2229621

+1

如果您正在設備上進行測試,請確保您的應用有權訪問照片。另外,是否有錯誤?使用我的代碼,在// Error保存部分中,添加一個NSLog或一個斷點並查看它是否停在那裏。 – Cameron

+0

它工作正常,謝謝。 – iDev

相關問題