MediaController Positioning
Asked Answered
D

4

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>
Duck answered 28/6, 2011 at 18:27 Comment(2)
Did you ever figure this out? I am creating a tablet application and am wanting to do the exact same thing. No problem playing the video, I just want the controls to show over the videoview.Coffeepot
Same issue for tablet here. :( Anybody found a solution yet?Yield
E
1

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.

Entrench answered 19/2, 2012 at 6:0 Comment(0)
C
1

Try:

ctrl.setPadding(x, y, z, w)
Cousins answered 8/3, 2012 at 13:19 Comment(0)
L
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!

Lennon answered 29/11, 2011 at 7:12 Comment(0)
F
0

i have a solution for this, add a vertical layout then put the videoview in that layout, the media controller will appear at the bottom of the layout where thw video is displayed.

Frodin answered 14/6, 2013 at 2:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.