2016-10-13 27 views
9

Tôi cố gắng sử dụng MPMoviePlayerController làm trình phát video được nhúng nhưng tôi phát hiện ra sự cố khi biểu tượng toàn màn hình bị thay đổi trong iOS 10?Tại sao MPMoviePlayerController biểu tượng toàn màn hình nút thay đổi thành biểu tượng chú thích trong iOS 10?

Có giải pháp nào để thay đổi lại thành nút toàn màn hình gốc không?

Cảm ơn bạn,

Đây là những gì nó trông giống như trong iOS 8 và iOS 9:

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

Đây là những gì nó trông giống như trong iOS 10:

This is what it look like in iOS 10

+0

Bạn đã tìm thấy bất kỳ giải pháp của vấn đề này? – Jasmit

+0

Không, tôi sẽ cập nhật mục tiêu của mình lên ios 9 và chuyển sang sử dụng AVPlayer thay thế. –

Trả lời

2

Dưới đây là một số mã để giải quyết lỗi iOS 10 mà bạn có thể viết trong tệp 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); 
} 

Sau đó cập nhật main.m tập tin của bạn để gọi WorkaroundInlinePlayerFullScreenButtonBug chức năng trước khi chạy UIApplicationMain fcuntion:

#import "AppDelegate.h" 

extern void WorkaroundInlinePlayerFullScreenButtonBug(void); 

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

Bạn có thể cho tôi biết cách triển khai giải pháp này trong một dự án Swift không có tệp main.m không? Tôi có cùng một vấn đề với biểu tượng và của bạn là giải pháp duy nhất tôi đã tìm thấy cho việc này. –

Các vấn đề liên quan