【问题标题】:iOS 8 video progress bar not visibleiOS 8 视频进度条不可见
【发布时间】:2015-01-13 15:08:53
【问题描述】:

我有一个 iOS 应用程序,我试图在其中使用 MPMoviePlayerController 显示视频。 代码非常简单,在所有 iOS 版本大于 6.0 的设备上都可以正常工作。

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

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

请提出建议。 提前致谢。

【问题讨论】:

    标签: objective-c ios8 mpmovieplayercontroller


    【解决方案1】:

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

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

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

    首先,肮脏的部分,也许对于遇到这个问题的每个人来说都不是必需的,我解析了一些播放器子视图来处理 MPVideoPlaybackOverlayView 视图,以强制其可见或不可见。

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

    但这还不够。可能是因为纵向模式有多个触发通知的方向(UIDeviceOrientationPortraitUIDeviceOrientationFaceUp、...),因此控制样式更改请求。

    所以我修复的第二步是处理这样一个事实,即如果我们已经处于正确的屏幕方向,则无需更改MPMoviePlayerControllercontrolStyle。 就我而言,解决方案是验证状态栏是否隐藏,因为我将其隐藏在横向中:

    // 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 已经设置为想要的值,我们不应该设置它。

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

    【讨论】:

    • @Johann....感谢您的回复....但在我的情况下,我发现重新绘制视图有问题...所以我只是在播放视频之前加载一个空白视图控制器0.5 秒后将其移除....一切正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多