MPMoviePlayer crashing app on device but not in simulator, but only when trying to play some files
I am writing an app that displays videos using MPMoviePlayer which are stored locally on the device. When I try to play most of the videos, the app crashes on the device, but not on the simulator where they play fine. I am using the same code to play all of the videos, I have tried deleting and reinstalling the app, cleaning then building again, with no luck.
The simulator is version 4.3 and the iPad I am testing the app on is version 4.3.1. I am using Xcode 4
This is the code I am using to play one of the videos that crashes:
@implementation SinglePendulumControl
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"SinglePendulumControl" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
[[self view] setBounds:CGRectMake(0, 0, 1024, 768)];
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
This is the code I am using to play one of the videos that doesn't crash:
@implementation GlueSettings
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"gluesettings" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
[[self view] setBounds:CGRectMake(0, 0, 1024, 768)];
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
The console log of the crash:
May 16 17:55:31 unknown Vector[3590] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** Call stack at first throw:
(
0 CoreFoundation 0x33c3d64f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x33f01c5d objc_exception_throw + 24
2 CoreFoundation 0x33c3d491 +[NSException raise:format:arguments:] + 68
3 CoreFoundation 0x33c3d4cb +[NSException raise:format:] + 34
4 Foundation 0x36da018f -[NSURL(NSURL) initFileURLWithPath:] + 70
5 Foundation 0x36da012f +[NSURL(NSURL) fileURLWithPath:] + 30
6 Vector 0x000eb7e5 -[BumpBarBumpSwitch playMovie:] + 80
7 CoreFoundation 0x33bad571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
8 UIKit 0x31f43ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
9 UIKit 0x31f43e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
10 UIKit 0x31f43e3b -[UIControl sendAction:to:forEvent:] + 38
11 UIKit 0x31f43b8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
12 UIKit 0x31f44423 -[UIControl touchesEnded:withEvent:] + 342
13 UIKit 0x31f42bf5 -[UIWindow _sendTouchesForEvent:] + 368
14 UIKit 0x31f4256f -[UIWindow sendEvent:] + 262
15 UIKit 0x31f2b313 -[UIApplication sendEvent:] + 298
16 UIKit 0x31f2ac53 _UIApplicationHandleEvent + 5090
17 GraphicsServices 0x3257ee77 PurpleEventCallback + 666
18 CoreFoundation 0x33c14a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
19 CoreFoundation 0x33c1683f __CFRunLoopDoSource1 + 166
20 CoreFoundation 0x33c1760d __CFRunLoopRun + 520
21 开发者_如何学Go CoreFoundation 0x33ba7ec3 CFRunLoopRunSpecific + 230
22 CoreFoundation 0x33ba7dcb CFRunLoopRunInMode + 58
23 GraphicsServices 0x3257e41f GSEventRunModal + 114
24 GraphicsServices 0x3257e4cb GSEventRun + 62
25 UIKit 0x31f55d69 -[UIApplication _run] + 404
26 UIKit 0x31f53807 UIApplicationMain + 670
27 Vector 0x000e9f31 main + 48
28 Vector 0x000e9efc start + 40
)
May 16 17:55:31 unknown UIKitApplication:Vector-Systems.Vector[0xc457][3590] <Notice>: terminate called after throwing an instance of 'NSException'
May 16 17:55:31 unknown ReportCrash[3591] <Notice>: Formulating crash report for process Vector[3590]
May 16 17:55:31 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:Vector-Systems.Vector[0xc457]) Job appears to have crashed: Abort trap: 6
May 16 17:55:31 unknown SpringBoard[29] <Warning>: Application 'Vector' exited abnormally with signal 6: Abort trap: 6
May 16 17:55:31 unknown ReportCrash[3591] <Error>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/Vector_2011-05-16-175531_Duncans-iPad.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0
May 16 17:55:34 unknown DTPower[3080] <Warning>: Task info failed for task Vector-Systems.Vector
精彩评论