So the problem I am having is that when I try to load a video this way:
-(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];
}
I am getting a SIGARBT thrown where I specified in code due to a NSException. However, If I simply write out the string, as follows:
- (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];
}
the code works perfectly fine. What could the problem be? I NSLog tempName to make sure that it is holding the correct string and it is. Also, sharedManager.vidName is a NSMutableString. This is the only problem left holding me back from finishing my Senior project and graduating college, so ANY help would be greatly appreciated. Thank you.
Here is what I'm getting in the log:
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'
Check out console log and see if it says something like this:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
If so, then sharedManager.vidName is definitely different from @"vid_name", and the path cannot be successfully found. Maybe @"vid_name.mp4"? Then you probably just have to replace
NSString *url = [[NSBundle mainBundle] pathForResource:tempName ofType:@"mp4"];
with
NSString *url = [[NSBundle mainBundle] pathForResource:tempName ofType:nil];
Give it a try.
Did you see this line in the error:
'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
Meaning that the second one only works because the iVar 'url' is not NULL unlike sharedManager.vidName;
, which I can guarantee is nil if you NSLog it.
This one of the most obscure things I have even seen ... one of the plenty in iOS. I had the same problem with a file named GetLocationVideo.m4v. I had some other files that worked fine. One of the was MVI_1723.MOV. After several hours working on something that SHOULD take more than 1 second. I deleted the GetLocationVideo.m4v from the reference list in resources in xcode. I renamed the GetLocationVideo.m4v file to MVI_1724.MOV, put it back to the resources folder of Xcode. rerun the app and it worked fine. It appears that xcode needs to have the video file extension in capital. .MOV will work. I have not tried .MP4 or any extension. Why? I have no idea. There are so many bugs or things that do not make any sense and you have to read 10,000 page documentation that is not even worth trying to understand why. Just keep going along till the next big thing comes in front of you. I hope this will help others struggling along the same lines.
User contributions licensed under CC BY-SA 3.0