为什么 MPMoviePlayerController 全屏按钮图标在 iOS 10 中变为字幕图标?
Why MPMoviePlayerController fullscreen button icon change to caption icon in iOS 10?
我尝试使用 MPMoviePlayerController 作为嵌入式视频播放器,但我发现一个问题,在 iOS 10?
中全屏图标被更改了
是否有任何解决方案可以将其改回原来的全屏按钮?
谢谢,
这是 iOS 8 和 iOS 9 中的样子:
这是 iOS 10:
中的样子
这里有一些代码可以解决 iOS 10 个错误,您可以将其写入 WorkaroundInlinePlayerFullScreenButtonBug.m
文件:
@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
函数之前调用 WorkaroundInlinePlayerFullScreenButtonBug
函数:
#import "AppDelegate.h"
extern void WorkaroundInlinePlayerFullScreenButtonBug(void);
int main(int argc, char *argv[])
{
@autoreleasepool
{
WorkaroundInlinePlayerFullScreenButtonBug();
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
我尝试使用 MPMoviePlayerController 作为嵌入式视频播放器,但我发现一个问题,在 iOS 10?
中全屏图标被更改了是否有任何解决方案可以将其改回原来的全屏按钮?
谢谢,
这是 iOS 8 和 iOS 9 中的样子:
这是 iOS 10:
中的样子这里有一些代码可以解决 iOS 10 个错误,您可以将其写入 WorkaroundInlinePlayerFullScreenButtonBug.m
文件:
@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
函数之前调用 WorkaroundInlinePlayerFullScreenButtonBug
函数:
#import "AppDelegate.h"
extern void WorkaroundInlinePlayerFullScreenButtonBug(void);
int main(int argc, char *argv[])
{
@autoreleasepool
{
WorkaroundInlinePlayerFullScreenButtonBug();
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}