how to create custom UI for android MediaController

感情迁移 提交于 2019-11-26 17:01:55

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:

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()

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

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

hussamabd

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!