MPMoviePlayer 在设备上导致应用程序崩溃,但在模拟器中则不然,但仅在尝试播放某些文件时发生
我正在编写一个使用 MPMoviePlayer 显示视频的应用程序,这些视频存储在设备本地。当我尝试播放大部分视频时,应用程序会在设备上崩溃,但在模拟器上却不会崩溃,它们可以正常播放。我使用相同的代码来播放所有视频,我尝试删除并重新安装应用程序,清理然后再次构建,但没有成功。
模拟器的版本是 4.3,我测试应用程序的 iPad 是版本 4.3.1。我正在使用 Xcode 4
这是我用来播放崩溃的视频之一的代码:
@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];
}
这是我用来播放不崩溃的视频之一的代码:
@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];
}
崩溃的控制台日志:
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 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
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论