Alex Rivera | Logout

MediaController Positioning

Asked 2011-06-28T18:27:13.173
13

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>
Edit
Report

1 Answer

0

Can you try this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="400dp"
    android:layout_height="400dp"
    android:background="#fff"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/video"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

</LinearLayout>

Then add the MediaController using as Layout Params

  • layout_width: fill_parent
  • layout_height: wrap_content
  • layout_weight: 0

Hope this helps!

answered 2011-11-29T07:12:25.467

Your Answer