iOS 8视频进度条不可见 [英] iOS 8 video progress bar not visible

查看:374
本文介绍了iOS 8视频进度条不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用,我试图使用 MPMoviePlayerController 来显示视频。
代码非常简单,并且在所有iOS版本大于6.0的设备上运行良好。

I have an iOS app in which I am trying to show videos using MPMoviePlayerController. The code is very simple and working fine on all the devices with all iOS version greater than 6.0.

但问题出在iOS 8和8.1上,视频的进度条不可见,如下图所示。

But the problem is on iOS 8 and 8.1, the progress bar of the video is not visible as shown in below image.

我不明白为什么会发生这种情况或者是iOS 8的错误。

I dont understand why this is happening or is this iOS 8 bug.

请建议。
提前致谢。

Please suggest. Thanks in advance.

推荐答案

我的应用程序中也有这个问题,它支持多个iOS版本但是这个问题确实只在iOS 8上可见。

I had this issue too in my app, which supports several iOS versions but this issue is indeed only visible on iOS 8.

我的代码切换 MPMoviePlayerController controlStyle MPMovieControlStyleEmbedded MPMovieControlStyleNone 之间,这是使用 UIDeviceOrientationDidChangeNotification触发的。我必须承认我以编程方式旋转我的播放器,我不旋转应用程序;这可能是这个问题的根源。我以纵向显示控件,并将它们隐藏在横向中。

My code toggles the MPMoviePlayerController's controlStyle between MPMovieControlStyleEmbedded and MPMovieControlStyleNone, and this is triggered using UIDeviceOrientationDidChangeNotification. I have to admit that I programmatically rotate my player, I do not rotate the application; this is maybe a root of this issue. I display the controls in portrait, and hide them in landscape.

我显然分两步解决了这个问题。我没有在一个简单的应用程序中分离出这个问题,所以如果解决方案对每个人都不准确,我很抱歉。

I apparently solved it in two steps. I did not isolated this issue in a simple app so my apologies if the solution is not accurate for everyone.

第一个,脏的部分, 并且对于遇到此问题的每个人来说可能都没有必要,我解析了一些玩家子视图来照看 MPVideoPlaybackOverlayView 视图,以强制其可见性或隐身。

First, the dirty part, and perhaps not necessary for everybody who encounter this issue, I parse some of the player subviews to look after the MPVideoPlaybackOverlayView view, in order to force its visibility or invisibility.

// Helps to hide or show the controls over the player
// The reason of this method is we are programmatically rotating the player view, while not rotating the application
// On latest iOS, this leads to misbehavior that we have to take into account
-(void)showMPMoviePlayerControls:(BOOL)show
{
    self.player.controlStyle = (show ? MPMovieControlStyleEmbedded : MPMovieControlStyleNone);
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8"))
    {
        // Workaround to avoid persistence of empty control bar
        for(UIView *subView in self.player.backgroundView.superview.superview.subviews)
        {
            if ([subView isKindOfClass:NSClassFromString(@"MPVideoPlaybackOverlayView")]) {
            subView.backgroundColor = [UIColor clearColor];
                subView.alpha = (show ? 1.0 : 0.0);
                subView.hidden = (show ? NO : YES);
            }
        }
    }
}

但是这还不够。可能是因为肖像模式有几个方向( UIDeviceOrientationPortrait UIDeviceOrientationFaceUp ,...)触发通知,因此控制样式更改请求。

But this was not enough. Probably because the portrait mode has several orientations (UIDeviceOrientationPortrait, UIDeviceOrientationFaceUp, ...) that trigger the notification, hence the control style change request.

所以我的修复的第二步是为了处理没有必要更改<$ c的事实$ c> MPMoviePlayerController 的 controlStyle 如果我们已经处于正确的屏幕方向。
在我的情况下,解决方案是验证状态栏是否隐藏,因为我将其隐藏在横向中:

So the second step of my fix was to handle the fact that it is not necessary to change the MPMoviePlayerController's controlStyle if we are already in the correct screen orientation. In my case, the solution was to verify that the status bar was hidden, as I hide it in landscape:

// Set embedded controls only when there is a transition to portrait, i.e. if status bar was hidden
if ([[UIApplication sharedApplication] isStatusBarHidden]) {
    [self showMPMoviePlayerControls:YES];
    // and we show the status bar here
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}

这里的重点可能是我们不应该设置 controlStyle 如果它已经设置为想要的值。

Maybe the point here is that we should not set the controlStyle if it is already set to the wanted value.

因为这解决了我的问题,我停止了我的调查。无论如何,我认为在大多数情况下它可能更简单。肯定与 controlStyle 在错误的时间更改或已更改但已处于所需状态的事实有关。

As this solved the problem for me, I stopped my investigations. Anyway I suppose that it is probably simpler in most cases. Certainly linked to the fact that the controlStyle is changed at the wrong time, or changed but was already in the wanted state.

这篇关于iOS 8视频进度条不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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