我正在使用exoplayer从我的android应用程序中的url播放视频。在画像中,一切都像预期的那样工作(在activity中使用viewpager、片段和标签)。我的目标是当用户处于场景中时,全屏播放视频。这意味着只有视频将在横向播放,所有其他细节将取消消失,并返回到肖像时的原始布局。我怎样才能做到这一点呢?或者,实现这一目标的最好方法是什么?任何示例代码都将受到欢迎。

发布于 2017-10-14 03:31:14
我是一个新手,所以这是我能提供的最好的帮助,顺便说一句,我在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();
}此外,这可能有助于将整个项目设置为全屏,以隐藏状态bar.etc,必须根据屏幕方向添加到onConfigurationChanged内部。
在LandScape中
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,以防止当用户单击视频中的控制按钮时状态栏显示。
发布于 2018-05-10 17:35:04
您可以在设置播放器时检查方向,并相应地设置参数:
if (getActivity().getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE) {
params = (LinearLayout.LayoutParams)
exoPlayerView.getLayoutParams();
params.width = params.MATCH_PARENT;
params.height = params.MATCH_PARENT;
exoPlayerView.setLayoutParams(params);
}并隐藏操作栏:
((AppCompatActivity) getActivity()).getSupportActionBar().hide();发布于 2018-07-07 05:49:55
对于有硬件按钮的屏幕,如果没有其他视图与ExoPlayer的PlayerView共享屏幕,则默认会填满整个屏幕。然而,对于屏幕上有虚拟按钮的设备,它不会充满整个屏幕。在我的例子中,通过将这一行添加到PlayerView来修复问题。
ads:resize_mode="fill"因为我在activity布局中有admob广告,所以我在顶部的RelativeLayout标记中添加了这一行。
xmlns:ads="http://schemas.android.com/apk/res-auto"我知道这没有意义,但是使用android:resize_mode="fill"会给你gradle构建错误。
此外,您还可以删除系统UI以获得更多空间:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
hideSystemUI();
}
}
private void hideSystemUI() {
// Enables "lean back" mode
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
// Hide the nav bar and status bar
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}欲了解更多信息,请访问安卓开发者页面https://developer.android.com/training/system-ui/immersive
https://stackoverflow.com/questions/46713761
复制相似问题