【发布时间】:2021-08-01 07:21:04
【问题描述】:
我有一个 VideoView 用于从 url 加载视频。我希望它有一个像 YouTube 一样的状态栏。我使用了 MediaController 但它只有倒带、前进、暂停和恢复。我希望它有一个按钮,单击它可以全屏并退出全屏。 任何我感激的帮助。
【问题讨论】:
标签: android kotlin fullscreen android-videoview
我有一个 VideoView 用于从 url 加载视频。我希望它有一个像 YouTube 一样的状态栏。我使用了 MediaController 但它只有倒带、前进、暂停和恢复。我希望它有一个按钮,单击它可以全屏并退出全屏。 任何我感激的帮助。
【问题讨论】:
标签: android kotlin fullscreen android-videoview
为您的视频播放器添加全屏按钮: 1-设置清单
<activity android:name=".YourPlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize">
** 这将防止播放器在切换到全屏时重置
2-step 2:在你的 xml 设计中添加一个新的控制器 ** 全屏图像视图
3- 初始化全屏按钮
boolean fullscreen = false;
fullscreenButton = playerView.findViewById(R.id.exo_fullscreen_icon);
fullscreenButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(fullscreen) {
fullscreenButton.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_fullscreen_open));
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
if(getSupportActionBar() != null){
getSupportActionBar().show();
}
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) playerView.getLayoutParams();
params.width = params.MATCH_PARENT;
params.height = (int) ( 200 * getApplicationContext().getResources().getDisplayMetrics().density);
playerView.setLayoutParams(params);
fullscreen = false;
}else{
fullscreenButton.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_fullscreen_close));
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
if(getSupportActionBar() != null){
getSupportActionBar().hide();
}
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) playerView.getLayoutParams();
params.width = params.MATCH_PARENT;
params.height = params.MATCH_PARENT;
playerView.setLayoutParams(params);
fullscreen = true;
}
}
});
【讨论】: