Android VideoView not playing Portrait Orientation

Rick Scolaro picture Rick Scolaro · Oct 29, 2012 · Viewed 7k times · Source

THE PLATFORM: Developing in Eclipse using Android SDK 16.

THE PROBLEM: I have a VideoView element that is supposed to fill the entire screen in 480x800 (PORTRAIT ORIENTATION) and it plays fine, but will not orient to portrait. It sticks in landscape mode and the aspect ratio is skewed to fit that way.

WHAT I HAVE ATTEMPTED:

  • using android:screenOrientation="portrait" in manifest
  • using android:orientation="vertical" in the container and the VideoView itself
  • using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); right before I call setContentView
  • trying to set the layout width and height to 480dpx800dp instead of fill_parent
  • trying to set the VideoView width and height to 480px x 800dp instead of fill_parent
  • switching off the auto rotate display

THE XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="480dp"
    android:layout_height="800dp"
    android:background="#000000" 
    android:orientation="vertical" > 

    <VideoView
        android:id="@+id/opening_video"
        android:layout_width="480dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:layout_alignParentBottom="true" 
        android:layout_height="800dp"
        android:orientation="vertical" /> 

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/transparent_button"
        android:contentDescription="@string/back_button_desc"
        android:background="@android:color/transparent" />

</RelativeLayout>

THE CODE:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.activity_start_screen);

        VideoView videoView = (VideoView) findViewById(R.id.opening_video);  

        Uri pathToVideo = Uri.parse("android.resource://com.example.consumerengage/" + R.raw.opening_tablet);  
        videoView.setVideoURI(pathToVideo);  
        videoView.setOnPreparedListener(new OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.setLooping(true);
            }
        });        

        videoView.requestFocus();  
        videoView.start(); 

       // boolean isPlaying = videoView.isPlaying() ; 

       // videoView.stopPlayback();  
       // videoView.clearFocus(); 

       addListenerOnButton();

    }

THE QUESTION: Nothing I have attempted has been successful. How can I get my 480x800 video to play in portrait orientation?

Answer

Raymond P picture Raymond P · Feb 19, 2013

Are you certain your video is is 480x800 and not 800x480? 800x480 is a standard resolution, if you record a video in portrait with a phone the output will still be 800x480 and to have normal playback the video should be turned 90 degrees. What you are describing is what would happen if you try to play a 800x480 video in a 480x800 videoView. If this is the case you could rotate it with video editing software like Windows Live Moviemaker or iMovie if you are on Mac.