Change MPMoviePlayerController fullscreen button icon to caption icon in iOS in Swift Project












2















I am using MPMoviePlayerController as an embedded video player, but the fullscreen icon from iOS 10+ has changed.



Original image in iOS 8, 9



enter image description here



Image in iOS 10+



enter image description here



I made the change earlier in an Objective-C project. Referring to this StackOverflow post. 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);
}


And then calling it from the main.m function as



#import "AppDelegate.h"

extern void WorkaroundInlinePlayerFullScreenButtonBug(void);

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


The above solution worked fine, but in Swift, I am not sure how to achieve this functionality.










share|improve this question




















  • 1





    Please show the relevant code in this question.

    – Magnas
    Jan 1 at 20:14






  • 3





    "I am using MPMoviePlayerController". Don't. It is deprecated. Use AVPlayerViewController.

    – matt
    Jan 1 at 23:25











  • @matt It is better not to, but I was still curious to find a solution to this problem in Swift.

    – Md. Ibrahim Hassan
    Jan 2 at 4:10











  • Do not keep re-adding a nonsense tag when the community removes it. I’ve removed it again, do not re-create it, it is no better than the now-removed swift-converter tag.

    – Martijn Pieters
    Jan 3 at 7:49


















2















I am using MPMoviePlayerController as an embedded video player, but the fullscreen icon from iOS 10+ has changed.



Original image in iOS 8, 9



enter image description here



Image in iOS 10+



enter image description here



I made the change earlier in an Objective-C project. Referring to this StackOverflow post. 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);
}


And then calling it from the main.m function as



#import "AppDelegate.h"

extern void WorkaroundInlinePlayerFullScreenButtonBug(void);

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


The above solution worked fine, but in Swift, I am not sure how to achieve this functionality.










share|improve this question




















  • 1





    Please show the relevant code in this question.

    – Magnas
    Jan 1 at 20:14






  • 3





    "I am using MPMoviePlayerController". Don't. It is deprecated. Use AVPlayerViewController.

    – matt
    Jan 1 at 23:25











  • @matt It is better not to, but I was still curious to find a solution to this problem in Swift.

    – Md. Ibrahim Hassan
    Jan 2 at 4:10











  • Do not keep re-adding a nonsense tag when the community removes it. I’ve removed it again, do not re-create it, it is no better than the now-removed swift-converter tag.

    – Martijn Pieters
    Jan 3 at 7:49
















2












2








2








I am using MPMoviePlayerController as an embedded video player, but the fullscreen icon from iOS 10+ has changed.



Original image in iOS 8, 9



enter image description here



Image in iOS 10+



enter image description here



I made the change earlier in an Objective-C project. Referring to this StackOverflow post. 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);
}


And then calling it from the main.m function as



#import "AppDelegate.h"

extern void WorkaroundInlinePlayerFullScreenButtonBug(void);

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


The above solution worked fine, but in Swift, I am not sure how to achieve this functionality.










share|improve this question
















I am using MPMoviePlayerController as an embedded video player, but the fullscreen icon from iOS 10+ has changed.



Original image in iOS 8, 9



enter image description here



Image in iOS 10+



enter image description here



I made the change earlier in an Objective-C project. Referring to this StackOverflow post. 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);
}


And then calling it from the main.m function as



#import "AppDelegate.h"

extern void WorkaroundInlinePlayerFullScreenButtonBug(void);

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


The above solution worked fine, but in Swift, I am not sure how to achieve this functionality.







ios iphone swift mpmovieplayercontroller code-migration






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 23 at 18:54









ashish saxena

386




386










asked Jan 1 at 19:33









Md. Ibrahim HassanMd. Ibrahim Hassan

3,60211131




3,60211131








  • 1





    Please show the relevant code in this question.

    – Magnas
    Jan 1 at 20:14






  • 3





    "I am using MPMoviePlayerController". Don't. It is deprecated. Use AVPlayerViewController.

    – matt
    Jan 1 at 23:25











  • @matt It is better not to, but I was still curious to find a solution to this problem in Swift.

    – Md. Ibrahim Hassan
    Jan 2 at 4:10











  • Do not keep re-adding a nonsense tag when the community removes it. I’ve removed it again, do not re-create it, it is no better than the now-removed swift-converter tag.

    – Martijn Pieters
    Jan 3 at 7:49
















  • 1





    Please show the relevant code in this question.

    – Magnas
    Jan 1 at 20:14






  • 3





    "I am using MPMoviePlayerController". Don't. It is deprecated. Use AVPlayerViewController.

    – matt
    Jan 1 at 23:25











  • @matt It is better not to, but I was still curious to find a solution to this problem in Swift.

    – Md. Ibrahim Hassan
    Jan 2 at 4:10











  • Do not keep re-adding a nonsense tag when the community removes it. I’ve removed it again, do not re-create it, it is no better than the now-removed swift-converter tag.

    – Martijn Pieters
    Jan 3 at 7:49










