Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

ios - Putting a video to pause state before playing

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???

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...