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 {
MPMoviePlayerViewController* 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!!