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?
Go to plugins -> Android support and disable this. Restart Android studio and enable the plugin again. Worked for me.
android.widget.MediaController. A view containing controls for a MediaPlayer. Typically contains the buttons like "Play/Pause", "Rewind", "Fast Forward" and a progress slider. It takes care of synchronizing the controls with the state of the MediaPlayer. The way to use this class is to instantiate it programmatically.
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.
You can prevent the MediaController from hiding extending MediaController and override hide() to do nothing. eg:
class UnhideableMediaController extends MediaController
{
// override whichever contstructors you need to.
public UnhideableMediaController(Context context)
{
super(context);
}
// override hide to do nothing
public void hide()
{
// don't hide
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With