Putting a video to pause state before playing

前端 未结 1 847
醉梦人生
醉梦人生 2020-12-17 07:18

I am using MVMoviePlayer to play videos in the app. Right now, a black screen comes after taping the play button and the video starts playing. But, the black screen is casin

相关标签:
1条回答
  • 2020-12-17 07:39

    You can hide your MPMoviePlayer until that annoying black flicker is gone.

    To ensure that the black flicker is gone, you can check if the MPMoviePlayer's loadState is 3 ( which means MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK ) and playbackState is 1 (which means MPMoviePlaybackStatePlaying)

    First hide your MPMoviePlayer:

    yourMPMoviePlayer.view.hidden = YES;
    

    Just add an observer to be notified when loadState changes:

    [NSNotificationCenter.defaultCenter addObserver:self
                                           selector:@selector(loadStateChanged:) 
                                               name:MPMoviePlayerLoadStateDidChangeNotification
                                             object:nil];
    

    And make your MPMoviePlayer visible again when you are notified and conditions are met:

    - (void)loadStateChanged:(NSNotification *)sentNotification
    {
        if (player.loadState == (MPMovieLoadStatePlaythroughOK | MPMovieLoadStatePlayable) && player.playbackState == MPMoviePlaybackStatePlaying)
            yourMPMoviePlayer.view.hidden = NO;
    }
    
    0 讨论(0)
提交回复
热议问题