2016-10-13 15 views
9

我尝试使用MPMoviePlayerController作为嵌入式视频播放器,但我发现iOS 10中全屏图标发生了更改的问题?为什么MPMoviePlayerController全屏按钮图标更改为iOS 10中的标题图标?

是否有任何解决方案将其更改回原始全屏按钮?

谢谢

这是它看起来像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

+0

你有没有发现这个问题的任何解决方案? – Jasmit

+0

不,我最终将目标更新为ios 9,并转而使用AVPlayer。 –

回答

2

下面是一些代码来解决你可以在WorkaroundInlinePlayerFullScreenButtonBug.m文件中写入的iOS 10错误:

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

然后更新您的main.m文件来调用运行UIApplicationMain fcuntion前WorkaroundInlinePlayerFullScreenButtonBug功能:

#import "AppDelegate.h" 

extern void WorkaroundInlinePlayerFullScreenButtonBug(void); 

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

你能告诉我如何在没有main.m文件的Swift项目中实现这个解决方案吗?我在图标上遇到了同样的问题,您的问题是我找到的唯一解决方案。 –