How Can I Get An Android Mediacontroller To Appear From Layout Xml?
Solution 1:
From this sample project:
ctlr=newMediaController(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.
Solution 2:
You can prevent the MediaController from hiding extending MediaController and override hide() to do nothing. eg:
classUnhideableMediaControllerextendsMediaController
{
// override whichever contstructors you need to. publicUnhideableMediaController(Context context)
{
super(context);
}
// override hide to do nothingpublicvoidhide()
{
// don't hide
}
}
Solution 3:
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;-(
MediaControllermc=newMediaController(MPlayer.this);
mc.setMediaPlayer(MPlayer.this);
mc.setEnabled(true);
ViewmMediaControllerView= (View)findViewById(R.id.media_controller); //get it from your layout
mc.setAnchorView(mMediaControllerView);
mMediaControllerView.setOnTouchListener(mPlayerTouchListener);//also use show() in onTouchListenernewHandler().postDelayed(newRunnable() {
publicvoidrun() {
mc.show(0);
} }, 1500);
Wait for screen to buid in order to avoid a bug in android (1,5 seconds here)
Solution 4:
You can inflate a mediacontroller from the layout xml. Also after obtaining a reference of it can set a videoview as an anchor.
- But this will cause a crash as soon as you try to touch mediacontroller (I am trying to figure out why its happening).
Also In this mediaController will appear always.
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><VideoViewandroid:id="@+id/mVideoView"android:layout_width="match_parent"android:layout_height="match_parent" /><MediaControllerandroid:id="@+id/mediaController1"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:focusable="false"android:focusableInTouchMode="false"/></RelativeLayout>
In activity,
publicclassAnimationActivityextendsActivityimplementsOnClickListener {
privateMediaControllermController=null;
privateVideoViewmVideoView=null;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation);
mController = (MediaController) findViewById(R.id.mediaController1);
mController.post(newRunnable() {
@Overridepublicvoidrun() {
mVideoView = (VideoView) findViewById(R.id.mVideoView);
mVideoView.setVideoURI(Uri.parse("android.resource://"
+ getPackageName() + "/" + R.raw.video0));
mController.setAnchorView(mVideoView);
mVideoView.setSoundEffectsEnabled(false);
mVideoView.start();
}
});
}
}
Solution 5:
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)
Post a Comment for "How Can I Get An Android Mediacontroller To Appear From Layout Xml?"