2010-06-26 57 views
0

我一直在試圖解決這個問題 - 我正在用MoviePlayerViewController播放一些視頻,但當我試圖通過加速度計來播放隨機視頻時,我得到了一個崩潰試圖切換到新電影。MoviePlayerViewController轉換導致崩潰

下面是播放影片的代碼:

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

      if (theMovie){ 
     [self presentMoviePlayerViewControllerAnimated:theMovie]; 
      theMovie.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 
     [theMovie.moviePlayer play]; 
     [theMovie release]; 
    } 
} 

這裏是加速度計代碼:

- (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; 
} 

,當它在這個位置切換視頻發生崩潰:

[self presentMoviePlayerViewControllerAnimated:theMovie]; 

當我改變視頻時調試器錯誤是:

由於未捕獲的異常'NSInternalInconsistencyException'而終止應用程序,原因:'嘗試在轉換已經進行時從UINavigationController到MPMoviePlayerViewController開始模態轉換。等待viewDidAppear/viewDidDisappear知道當前轉換已完成'

任何建議和想法,非常感謝。謝謝!!

+0

您是否找到了解決此問題的方法(除了稍後調用某種方法的某些方法之外)? – stk 2012-12-20 15:46:44

回答

0

我在設備上首次安裝我的應用程序時看到類似的問題。當我嘗試播放視頻時,該應用崩潰。我也使用 [self presentMoviePlayerViewControllerAnimated:theMovieView];呼叫。 這是來自調試器的堆棧轉儲。

#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