MoviePlayerViewController transition causing crash
<p>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. </p>

<p>Here is the code that plays the movie:</p>

<pre><code>            -(void)playMovieAtURL:(NSURL*)theURL { 
         MPMoviePlayerViewController* theMovie=[[MPMoviePlayerViewController alloc] initWithContentURL:theURL]; 

          if (theMovie){
         [self presentMoviePlayerViewControllerAnimated:theMovie];
          theMovie.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
         [theMovie.moviePlayer play];
         [theMovie release]; 
    }
}
</code></pre>

<p>And here is the accelerometer code:</p>

<pre><code>- (void) accelerometer: (UIAccelerometer *)accelerometer didAccelerate: (UIAcceleration *)acceleration {
if (self.lastAcceleration) {
    if (!shakeDetected &amp;&amp; IsDeviceShaking(self.lastAcceleration, acceleration, 0.7)) {
        shakeDetected = YES; 


NSLog(@"Shake detected"); 

   int filescount = [entries count];
   int randomIndex;

   for( int index = 0; index &lt; 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 &amp;&amp; !IsDeviceShaking(self.lastAcceleration, acceleration, 0.2)) {
            shakeDetected = NO;
        }
    }
 self.lastAcceleration = acceleration;
}
</code></pre>

<p>The crash occurs when it switches videos at this spot:</p>

<pre><code>[self presentMoviePlayerViewControllerAnimated:theMovie];
</code></pre>

<p>The debugger error when I shake to change videos is :</p>

<p>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'</p>

<p>Any suggestions and ideas are greatly appreciated.  Thank you!!</p>
