I've been rattling my brain trying to figure this out -- I am playing some videos with MoviePlayerViewController, but when I try to shake to play a random video via the accelerometer, I get a crash when it tries to switch to the new movie.
Here is the code that plays the movie:
-(void)playMovieAtURL:(NSURL*)theURL {
MPMoviePlaye开发者_JS百科rViewController* theMovie=[[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
if (theMovie){
[self presentMoviePlayerViewControllerAnimated:theMovie];
theMovie.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[theMovie.moviePlayer play];
[theMovie release];
}
}
And here is the accelerometer code:
- (void) accelerometer: (UIAccelerometer *)accelerometer didAccelerate: (UIAcceleration *)acceleration {
if (self.lastAcceleration) {
if (!shakeDetected && IsDeviceShaking(self.lastAcceleration, acceleration, 0.7)) {
shakeDetected = YES;
NSLog(@"Shake detected");
int filescount = [entries count];
int randomIndex;
for( int index = 0; index < filescount; index++ )
{
randomIndex= arc4random() % filescount;
[entries exchangeObjectAtIndex:index withObjectAtIndex:randomIndex];
}
AppRecord *app = [entries objectAtIndex:randomIndex];
contentController.detailItem = app;
[self playMovieAtURL:[NSURL URLWithString:app.applink]];
}
else if (shakeDetected && !IsDeviceShaking(self.lastAcceleration, acceleration, 0.2)) {
shakeDetected = NO;
}
}
self.lastAcceleration = acceleration;
}
The crash occurs when it switches videos at this spot:
[self presentMoviePlayerViewControllerAnimated:theMovie];
The debugger error when I shake to change videos is :
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from UINavigationController to MPMoviePlayerViewController while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'
Any suggestions and ideas are greatly appreciated. Thank you!!
I am seeing a similar problem when a install my app for the first time on the device. When I try to play a video the app crashes. I am also using the [self presentMoviePlayerViewControllerAnimated:theMovieView]; call. Here is the stack dump from the debugger.
#0 0x3037fd7c in ___forwarding___
#1 0x30312680 in __forwarding_prep_0___
#2 0x35203dee in -[MPMoviePlayerViewController viewDidAppear:]
#3 0x324128bc in -[UIWindowController transitionViewDidComplete:fromView:toView:]
#4 0x323959da in -[UITransitionView notifyDidCompleteTransition:]
#5 0x3239588e in -[UITransitionView _didCompleteTransition:]
#6 0x32412556 in -[UITransitionView _transitionDidStop:finished:]
#7 0x3237a97a in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
#8 0x3237a884 in -[UIViewAnimationState animationDidStop:finished:]
#9 0x343557c0 in run_animation_callbacks
#10 0x34355662 in CA::timer_callback
#11 0x30352a5a in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#12 0x30354ee4 in __CFRunLoopDoTimer
#13 0x30355864 in __CFRunLoopRun
#14 0x302fe8ea in CFRunLoopRunSpecific
#15 0x302fe7f2 in CFRunLoopRunInMode
#16 0x31a776ee in GSEventRunModal
#17 0x31a7779a in GSEventRun
#18 0x323272a6 in -[UIApplication _run]
#19 0x32325e16 in UIApplicationMain
#20 0x000022ca in main at main.m:14
精彩评论