Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaController Positioning

I am using VideoView to show play a local mp4 and i am using MediaController as well. The media control bar is not displaying under my video clip but in the middle of the screen. I used setAnchorView to attach it to my videoView but that had no affect. How do i position my mediacontroller to be directly under my videoview?

public class VideoDemo extends Activity {
private VideoView video;
private MediaController ctlr;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    setContentView(R.layout.main);

    File clip=new File(Environment.getExternalStorageDirectory(),
                                         "test.mp4");

    if (clip.exists()) {
        video=(VideoView)findViewById(R.id.video);
        video.setVideoPath(clip.getAbsolutePath());

        ctlr=new MediaController(this, false);
        ctlr.setAnchorView(video);
        ctlr.setMediaPlayer(video);
        video.setMediaController(ctlr);
        video.requestFocus();
    }
}
}

and my layout is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="400dp"
    android:layout_height="400dp"
    android:background="#fff"
    >
<VideoView 
     android:id="@+id/video" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</LinearLayout>
like image 221
newdev Avatar asked Jun 28 '11 18:06

newdev


People also ask

What is MediaController?

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.

How to set MediaController with VideoView in Android?

Just define the MediaController object in on create and then add the view to that otherwise the error will like adding a view in a null object reference......

How do I make Android videos full screen?

Tap the video you'd like to watch. At the bottom of the video player, tap full screen .


2 Answers

To get a tablet app to display the media controller at full screen size instead of in the middle, you need to put a uses-sdk line in your AndroidManifest.xml and target an sdk version that is aware of the existence of higher resolution devices - otherwise a lot of views are limited to 480x320

Edit: I'd previously posted of having some problems with adding the uses-sdk resulting in the rewind/pause/forward showing without a progress slider underneath, but turns out that on a particular tablet adapted to android the soft home/menu/etc buttons bar was simply covering the lower half of the media controller.

like image 138
Chris Stratton Avatar answered Sep 23 '22 13:09

Chris Stratton


Try:

ctrl.setPadding(x, y, z, w)
like image 29
zhangjie Avatar answered Sep 21 '22 13:09

zhangjie