1

i want to change the Screen Orientation to SENSOR when the Frame Layout is visible (i.e video is playing in full screen) which is working fine , But i want to revert it back to PORTRAIT when the frame layout is gone Which is Not working (No Errors, but the code is not doing anything) i have tried this so far

// Finally show the custom view container.
        mCustomViewContainer.setVisibility(View.VISIBLE);
        mCustomViewContainer.bringToFront();

        // auto orientation change if video is playing
        if (mCustomViewContainer.getVisibility() == View.VISIBLE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        } else {        
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }       
    }

the workaround i found was to change orientation onbackpressed because that's where i am hiding my frame layout also

@Override
public void onBackPressed() {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    exitdlg = (View) findViewById(R.id.exitdlg);
    options1 = (View) findViewById(R.id.options1);
    if (mCustomView != null) {// close full screen video view if open
        mWebChromeClient.onHideCustomView();// FULL-SCREEN VIDEO-5
    } else if (options1.getVisibility() == View.VISIBLE) {
        findViewById(R.id.options1).setVisibility(View.GONE);

    } else if (exitdlg.getVisibility() == View.GONE) {// this brings
                                                        // up/hides
        // menu 1 on hardware
        // options btn
        // Its visible
        findViewById(R.id.exitdlg).setVisibility(View.VISIBLE);
    } else {
        // Either gone or invisible
        findViewById(R.id.exitdlg).setVisibility(View.GONE);

    }
}

but it only works when i press back button Twice which i don't want. that's where i got this code

Community
  • 1
  • 1
User_420
  • 83
  • 2
  • 11

0 Answers0