MPMoviePlayerController 在全屏模式下向前搜索,直到末尾卡住

发布于 2024-11-28 05:25:57 字数 167 浏览 11 评论 0原文

MPMoviePlayerController 似乎有一个问题,一旦您处于全屏模式并按住快进按钮,让它向前搜索(快速播放)一直到视频结尾。

此后,您只会看到黑屏并且卡住了。换句话说,它不会响应任何点击手势,您无法摆脱这种情况。还有其他人遇到过这个问题吗?

有没有办法在代码中解决这个问题?

There seems to be a problem with the MPMoviePlayerController where once you're in fullscreen mode and you hold down the fast forward button, letting it seek forward (playing at fast speed) all the way to the end of the video.

Thereafter the you just get a black screen and it's stuck. In other words it does not respond to any taps gestures and you can not get out of this situation. Has anyone else encountered this problem?

Is there anyway to work around it in code?

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

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

发布评论

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

评论(4

梦途 2024-12-05 05:25:57

这似乎是一个 iOS 错误,因为快退到开头不会导致黑屏,但快进到结尾会导致黑屏,之后对视频播放器的“播放”/“暂停”调用永远不会起作用。我通过将受保护的逻辑添加到清理器刷新回调中来临时修复此问题:
假设将在“PLAY_BACK_TIME_MONITOR_INTERVAL”秒期间调用monitorPlaybackTime来刷新擦洗器,并在其中添加一个检查逻辑:

NSTimeInterval duration = self.moviePlayer.duration;
NSTimeInterval current = self.moviePlayer.currentPlaybackTime;

if (isnan(current) || current > duration) {
    current = duration;
} else if (self.moviePlayer.playbackState == MPMoviePlaybackStateSeekingForward) {
    if (current + self.moviePlayer.currentPlaybackRate*PLAY_BACK_TIME_MONITOR_INTERVAL > duration) {
        [self.moviePlayer endSeeking];
    }
}

解决黑屏的解决方法,并不完美,希望它能有所帮助。

It seems it's an iOS bug since fast backward to the very beginning won't cause the black screen but fast forward to the end will, and after that the 'play'/'pause' call to the video player never works. I temporarily fix this by adding protected logic into the scrubber refresh callback:
let's assume that monitorPlaybackTime will be called in 'PLAY_BACK_TIME_MONITOR_INTERVAL' seconds period to refresh the scrubber, and in it I add a check logic:

NSTimeInterval duration = self.moviePlayer.duration;
NSTimeInterval current = self.moviePlayer.currentPlaybackTime;

if (isnan(current) || current > duration) {
    current = duration;
} else if (self.moviePlayer.playbackState == MPMoviePlaybackStateSeekingForward) {
    if (current + self.moviePlayer.currentPlaybackRate*PLAY_BACK_TIME_MONITOR_INTERVAL > duration) {
        [self.moviePlayer endSeeking];
    }
}

A workaround to solve the black screen, not perfect, hope it can help.

伤感在游骋 2024-12-05 05:25:57

我猜你没有处理 MPMoviePlayerPlaybackDidFinishNotification。如果你不是的话,你真的应该这样做。

对于我来说,电影播放器​​会进入你所描述的“卡住”状态仍然是出乎我意料的。我更愿意期望它自动停止播放并在播放结束时重置。无论如何,我认为如果您观察 MPMoviePlayerPlaybackDidFinishNotification 并正确处理影片控制器,您的问题就会消失。

I'm guessing you are not handling the MPMoviePlayerPlaybackDidFinishNotification. You really should if you're not.

Still its unexpected for me that the movie player would go into a "stuck" state like you describe. I would more readily expect it to stop playback automatically and reset when it reaches the end. Anyway, I think your problem will go away if you observe the MPMoviePlayerPlaybackDidFinishNotification and handle the movie controller appropriately.

少女七分熟 2024-12-05 05:25:57

在 iOS6 上遇到了同样的问题。设法通过使用以下实现注册 MPMoviePlayerPlaybackDidFinishNotification (如 Leuguimerius 建议)来修复它:

- (void)playbackDidFisnish:(NSNotification *)notif {
    if (self.player.currentPlaybackTime <= 0.1) {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.player stop];
        [self.player play];
        [self.player pause];
        });
    }
}

其中 self.player 是关联的 MPMoviePlayerController 实例。对 currentPlaybackTime 的检查用于区分更标准的playbackDidFinish 调用(允许电影以正常速度播放直到结束)和用户快进直到结束的场景。即使快进到最后,停止然后播放和暂停也会产生可用的、视觉上一致的界面。

Ran into the same issue on iOS6. Managed to fix it by registering for the MPMoviePlayerPlaybackDidFinishNotification (as suggested by Leuguimerius) with the following implementation:

- (void)playbackDidFisnish:(NSNotification *)notif {
    if (self.player.currentPlaybackTime <= 0.1) {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.player stop];
        [self.player play];
        [self.player pause];
        });
    }
}

Where self.player is the associated MPMoviePlayerController instance. The check against currentPlaybackTime serves to distinguish the more standard invocations of playbackDidFinish (where the movie is allowed to play at normal speed until its end) from those scenarios where the user fast forwards until the end. Stopping then playing and pausing results in a usable, visually consistent interface even when fast-forwarding to the end.

软糖 2024-12-05 05:25:57

上述解决方案都不适合我,所以这就是我最终所做的:

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("moviePlayerLoadStateDidChange"), name: MPMoviePlayerLoadStateDidChangeNotification, object: nil)

func moviePlayerLoadStateDidChange() {
    let loadState = moviePlayerController?.loadState

    if loadState == MPMovieLoadState.Unknown {
        moviePlayerController?.contentURL = currentmovieURL
        moviePlayerController?.prepareToPlay()
    }
}

我认为问题是,当单击前进按钮时,它想要跳到下一个视频,这就是为什么会出现加载指示器。监听加载状态更改事件,您可以指定下一个视频应该是什么,如果没有,您可以给它相同的 url。

None of the aforementioned solutions worked for me, so this is what I ended up doing:

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("moviePlayerLoadStateDidChange"), name: MPMoviePlayerLoadStateDidChangeNotification, object: nil)

func moviePlayerLoadStateDidChange() {
    let loadState = moviePlayerController?.loadState

    if loadState == MPMovieLoadState.Unknown {
        moviePlayerController?.contentURL = currentmovieURL
        moviePlayerController?.prepareToPlay()
    }
}

I think the issue is that when the seek foraward button is single pressed, it wants to skip to the next video, that's why a loading indicator appears. Listening for the load state change event, you can specify what the next video should be, and if you don't have any, you can just give it the same url.

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