MPMoviePlayerController看似随机崩溃

时间:2012-11-06 08:57:47

标签: ios ios5 ios6 mpmovieplayercontroller mpmovieplayer

随机时间,我的应用程序崩溃了这个崩溃日志。

一个神奇的解决方案是理想的,但是一些帮助从哪里开始调试也会有所帮助。该应用程序很难调试,因为它是一个基于GPS的应用程序,所以如果我知道要寻找什么,我可以建立一些压力测试。

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread:  0

Last Exception Backtrace:
0   CoreFoundation      0x3789c88f __exceptionPreprocess + 163
1   libobjc.A.dylib     0x31911259 objc_exception_throw + 33
2   AVFoundation        0x309301d9 -[AVPlayer _attachItem:andPerformOperation:withObject:] + 249
3   AVFoundation        0x309300db -[AVPlayer _insertItem:afterItem:] + 27
4   AVFoundation        0x30943b9d -[AVQueuePlayer insertItem:afterItem:] + 137
5   MediaPlayer         0x364a68b7 __block_global_2 + 199
6   libdispatch.dylib   0x34a4bc59 _dispatch_call_block_and_release + 13
7   libdispatch.dylib   0x34a4dee7 _dispatch_main_queue_callback_4CF$VARIANT$mp + 195
8   CoreFoundation      0x3786f2ad __CFRunLoopRun + 1269
9   CoreFoundation      0x377f24a5 CFRunLoopRunSpecific + 301
10  CoreFoundation      0x377f236d CFRunLoopRunInMode + 105
11  GraphicsServices    0x379eb439 GSEventRunModal + 137
12  UIKit               0x309fecd5 UIApplicationMain + 1081
13  App                 0x000b5b6f main (main.m:14)

我正在播放各种电影(mov(H.264,1024 x 576,AAC,44100 Hz,Stereo(L R))和声音(MP3和WAV),有时混合。

使用MPMoviePlayer播放电影,声音使用AVAudioPlayer。

发生在ios 5和6上。(iPad)

---编辑:添加代码----

视频在这里准备:

- (void) prepareLayer:(NSDictionary*) aUserInfo{
    mMoviePlayerController.contentURL = [aUserInfo objectForKey:@"contenturl"];                     // set content
    [mMoviePlayerController prepareToPlay];
    mMoviePlayerController.shouldAutoplay = NO;                                                     // prevent autoplay
    mMovieShouldLoop = NO;
    [mWrapper setOpacity: 0];                                                                       // hide video view (we don't want to see the previous video file)                                                                           
}

mWrapper用于将视频封装在cocos2d节点中

- (void) showLayer {
    [mWrapper setVisible: YES];
    [mMoviePlayerController pause];
    mRetryCounter = 0;
    mMovieStarted = NO;
    self.visible = YES;
}

- (void) updateLayer {
    if (!self.visible)      {   return; }                                                                                       // not visible, so not updating (prevents accidental playing of video)

    if (mWarningHidden && !mMovieStarted)                                                                                       // if warning is hidden and the movieStarted flag is false
    {
        if (mMoviePlayerController.playbackState == MPMoviePlaybackStatePlaying) {                                              // if movie did start successfully.
            mMovieStarted = YES;                                                                                                // set flag
            [mWrapper setOpacity: 255];                                                                                         // show video view
        }
        else {                                                                                                                  // if movie is not playing yet          
            if (mRetryCounter == 0) {                                                                                           // if this is the first try
                [[[CCDirector sharedDirector] openGLView] addGestureRecognizer:mSwipe];                                         // enable swipe gesture
            }
            [mMoviePlayerController play];                                                                                      // start playing
            if (mMovieShouldLoop) {                                                                                             // and set loop or not
                if (mMoviePlayerController.repeatMode != MPMovieRepeatModeOne) {
                    mMoviePlayerController.repeatMode = MPMovieRepeatModeOne;
                }
            } else {
                if (mMoviePlayerController.repeatMode != MPMovieRepeatModeNone) {
                    mMoviePlayerController.repeatMode = MPMovieRepeatModeNone;
                }
            }


            if (mMoviePlayerController.playbackState != MPMoviePlaybackStatePlaying && mRetryCounter > 5) {                     // if movie not playing and retried for 5 times,
                mMoviePlayerController.contentURL = [[NSBundle mainBundle] URLForResource:@"novideo" withExtension:@"m4v"];     // switch to movie of static, indicating something went wrong
                [mMoviePlayerController play];                                                                                  // and play that.
            }

            if (mRetryCounter > 10) {
                mMovieStarted = YES;                                                                                            // if movie still doesn't run after switched to static and retrying that for 5 times, skip it.
                NSLog(@"A Movie was skipped after trying to play it for 10 times.");
            }           
            mRetryCounter++;                                                                                                    // count retries.           
        }
    }
}

- 编辑:删除了代码段的声音部分,因为它们不是问题的一部分,并更改了标题以反映问题在MPMoviePlayerController中,而不是在AVPlayer中。

1 个答案:

答案 0 :(得分:1)

我通过使用较低级别的AVPlayer而不是MPMoviePlayer解决了这个问题。这完全解决了我的问题。

相关问题