dorjeduck
dorjeduck

Reputation: 7794

android mediacontroller - defining the mediacontroller in the layout xml

In the android documentation on the MediaController widget I read

Functions like show() and hide() have no effect when MediaController is created in an xml layout.

which points to the fact the the mediacontroller can be defined in the xml layout. As I want a controller which never hides and also doesn't take the focus so that it is possible to click buttons on the rest of the screen I tried to go the xml layout way. As I can't get this to work I am looking for an example on how to use MediaController by defining it in the layout xml.

Any hint highly appreciated

Upvotes: 2

Views: 1612

Answers (1)

vyndor
vyndor

Reputation: 368

I found one workaround for Android 2.x. Sadly it doesn't seem to work in 4.x.

You need to call setAnchorView() to show the MediaController. This code worked for me in Android 2.2 and 2.3.6, but caused crash in 4.0.4:

mediaController.setAnchorView(mediaController);

I also tried passing activity content view to setAnchorView(), but it still crashing in 4.0.4.

The most reliable way is to instantiate it programatically as said in documentation:

The way to use this class is to instantiate it programatically.

Upvotes: 1

Related Questions