56

I want to customize the controls in the MediaController for my video player. I want to swap out the image for the play button, change the skin, change the color, ect.

Is there a known way of doing this?

Thanks

user1681001
  • 632
  • 2
  • 7
  • 7
  • 1
    What have you done until now? Have you tried to code something? Add sample code. – Michaël Sep 18 '12 at 18:03
  • http://stackoverflow.com/questions/2044000/change-style-of-android-mediacontroller/36173266#36173266 offers a good solution to change existing elements – OneWorld Mar 23 '16 at 08:39

2 Answers2

105

I had the same problem on a recent project and ended up creating a custom implementation based on the stock MediaController. It adds a fullscreen button at the far right, but even if that's not what you want this class should be a good starting point.

Code:

Image resources:

  • enter image description here
  • http://imgur.com/JYJGN
  • http://imgur.com/R0txq
  • http://imgur.com/dQ6wA

Gotchas:

  • The class assumes the anchor view is a FrameLayout to position itself at the bottom.
  • The class does not use a Window to ensure control floats on top of the anchor. However, this hasn't been a problem for me as the show() method does mAnchor.addView() every time.
  • The class uses its own MediaPlayerControl protocol. This allows customizations such as toggleFullScreen()

UPDATE (2013): See this tutorial for more details: http://www.brightec.co.uk/blog/custom-android-media-controller

UPDATE (2018): You can now use the wonderful ExoPlayer and fully customize your player UI simply by overriding a layout file.

Blago
  • 4,697
  • 2
  • 34
  • 29
  • @Blago you have an inner class containing a WeakReference to the outer class. This is useless and doesn't do what you think because an inner class is just syntactic sugar for a top-level class to which you pass a reference to the outer class in the constructor. – dcow Oct 03 '13 at 20:53
  • Seekbar doesn't work properly when the user seeks/moves it manually. In that case seekbar stops updating itself. – Umer Farooq Dec 17 '14 at 10:56
  • Yeah, but you know that this project not is a full because not works correctly (bad assynk + bad instance to generate) but is a good example to start, thanks. –  Mar 01 '16 at 11:58
  • full screen button not active – Trần Hoà Jun 01 '16 at 04:15
-6

I tested it and it works great on 4.4 kitkat, but like KAPLANDROID said blackscreen appeared on android 2.3.6 but the music and videocontroller works fine,

Have found a solution, just put this code

videoHolder.setType( SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS );

after this

videoHolder.addCallback( this );

and you are ready to go

user3666197
  • 1
  • 6
  • 50
  • 92
hussamabd
  • 38
  • 5