2011-10-11 61 views
-2

我在〜/ Library/Application Support/iphone模擬器/ 4.3.2/Applications/ApplicationGUID/Documents文件夾中有.m4v視頻文件。但是我的應用程序在運行時崩潰。在NSlog中,它顯示文件路徑爲空。在iPhone模擬器中不顯示視頻

我有以下的代碼的applicationDidFinishLaunching:(UIApplication的*)應用

NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/Sample_ipod.m4v"]]; 
NSString *videoFilepath = [[NSBundle mainBundle] pathForResource:@"VID" ofType:@"m4v"]; 
NSLog(@"Filepath is: %@", videoFilepath); 

UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil); 
imagePickerController.delegate = self; 
imagePickerController.sourceType = 
UIImagePickerControllerSourceTypePhotoLibrary; 

imagePickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];  
[window addSubview:imagePickerController.view]; 

回答

0

檢查在filePath文件存在......你可能已經弄錯了路徑或文件正從你刪除捆綁,類似的東西。

使用NSFileManager檢查是否存在。

如果這樣不能解決它,請發佈有關崩潰的詳細信息。它崩潰的代碼行是什麼,它給了什麼信息?

0

您不會給我們提供崩潰詳細信息,所以我認爲它由於null filePath而崩潰。

有越來越Documents文件夾的更好的方法,例如:

NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"Sample_ipod.m4v"]; 

使用[[NSBundle mainBundle] pathForResource:...]是不會找到的文檔文件,這就是你說的這些文件。改爲使用上面顯示的代碼替代filePath。

+0

感謝Paul。我已經更新了我的代碼,但它仍然崩潰,它給出了以下error2011- 10-12 11:19:29.258 ios視頻​​電子郵件[46729:b303]文件路徑是:(空) 2011-10-12 11:19:32.219 ios視頻​​電子郵件[46729:b303] ***終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:'+ [NSInvocation invocationWithMethodSignature:]:方法簽名參數不能爲零' – user973637

+0

好吧,現在我可以獲取文件路徑。 (視頻:didFinishSavingWithError:contextInfo :),無); – user973637

+0

2011-10-12 11:36:28.323 IOS視頻電子郵件[46885:B303] filepath是:/用戶/ jonathanchen /庫/應用程序支持/ IPHON e Simulator/4.3.2/Applications/44B36E70-3EAE-4275-BA15-55B7E16AA25F/Documents/sample_ipod.m4v 2011-10-12 11:36:29.671 ios video email [46885:b303] ***終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:'+ [NSInvocation invocationWithMethodSignature:]:方法簽名參數不能爲零' – user973637

0

好的。我能弄明白。我沒有實現方法(視頻:didFinishSavingWithError:contextInfo。這就是爲什麼,我的應用程序崩潰了,它現在很好用