0

I want to show my Video with normal size on portrait, and with Full Size on Landscape. So when the users starts to watch at portrait and switches to Landscape(Rotates the device) It goes fullscreen; when vice versa, It goes back to original size. I've checked internet but couldn't find a good example. My codes are below.

enter image description here enter image description here

VideoActivity.java:

public class VideoActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_video);


        Bundle bund = getIntent().getExtras();
        String s = bund.getString("LINK");
        VideoView videoView = (VideoView) findViewById(R.id.videoView);
        MediaController controller = new MediaController(this);
        videoView.setVideoPath(s);
        videoView.setMediaController(controller);
        videoView.start();
    }
}

activity_video.xml :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}"
    android:background="#000000"
    >

    <VideoView
        android:id="@+id/videoView"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"

         />

</RelativeLayout>

Basically. When user starts the video it can be original size (If Portrait Mode) but whenever he turns the phone around I want it to go fullscreen automatically. And when turned back to portrait, original size again.

Thanks.

1 Answers1

1

Create a new file named bools.xml in values folder as below:

<?xml version="1.0" encoding="utf-8"?>
    <resources>
    <item type="bool" name="isPortLayout">true</item>
</resources>

create another file in values-land folder named bools.xml as below:

<?xml version="1.0" encoding="utf-8"?>
    <resources>
    <item type="bool" name="isPortLayout">false</item>
</resources>

Now in your activity before calling to setContentView get this resource and based on its value set Activity as full screen or not:

boolean isPortLayout = getResources().getBoolean(R.bool.isLargeLayout);
if(isPortLayout) {
    // PORT
} else {
    // LAND
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

Set your VideoView's width and height match_parent.

Ali Behzadian Nejad
  • 8,804
  • 8
  • 56
  • 106
  • answer is based on my answer to another question: http://stackoverflow.com/questions/27020276/how-to-make-application-run-portrait-in-phone-and-landscape-on-tablets/27020935#27020935 – Ali Behzadian Nejad Nov 23 '14 at 14:47
  • Can you post a screen shot of what it is and explain what it should be? – Ali Behzadian Nejad Nov 23 '14 at 14:54
  • I've uploaded the Screenshots and gave another explaination there. Basically when video is playing if it is Portrait mode I want it to be original sized; but if Landscape Full Screen video. And it should always change when user rotates the phone, even when playing. –  Nov 23 '14 at 15:04
  • Because `video with/height ratio` is not equal to `screen's width/screen height ratio`, you will have always a blank margin or your video must be stretched. So make your background black and the video view width and height `match_parent`. I did this and it is OK. – Ali Behzadian Nejad Nov 23 '14 at 15:52
  • There is a problem there, when I do that It is full screen at portrait as well. I want it to be full only at Landscape –  Nov 23 '14 at 15:59
  • I was able to do it with the latest method, thank you! –  Nov 23 '14 at 16:06