ios - 电影播放器​​控件可见/隐藏时的通知?

标签 ios uikit mpmovieplayercontroller nsnotifications

我只是想知道是否可以在播放控件可见或隐藏时收到通知?

例如,我想呈现一个具有以下样式的视频:

self.moviePlayerController.controlStyle = MPMovieControlStyleEmbedded;

当视频开始播放时,播放控件会变得可见并自动消失。如果用户只是点击视频,就会出现控件。

我需要一个通知,以便我可以调整我的 View (在 MPMoviePlayerController View 下重新放置一些额外的按钮。 那可能吗?因为不幸的是我在文档中没有找到任何东西。

最佳答案

恐怕这些事件没有记录在案的通知。

你可能很幸运,通过嗅探所有已发布的通知找到了一些东西,如下面的答案:

Trapping and tracing all notifications

How to receive NSNotifications from UIWebView embedded YouTube video playback


然而,有一种方法可以将您的控件与 MPMoviePlayerControler 的控件简单地链接起来。这种方式绝对没有记录,并且在尝试在 iTunes 上销售您的应用程序时确实存在被拒绝的强烈风险。

首先,您需要在 MPMoviePlayerController 中找到界面 View ,直到今天,当使用嵌入式界面时,它由一个名为 MPInlineVideoOverlay 的类表示。再次请注意,他的这个有很大的机会或打破,因为苹果可能会决定在任何一天使用不同的命名。

/**
 * This quirky hack tried to locate the interface view within the supposingly opaque MPMoviePlayerController
 * view hierachy.
 * @note This has a fat chance of breaking and/or getting rejected by Apple
 *
 * @return interface view reference or nil if none was found
 */
- (UIView *)interfaceViewWithPlayer:(MPMoviePlayerController *)player
{
    for (UIView *views in [player.view subviews])
    {
        for (UIView *subViews in [views subviews])
        {
            for (UIView *controlView in [subViews subviews])
            {
                if ([controlView isKindOfClass:NSClassFromString(@"MPInlineVideoOverlay")])
                {
                    return controlView;
                }
            }
        }
    }
    return nil;
}

如果返回正确的 View ,您只需使用 UIView addSubview: 将您自己的添加添加到它的界面上 完成此操作后,您的控件将成为播放器界面的一部分,与其一起显示和隐藏(也遵循所有动画等)。

关于ios - 电影播放器​​控件可见/隐藏时的通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11560753/

相关文章:

ios - 如何优化4英寸兼容3.5英寸的屏幕尺寸

ios - 文本字段中的 addSubview 显示 CGContextSetFillColorWithColor : invalid context 0x0

ios - (iOS) 我如何对 UI 元素的翻译进行动画处理,例如两个 View Controller 之间转换中的标签和图像?

iOS : How to Full screen video when change device orientation to Landscape in MPMoviePlayerController?

ios - 在 XCTestCase 中对同一测试运行迭代测试

ios - 向服务器发出请求时 iOS7 的加载指示器

ios - 为什么当我更改边界时 View 没有变化?

ios - 如何在 swift 4 中更改 NavBar 标题文本颜色?

ios - 隐藏视频控件 MPMoviePlayerController

iphone - iPhone 上的 MPMoviePlayerController 替代品?