2012-03-26 60 views
0

所以我遇到的問題是,當我嘗試加載視頻這種方式:我收到SIGABRT當我嘗試加載視頻(Objective-C的)

-(void) viewDidLoad 
{ 
MyManager *sharedManager = [MyManager sharedManager]; 
[super viewDidLoad]; 
NSString *tempName = sharedManager.vidName; 
NSLog(@"%@", tempName); 

//This is where the problem is being caused 
NSString *url = [[NSBundle mainBundle] pathForResource:tempName ofType:@"mp4"]; 
//This is where I'm getting the SIGABRT thrown 
MPMoviePlayerController* theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallBack:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie]; 
theMovie.scalingMode = MPMovieScalingModeAspectFit; 
[theMovie.view setFrame:self.view.bounds]; 
[self.view addSubview:theMovie.view]; 
[theMovie play]; 

} 

我得到一個SIGARBT拋出我在代碼中由於NSException而指定的地方。但是,如果我簡單地寫出字符串,如下所示:

- (void)viewDidLoad 
{ 
MyManager *sharedManager = [MyManager sharedManager]; 
[super viewDidLoad]; 
NSString *tempName = sharedManager.vidName; 
NSLog(@"%@", tempName); 

//This is the line I changed 
NSString *url = [[NSBundle mainBundle] pathForResource:@"vid_name" ofType:@"mp4"]; 

MPMoviePlayerController* theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallBack:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie]; 
theMovie.scalingMode = MPMovieScalingModeAspectFit; 
[theMovie.view setFrame:self.view.bounds]; 
[self.view addSubview:theMovie.view]; 
[theMovie play]; 

} 

代碼工作得很好。問題是什麼?我NSLog的tempName,以確保它保持正確的字符串,它是。另外,sharedManager.vidName是一個NSMutableString。這是我完成高級項目和大學畢業後留下的唯一問題,所以任何幫助都將不勝感激。謝謝。

這裏是我得到的日誌中:

