Reputation: 746
I want to play the video only in landscape mode. I tried the following code but the entire activity turns on landscape mode but I want only the videoview in the Xml layout to play in the landscape.
<activity android:name=".Video_play"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
...
</activity>
Upvotes: 2
Views: 68
Reputation: 7666
First of all... check the SDK version of the user to match API lvl 8:
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.FROYO){
// This will only hit API lvl 8
// myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
And myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
will force you screen to be landscape. Remember to have the xml layout-land to make sure the UI will be good for the user.
Upvotes: 1
Reputation: 6967
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.
Upvotes: 0