I'm trying to replicate in my app what the Youtube app does when playing a video.
Portrait mode: Shows the video using only 40% of the screen and the rest with information about the video.
Landscape mode: Shows the video and the window in fullscreen mode.
I've seen a lot of threads in stack overflow and other forums about this subject, but none of them seem to work with me. Currently i have my videoplayeractivity with android:configChanges="keyboardHidden|orientation|screenSize" and i've overriden the onConfigurationChanged event with the following code:
@Override
public void onConfigurationChanged(Configuration config)
{
super.onConfigurationChanged(config);
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
// requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else
{
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
}
This doesn't put the app in fullscreen, and if i uncomment the requestwindowfeature it will crash because "requestFeature() must be called before adding content". Later on i've tried removing the onConfigurationChanged event and on the onCreate event i've tried :
@Override
public void onCreate(Bundle savedInstanceState)
{
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
But crashes with NullPointerException at com.android.internal.policy.impl.PhoneWindow$PanelFeatureState.onRestoreInstanceState(PhoneWindow.java:3527) if i start the activity on portrait and then flip to landscape. Any suggestions?