播放前将视频置于暂停状态

发布于 2024-11-28 06:48:11 字数 153 浏览 5 评论 0原文

我正在使用 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???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云醉月微眠 2024-12-05 06:48:11

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

为了确保黑色闪烁消失,您可以检查 MPMoviePlayerloadState 是否为 3(这意味着 MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK )且 playbackState 为 1(这意味着 MPMoviePlaybackStatePlaying

首先隐藏您的MPMoviePlayer

yourMPMoviePlayer.view.hidden = YES;

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

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

并在收到通知且满足条件时使您的 MPMoviePlayer 再次可见:

- (void)loadStateChanged:(NSNotification *)sentNotification
{
    if (player.loadState == (MPMovieLoadStatePlaythroughOK | MPMovieLoadStatePlayable) && player.playbackState == MPMoviePlaybackStatePlaying)
        yourMPMoviePlayer.view.hidden = NO;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文