Question

I developed an application for playing video.. the code for playing video is here..

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.videoview);
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    filename = extras.getString("videofilename");
    mVideoView = (VideoView)findViewById(R.id.videoview);

    path=filename;
    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(
                ViewVideo.this,
                "Please edit VideoViewDemo Activity, and set path"
                        + " variable to your media file URL/path",
                Toast.LENGTH_LONG).show();

    } else {

          mVideoView.setVideoPath(path);
          mc = new MediaController(this);
          mVideoView.setMediaController(mc);
          mVideoView.requestFocus();
          mVideoView.bringToFront();
          mVideoView.start();

    }
}

Here is the xml code

 <?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="fill_parent"
           android:layout_height="fill_parent" >
   <VideoView android:id="@+id/videoview"
             android:layout_width="fill_parent"
             android:layout_alignParentRight="true"
             android:layout_alignParentLeft="true"
             android:layout_alignParentTop="true"
             android:layout_alignParentBottom="true"
             android:layout_height="fill_parent">
       </VideoView>
       </RelativeLayout>

The problem is that when I try to play a widescreen 16:9 video. It shows it on fullscreen and the characters appear squeezed. I need to play in widescreen format with mattes (two horizontal black bars above and below the video).. Any suggestions please ??

Was it helpful?

Solution

Here's a related question.

It seems like you are forcing the video to align with all four sides of the screen by using

android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"

This is throwing off the aspect ratio of the video. Instead try putting it in a LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">

    <VideoView android:id="@+id/videoview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</LinearLayout>

OTHER TIPS

Try using the MediaViewer in a vertical linearLayout.

Something like this (off the top of my head, so don't trust it implicitly):

<LinearLayout android:layout_height="match_parent" 
    android:layout_width="match_parent" android:weightSum="9"
    android:orientation="vertical">
    <VideoView android:layout_height="0dp" android:layout_width="0dp"
        android:layout_weight="6" />
</LinearLayout>

This should fill up 2/3 of the vertical area of the screen.

Adjust weightSum and layout_weight as desired.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top