0

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

Farhan
  • 3,206
  • 14
  • 49
  • 62
  • Can you post your XML layout as well? – theisenp Aug 10 '11 at 16:52
  • i have edited the code to include xml.. can you please help me here.. – Farhan Aug 10 '11 at 16:57
  • May be you need set the layout parameters for VideoView. I have put code for an Activty doing video playback, on one of the stackoverflow posts. Can refer to http://stackoverflow.com/questions/6977382/videoview-in-eclipse-not-playing-on-phone/6977770#6977770 – Shash316 Aug 10 '11 at 17:00
  • can you please provide me with the xml code as well? – Farhan Aug 10 '11 at 17:07
  • the other thing you could do here is define two different xml layouts with the tag and simply add the pre-defined views to the screen depending on what kind of video is being played. – Codeman Aug 10 '11 at 17:33

2 Answers2

1

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!

Codeman
  • 12,157
  • 10
  • 53
  • 91
  • can you please elaborate a more.. Actually I want to dynamically adjust the video player for the video..There are some videos that are not widescreen and there are some videos that are widescreen with aspect ratio of 16:9 with mattes (horizontal black bars below and above the video), I want my application to dynamically set this.. Do you know if there is any way of setting the aspect ratio for the video??? please do reply – Farhan Aug 10 '11 at 17:05
  • I don't know that there's a way to set the aspect ratio... You would have to adjust the size of your VideoView. You should be able to do this with the code provided, just change the layout_weight of the VideoView to whatever you need with LayoutParams. – Codeman Aug 10 '11 at 17:10
1

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>
Community
  • 1
  • 1
theisenp
  • 8,639
  • 5
  • 39
  • 47
  • Sir, i tried it.. it is partially working.. actually the problem is that.. the horizontal bars now appear at the bottom; however, when i remove the titlebar so that it can be appeared above the video, the whole video is pushed upwards. do you have any idea what is wrong here?? – Farhan Aug 10 '11 at 17:25
  • Try adding an android:gravity="center" field to the LinearLayout. I've updated the XML in my answer. You can remove the Title Bar if you want, but you don't have to. – theisenp Aug 10 '11 at 17:35