tags:

views:

1747

answers:

3

I've created a layout.xml file with the following XML, but I can't get the MediaController to appear at all.

<MediaController android:id="@+id/media_controller"
    android:layout_width="fill_parent"
    android:layout_height="200px"
    android:visibility="visible"/>

In code, I can obtain a reference to it from code, call show(), etc, but it never appears.

I have noticed in the android dev documentation (MediaController.html) that it states, "The way to use this class is to instantiate it programatically.", so maybe I'm a dufus and just need to do something differently such as not do what I'm doing. :)

I CAN get it to appear if I do it programmatically, but I need it to always appear on the screen. Am I just being stupid, or is it just not meant to be inflated via XML?

A: 

http://www.docstoc.com/docs/9811647/Media-on-the-Android-Platform

This doc suggests you may need to extend the Controller to get the behaviour that you need.

You could also show it for a very long time i suppose ;)

I'm presently struggling to even get the controller to show then I press a button :\

(also interesting how quickly google added this question to search results)

dpn
+1  A: 

From this sample project:

ctlr=new MediaController(this);
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);

Then, it will appear when you tap the screen towards the bottom edge of your VideoView.

In terms of keeping it on screen all the time...I don't know if that's possible. You can always create your own controller -- here's a sample project that creates its own pop-up translucent controller. It's really not all that hard, and you get full control over everything, including arranging for it to be on-screen all the time.

CommonsWare
A: 

By using show(0) media controller will be shown until hide() is called by an interaction with the player. I found unfortunately no way to prevent hide() yet;-(

MediaController mc = new MediaController(MPlayer.this);
mc.setMediaPlayer(MPlayer.this);
mc.setEnabled(true);

View mMediaControllerView = (View)findViewById(R.id.media_controller); //get it from your layout

mc.setAnchorView(mMediaControllerView); mMediaControllerView.setOnTouchListener(mPlayerTouchListener);//also use show() in onTouchListener

new Handler().postDelayed(new Runnable() {

public void run() {
   mc.show(0);
} }, 1500);

Wait for screen to buid in order to avoid a bug in android (1,5 seconds here)

duessi