2014-11-04 117 views
0

我有一個問題,在UIScrollView中,我有一些視圖(視頻控制器在下面)充當視頻內容的頁面(最初顯示縮略圖視圖)。MPMoviePlayerController有時播放音頻,而不是在淡入淡出時的視頻

有時(但並非總是)當我滾動到下一頁時,視頻的音頻開始播放,但沒有視覺效果。這似乎並不當我不褪色的視圖中的發生

視頻初始化代碼爲:

MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] init]; 

    self.moviePlayer = moviePlayer; 

    [moviePlayer setControlStyle:MPMovieControlStyleNone]; 
    [moviePlayer setRepeatMode:MPMovieRepeatModeOne]; 
    [moviePlayer.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 

    moviePlayer.backgroundView.backgroundColor = [UIColor clearColor]; 
    moviePlayer.movieSourceType = MPMovieSourceTypeStreaming; 
    moviePlayer.contentURL = [NSURL URLWithString:[videoData.video src]]; 

    [self.videoController.view addSubview:self.moviePlayer.view]; 
    [self.videoController.view bringSubviewToFront:moviePlayer.view]; 
    [moviePlayer.view setAlpha:0.0f]; 

    // Movie Observer 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkMovieStatus:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; 

    // Add tap handler 
    UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onPlayerTapped:)]; 
    singleFingerTap.numberOfTapsRequired = 1; 
    singleFingerTap.delegate = self; 
    [self.moviePlayer.view addGestureRecognizer:singleFingerTap]; 

    [moviePlayer prepareToPlay]; 

和播放代碼(儘量避免黑色閃光在視頻的開始)是:

- (void)checkMovieStatus:(NSNotification *)notification { 
    if(self.moviePlayer.readyForDisplay && (MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK)) { 

      [self.moviePlayer play]; 

      [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; 

      [UIView animateWithDuration:0.4f animations:^{ 
       [self.moviePlayer.view setAlpha:1.0f]; 
      } completion:^(BOOL finished) { 
       //[self.moviePlayer play]; // tried here as well 
      }]; 
     } 
} 

代碼,以消除滾動視頻的看法是:

- (void)removeMoviePlayer { 
     if(self.moviePlayer) { 
       [self.moviePlayer stop]; 

       [self.moviePlayer.view removeFromSuperview]; 

       self.moviePlayer = nil; 
     } 
} 

回答

0

我發現了一個很奇怪的修復這個PROBL EM。在我的情況下,我會滑動到視頻和音頻播放,並沒有圖片。如果我刷卡並回來,一切正常,所以只是爲了它的樂趣我試過這個

MPMoviePlayerController *mp = [self.arrayOfScrollView objectAtIndex:xx]; 
[mp play]; 
[mp stop]; 
[mp play]; 

奇怪的是,工作。既然你在六個月前發佈了這篇文章,如果你發現了另一種解決方法,我很想知道它。