androidvideowidescreen

android: playing widescreen video


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 ??


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>