2012-03-26 22:04:52.115 SeniorProject[20502:207] Barbell Incline Bench Press - Medium Grip 
2012-03-26 22:04:52.120 SeniorProject[20502:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter' 
*** Call stack at first throw: 
(
0 CoreFoundation      0x00fb15a9 __exceptionPreprocess + 185 
1 libobjc.A.dylib      0x01105313 objc_exception_throw + 44 
2 CoreFoundation      0x00f69ef8 +[NSException raise:format:arguments:] + 136 
3 CoreFoundation      0x00f69e6a +[NSException raise:format:] + 58 
4 Foundation       0x007e3ab6 -[NSURL(NSURL) initFileURLWithPath:] + 90 
5 Foundation       0x007e3a44 +[NSURL(NSURL) fileURLWithPath:] + 72 
6 SeniorProject      0x000105f4 -[Video viewDidLoad] + 420 
7 UIKit        0x000ef089 -[UIViewController view] + 179 
8 UIKit        0x000ed482 -[UIViewController contentScrollView] + 42 
9 UIKit        0x000fdf25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48 
10 UIKit        0x000fc555 -[UINavigationController _layoutViewController:] + 43 
11 UIKit        0x000fd870 -[UINavigationController _startTransition:fromViewController:toViewController:] + 524 
12 UIKit        0x000f832a -[UINavigationController _startDeferredTransitionIfNeeded] + 266 
13 UIKit        0x000ff562 -[UINavigationController pushViewController:transition:forceImmediate:] + 932 
14 UIKit        0x000f81c4 -[UINavigationController pushViewController:animated:] + 62 
15 SeniorProject      0x00005998 -[ExerciseList goToVideo:] + 328 
16 UIKit        0x0003f4fd -[UIApplication sendAction:to:from:forEvent:] + 119 
17 UIKit        0x000cf799 -[UIControl sendAction:to:forEvent:] + 67 
18 UIKit        0x000d1c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
19 UIKit        0x000d07d8 -[UIControl touchesEnded:withEvent:] + 458 
20 UIKit        0x00063ded -[UIWindow _sendTouchesForEvent:] + 567 
21 UIKit        0x00044c37 -[UIApplication sendEvent:] + 447 
22 UIKit        0x00049f2e _UIApplicationHandleEvent + 7576 
23 GraphicsServices     0x011ea992 PurpleEventCallback + 1550 
24 CoreFoundation      0x00f92944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
25 CoreFoundation      0x00ef2cf7 __CFRunLoopDoSource1 + 215 
26 CoreFoundation      0x00eeff83 __CFRunLoopRun + 979 
27 CoreFoundation      0x00eef840 CFRunLoopRunSpecific + 208 
28 CoreFoundation      0x00eef761 CFRunLoopRunInMode + 97 
29 GraphicsServices     0x011e91c4 GSEventRunModal + 217 
30 GraphicsServices     0x011e9289 GSEventRun + 115 
31 UIKit        0x0004dc93 UIApplicationMain + 1160 
32 SeniorProject      0x00001b39 main + 121 
33 SeniorProject      0x00001ab5 start + 53 
) 
terminate called after throwing an instance of 'NSException' 
+0

如果你得到一個SIGABRT,那麼你在日誌裏有東西。發佈。 – CodaFi 2012-03-27 00:15:23

+0

@CodaFi:我現在把它放在編輯中 – 2012-03-27 01:04:34

回答

0

你看到這行錯誤:

'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter' 

意思就是第二個只工作,因爲伊娃「網址」不爲NULL不像sharedManager.vidName;,這點我可以保證的是零,如果你的NSLog它。

+0

我很困惑,第二個什麼才起作用? – 2012-03-27 03:08:19

+0

您發佈了兩個版本的viewDidLoad,你沒有嗎? – CodaFi 2012-03-27 03:19:10

+0

哎呦。腦屁。當我NSLog sharedManager.vidName,它不是零。正確的字符串保存在sharedManager.vidName中。這是你的意思嗎? – 2012-03-27 04:34:13

1

退房控制檯日誌,看看它說是這樣的:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter' 

如果是這樣,那麼sharedManager.vidName是與@「vid_name」完全不同,並且路徑無法成功找到。也許@「vid_name.mp4」?那麼你可能只需要更換

NSString *url = [[NSBundle mainBundle] pathForResource:tempName ofType:@"mp4"]; 

NSString *url = [[NSBundle mainBundle] pathForResource:tempName ofType:nil]; 

試試看吧。

+0

控制檯日誌確實會這麼說。我嘗試用類型爲nil的新代碼行替換該行,但它仍然不起作用:( – 2012-03-27 02:53:15

+0

好的。請向我們展示NSLog的輸出(@「'%@'」,tempName);應該可能是一些平庸的原因,或許是文件名中沒有必要的空間,或者類似的東西 – lukasz 2012-03-27 03:52:43

+0

我剛剛在log上面加上了NSLog的輸出 – 2012-03-27 05:07:12

0

這是我見過的最晦澀的事情之一...... iOS中的豐富內容之一。我和一個名爲GetLocationVideo.m4v的文件有同樣的問題。我有一些其他文件工作正常。其中之一是MVI_1723.MOV。經過幾個小時的工作,應該需要超過1秒鐘。我從xcode資源中的參考列表中刪除了GetLocationVideo.m4v。我將GetLocationVideo.m4v文件重命名爲MVI_1724.MOV,並將其放回到Xcode的資源文件夾中。重新運行應用程序,它運行良好。看來,xcode需要在大寫視頻文件的擴展名。 .MOV將工作。我還沒有嘗試.MP4或任何擴展名。爲什麼?我不知道。有太多的錯誤或東西沒有任何意義,你必須閱讀10,000頁的文檔,甚至不值得試圖理解爲什麼。只要繼續下去,直到下一件大事出現在你面前。我希望這能夠幫助其他人在同樣的道路上掙扎。

相關問題