我是菜鸟,所以这是我能提供的最好帮助,顺便说一句,我在 Exoplayer 演示应用程序中对此进行了测试,我将 exoplayer 高度更改为 600px,并应用了此代码,它运行得很好。
添加此代码来检测屏幕方向
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checking the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//First Hide other objects (listview or recyclerview), better hide them using Gone.
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) simpleExoPlayerView.getLayoutParams();
params.width=params.MATCH_PARENT;
params.height=params.MATCH_PARENT;
simpleExoPlayerView.setLayoutParams(params);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
//unhide your objects here.
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) simpleExoPlayerView.getLayoutParams();
params.width=params.MATCH_PARENT;
params.height=600;
simpleExoPlayerView.setLayoutParams(params);
}
}
顺便说一句,如果您不使用 FrameLayout 而是relativelayout
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) simpleExoPlayerView.getLayoutParams();
我忘记了您需要隐藏操作或标题栏,希望此代码有帮助,在上面的代码中添加这些代码,而且我认为您需要将您的活动扩展到 AppCompatActivity 才能使 getSupportActionBar 代码正常工作。
if(getSupportActionBar()!=null) {
getSupportActionBar().hide();
}
//To show the action bar
if(getSupportActionBar()!=null) {
getSupportActionBar().show();
}
这也可能有助于将整个项目设置为全屏,隐藏状态栏等,必须根据屏幕方向添加到 onConfigurationChanged 中。
在风景中
ExoPlayerActivity.this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN || View.SYSTEM_UI_FLAG_IMMERSIVE);
在肖像中退出全屏
ExoPlayerActivity.this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
我编辑了代码,添加了 View.SYSTEM_UI_FLAG_IMMERSIVE 以防止用户单击视频中的控制按钮时显示状态栏。