Search code examples
androidmediacontroller

Android MediaController custom graphics


Is there a way to "easily" change the graphics of the MediaController to show a "skip ahead 5sec" or "rev 5 sec" (which I have) instead of the ff and rew buttons?


Solution

  • The best will be to copy source code of MediaController and change layout according to Your needs. Not easy but the best way :)

    You can also try get

    ImageButton mRewButton;
    

    by reflection and try to change it but i will not recommend that. Here is how this can be done:

    try {
        Field field = mediaController.getClass().getDeclaredField("mRewButton");
        field.setAccessible(true);
        Object value = field.get(mediaController);
        if (value instanceof ImageButton) {
            // do some changes here
            ((ImageButton) value).setImageResource(R.mipmap.ic_launcher);
        }
    } catch (NoSuchFieldException e) {
        //handle errors gently
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        //handle errors gently
        e.printStackTrace();
    }
    

    Just make sure that before that Your controller is initialized. Result looks like this:

    enter image description here