Putting a video to pause state before playing

风格不统一 提交于 2019-11-27 19:05:45

问题


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 casing some discofort from the user end point of view. So, i want to start the video from a paused state. In order to do this, i thought of putting the player to paused state before playing it..

Is there a way to do this???


回答1:


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 == 3 &&  player.playbackState == 1 )
       yourMPMoviePlayer.view.hidden = NO;
}


来源:https://stackoverflow.com/questions/6941734/putting-a-video-to-pause-state-before-playing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!