2010-06-26 58 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