首页 > 解决方案 > ExoPlayer rotate in FullScreen

问题描述

I want to rotate my player when device is rotating. I use this for making my player full screen

 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
                                                                |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                                                                |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

I try setRotation(90) but my view lose size,from corners ! When i try just change my device orientation for making full screen, player first player draw half of view,after it go to normal fullscreen mode[!

After 1 sec , <code>onMeasure</code> called again and video get his normal size

标签: androidrotationfullscreenexoplayer

解决方案


I found the answer myself, this is fullScreen integration for ReactExoPlayerView

private void openFullscreenDialog() {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        ((ViewGroup) exoPlayerView.getParent()).removeView(exoPlayerView);
        if (playerControlView.getParent() != null) {
            ((ViewGroup) playerControlView.getParent()).removeView(playerControlView); // <- fix
        }
        exoPlayerView.addView(playerControlView);
        mFullScreenDialog = new Dialog(themedReactContext, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        mFullScreenDialog.addContentView(exoPlayerView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        mFullScreenDialog.setCancelable(false);
        mFullScreenDialog.setOnKeyListener((dialog, keyCode, event) -> {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                if (isFullscreen) {
                    fullScreenButtonClick();
                }
                return true;
            } else {
                return false;

            }
        });
        mFullScreenDialog.show();
    }

private void closeFullscreenDialog() {
          activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        ((ViewGroup) exoPlayerView.getParent()).removeView(exoPlayerView);
        if (playerControlView.getParent() != null) {
            ((ViewGroup) playerControlView.getParent()).removeView(playerControlView); // <- fix
        }
        addView(exoPlayerView);
        setControls(true);
        mFullScreenDialog.dismiss();
    }

Hope it will help someone


推荐阅读