1




1





Please show the relevant code in this question.

– Magnas
Jan 1 at 20:14





Please show the relevant code in this question.

– Magnas
Jan 1 at 20:14




3




3





"I am using MPMoviePlayerController". Don't. It is deprecated. Use AVPlayerViewController.

– matt
Jan 1 at 23:25





"I am using MPMoviePlayerController". Don't. It is deprecated. Use AVPlayerViewController.

– matt
Jan 1 at 23:25













@matt It is better not to, but I was still curious to find a solution to this problem in Swift.

– Md. Ibrahim Hassan
Jan 2 at 4:10





@matt It is better not to, but I was still curious to find a solution to this problem in Swift.

– Md. Ibrahim Hassan
Jan 2 at 4:10













Do not keep re-adding a nonsense tag when the community removes it. I’ve removed it again, do not re-create it, it is no better than the now-removed swift-converter tag.

– Martijn Pieters
Jan 3 at 7:49







Do not keep re-adding a nonsense tag when the community removes it. I’ve removed it again, do not re-create it, it is no better than the now-removed swift-converter tag.

– Martijn Pieters
Jan 3 at 7:49














1 Answer
1






active

oldest

votes


















1














The solution to this problem has multiple stages. First, we need to add a main.m to our Swift so that the code in the original solution can be injected. In Swift projects the main file is abstracted. Refer to this post.



So the first step is to remove @UIApplicationMain keyword from AppDelegate class.



Then we add a main.m by adding an Objective-C.m file and naming it as main
enter image description here.



Add the following code as below in the main.m file



#import <UIKit/UIKit.h>
#import "MoviePlayerDemo-Swift.h"

extern void WorkaroundInlinePlayerFullScreenButtonBug(void);

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


The original icon changing code remains the same as in the original answer:



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





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998346%2fchange-mpmovieplayercontroller-fullscreen-button-icon-to-caption-icon-in-ios-in%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The solution to this problem has multiple stages. First, we need to add a main.m to our Swift so that the code in the original solution can be injected. In Swift projects the main file is abstracted. Refer to this post.



    So the first step is to remove @UIApplicationMain keyword from AppDelegate class.



    Then we add a main.m by adding an Objective-C.m file and naming it as main
    enter image description here.



    Add the following code as below in the main.m file



    #import <UIKit/UIKit.h>
    #import "MoviePlayerDemo-Swift.h"

    extern void WorkaroundInlinePlayerFullScreenButtonBug(void);

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


    The original icon changing code remains the same as in the original answer:



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





    share|improve this answer




























      1














      The solution to this problem has multiple stages. First, we need to add a main.m to our Swift so that the code in the original solution can be injected. In Swift projects the main file is abstracted. Refer to this post.



      So the first step is to remove @UIApplicationMain keyword from AppDelegate class.



      Then we add a main.m by adding an Objective-C.m file and naming it as main
      enter image description here.



      Add the following code as below in the main.m file



      #import <UIKit/UIKit.h>
      #import "MoviePlayerDemo-Swift.h"

      extern void WorkaroundInlinePlayerFullScreenButtonBug(void);

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


      The original icon changing code remains the same as in the original answer:



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





      share|improve this answer


























        1












        1








        1







        The solution to this problem has multiple stages. First, we need to add a main.m to our Swift so that the code in the original solution can be injected. In Swift projects the main file is abstracted. Refer to this post.



        So the first step is to remove @UIApplicationMain keyword from AppDelegate class.



        Then we add a main.m by adding an Objective-C.m file and naming it as main
        enter image description here.



        Add the following code as below in the main.m file



        #import <UIKit/UIKit.h>
        #import "MoviePlayerDemo-Swift.h"

        extern void WorkaroundInlinePlayerFullScreenButtonBug(void);

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


        The original icon changing code remains the same as in the original answer:



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





        share|improve this answer













        The solution to this problem has multiple stages. First, we need to add a main.m to our Swift so that the code in the original solution can be injected. In Swift projects the main file is abstracted. Refer to this post.



        So the first step is to remove @UIApplicationMain keyword from AppDelegate class.



        Then we add a main.m by adding an Objective-C.m file and naming it as main
        enter image description here.



        Add the following code as below in the main.m file



        #import <UIKit/UIKit.h>
        #import "MoviePlayerDemo-Swift.h"

        extern void WorkaroundInlinePlayerFullScreenButtonBug(void);

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


        The original icon changing code remains the same as in the original answer:



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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 10:00









        CrulexCrulex

        834814




        834814
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998346%2fchange-mpmovieplayercontroller-fullscreen-button-icon-to-caption-icon-in-ios-in%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas