2

i am not able to change the orientation of my video in landscape mode. Here's my code:

VideoView videoView = (VideoView) findViewById(R.id.video_view);
    MediaController mediaController = new MediaController(this); //Creating the media controller
    mediaController.setAnchorView(videoView);

    //Specify the location of media file
    Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"
            + R.raw.my_video);

    videoView.setMediaController(mediaController);
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.start();

    videoView.setOnCompletionListener(this);

and in manifest i have added below lines:

android:configChanges="keyboard|orientation|screenSize"
        android:screenOrientation="landscape"

and with this it's not working. Thanks in advance!! :)

SKP
  • 410
  • 5
  • 20

3 Answers3

2

I solved this problem by adding below line of code in onStart of the activity:

@Override
protected void onStart() {
    super.onStart();
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
SKP
  • 410
  • 5
  • 20
1

This is what I did to force scaling the video to landscape, hope it help.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

    <VideoView
        android:id="@+id/video_view"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>
Mark KWH
  • 1,059
  • 1
  • 8
  • 20
0

Changing orientation of your video view can be done by changing the orientation of you screen.

Use this to change the orientation of you device dynamically on a button press etc.

You can define a new layout-landscape in the way you want. So basically whenever you press the button, the orientation of the device changes and so changes the videoview orientation too.

Community
  • 1
  • 1
Pramod Ravikant
  • 1,039
  • 2
  • 11
  • 28