Reputation: 420
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!! :)
Upvotes: 2
Views: 5952
Reputation: 420
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);
}
Upvotes: 2
Reputation: 1089
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>
Upvotes: 1
Reputation: 1037
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.
Upvotes: 0