为什么在iOS 10中MPMoviePlayerController全屏按钮图标更改为字幕图标? [英] Why MPMoviePlayerController fullscreen button icon change to caption icon in iOS 10?

查看:85
本文介绍了为什么在iOS 10中MPMoviePlayerController全屏按钮图标更改为字幕图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将MPMoviePlayerController用作嵌入式视频播放器,但是我发现一个问题,其中iOS 10中的全屏图标已更改?

I try to use MPMoviePlayerController as embedded video player but I spot a problem where the fullscreen icon were changed in iOS 10?

有什么解决方法可以将其更改回原始的全屏按钮?

Is there any solution to change it back to original fullscreen button ?

谢谢

这是在iOS 8和iOS 9中的外观:

This is what it look like in iOS 8 and iOS 9:

这是iOS 10中的样子:

This is what it look like in iOS 10:

推荐答案

以下是一些可以解决iOS 10错误的代码,您可以在WorkaroundInlinePlayerFullScreenButtonBug.m文件中编写该错误:

Here is some code to workaround that iOS 10 bug which you can write in a WorkaroundInlinePlayerFullScreenButtonBug.m file:

@import MediaPlayer;
@import ObjectiveC;

static void (*configureAuxiliaryButtonsIMP)(id, SEL, BOOL);

static void ConfigureAuxiliaryButtons(id self, SEL _cmd, BOOL flag)
{
    configureAuxiliaryButtonsIMP(self, _cmd, flag);
    @try
    {
        id delegate = [self delegate]; // Either nil or MPInlineVideoController (responds to `isFullscreen`) or MPInlineVideoFullscreenViewController (does not respond to `isFullscreen`)
        BOOL isFullscreen = [delegate respondsToSelector:@selector(isFullscreen)] ? [delegate isFullscreen] : YES;
        NSString *imageName = [@[ @"Video", @"Player", @"_", isFullscreen ? @"Exit" : @"Enter", @"Fullscreen" ] componentsJoinedByString:@""];
        SEL imageNamedForControlState = NSSelectorFromString([@[ @"_", @"image", @"Named", @":", @"for", @"Control", @"State", @":" ] componentsJoinedByString:@""]);
        UIImage *normalImage = ((UIImage *(*)(id, SEL, NSString *, UIControlState))objc_msgSend)(self, imageNamedForControlState, imageName, UIControlStateNormal);
        UIImage *highlightedImage = ((UIImage *(*)(id, SEL, NSString *, UIControlState))objc_msgSend)(self, imageNamedForControlState, imageName, UIControlStateHighlighted);
        UIButton *fullscreenButton = [self valueForKey:[@[ @"fullscreen", @"Button" ] componentsJoinedByString:@""]];
        [fullscreenButton setImage:normalImage forState:UIControlStateNormal];
        [fullscreenButton setImage:highlightedImage forState:UIControlStateHighlighted];
    }
    @catch (NSException *exception)
    {
        NSLog(@"Failed to workaround inline player fullscreen button bug: %@", exception);
    }
}

void WorkaroundInlinePlayerFullScreenButtonBug(void)
{
    if (![NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 0, 0}])
        return;

    Class MPVideoPlaybackOverlayView = NSClassFromString([@[ @"M", @"P", @"Video", @"Playback", @"Overlay", @"View" ] componentsJoinedByString:@""]);
    SEL configureAuxiliaryButtonsSEL = NSSelectorFromString([@[ @"_", @"configure", @"Auxiliary", @"Buttons", @":" ] componentsJoinedByString:@""]);
    NSMethodSignature *methodSignature = [MPVideoPlaybackOverlayView instanceMethodSignatureForSelector:configureAuxiliaryButtonsSEL];
    if (methodSignature.numberOfArguments != 3)
    {
        NSLog(@"Failed to workaround inline player fullscreen button bug (method not found)");
        return;
    }

    const char *returnType = methodSignature.methodReturnType;
    const char *argType = [methodSignature getArgumentTypeAtIndex:2];
    if (strcmp(returnType, @encode(void)) != 0 || strcmp(argType, @encode(BOOL)) != 0)
    {
        NSLog(@"Failed to workaround inline player fullscreen button bug (type mismatch)");
        return;
    }

    Method configureAuxiliaryButtons = class_getInstanceMethod(MPVideoPlaybackOverlayView, configureAuxiliaryButtonsSEL);
    configureAuxiliaryButtonsIMP = (__typeof__(configureAuxiliaryButtonsIMP))method_getImplementation(configureAuxiliaryButtons);
    method_setImplementation(configureAuxiliaryButtons, (IMP)ConfigureAuxiliaryButtons);
}

然后在运行UIApplicationMain函数之前更新main.m文件以调用WorkaroundInlinePlayerFullScreenButtonBug函数:

Then update your main.m file to call the WorkaroundInlinePlayerFullScreenButtonBug function before running the UIApplicationMain function:

#import "AppDelegate.h"

extern void WorkaroundInlinePlayerFullScreenButtonBug(void);

int main(int argc, char *argv[])
{
    @autoreleasepool
    {
        WorkaroundInlinePlayerFullScreenButtonBug();
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

这篇关于为什么在iOS 10中MPMoviePlayerController全屏按钮图标更改为字幕图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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