在播放之前将视频置于暂停状态 [英] Putting a video to pause state before playing

查看:212
本文介绍了在播放之前将视频置于暂停状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVMoviePlayer在应用中播放视频。现在,点击播放按钮后会出现黑屏,视频开始播放。但是,从用户端的角度来看,黑屏是一些代价。所以,我想从暂停状态开始播放视频。
为了做到这一点,我想在播放之前将播放器置于暂停状态..

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

推荐答案

您可以隐藏 MPMoviePlayer ,直到恼人的黑色闪烁消失。

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

为确保黑色闪烁消失,您可以检查 MPMoviePlayer 的loadState是否为3(其中表示 MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK )和playbackState为1(表示 MPMoviePlaybackStatePlaying

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)

首先隐藏你的 MPMoviePlayer

yourMPMoviePlayer.view.hidden = YES;

只需添加一个观察者,以便在loadState更改时收到通知:

Just add an observer to be notified when loadState changes:

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

并在收到通知并满足条件后再次显示您的MPMoviePlayer:

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

这篇关于在播放之前将视频置于暂停状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