如何使用exoplayer在横向播放全屏视频 [英] How to play video full screen in landscape using exoplayer

查看:1847
本文介绍了如何使用exoplayer在横向播放全屏视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用exoplayer从我的android应用中的url播放视频.在纵向模式下,一切都按预期工作(在活动中使用viewpager,片段和选项卡). 我的目标是当用户处于横向时以全屏播放视频.这意味着只有视频将在横向播放,而其他所有细节将消失,并在纵向显示时恢复为原始布局. 请问我该如何实现?或实现此目标的最佳方法是什么?任何示例代码将不胜感激.

I am using exoplayer to play video from url in my android app. In portrait everything work as expected (using viewpager, fragments and tabs inside activity). My goal is to play the video in full screen when the user is in landscape. It means only the video will play in landscape and all other details will desapear and return back to the original layout when portrait. How can I achieve this please? or what is the best way to achieve this? any sample code will be appreciate.

推荐答案

我是菜鸟,所以这是我能提供的最好的帮助,顺便说一句,我在Exoplayer Demo应用程序中对此进行了测试,将exoplayer的高度更改为600px,应用了此代码,效果很好.

i am a noob so this is the best i can help with, btw I tested this in the Exoplayer Demo application, i changed the exoplayer height to 600px and i applied this code and it worked perfectly.

添加此代码以检测屏幕方向

add this Code to detect screen orientation

  @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

btw in case you are not using FrameLayout but RelativeLayout

      RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) simpleExoPlayerView.getLayoutParams();

我忘记了您需要隐藏操作或标题栏,希望该代码有帮助,将这些代码添加到上面的代码中,我还认为您需要将活动扩展到AppCompatActivity才能使getSupportActionBar代码正常工作.

I forgot that you need to hide the action or title bar, hope this code helps, add these codes inside the code above, also i think you will need to extend your activity to AppCompatActivity for getSupportActionBar code to work.

if(getSupportActionBar()!=null) {
   getSupportActionBar().hide();
}
//To show the action bar
if(getSupportActionBar()!=null) {
   getSupportActionBar().show();
 }

这也可能有助于将整个项目设置为全屏显示,以隐藏状态栏等.必须根据屏幕方向将其添加到onConfigurationChanged中.

also this may help to set the whole project in full screen, to hide status bar.etc, must be added inside onConfigurationChanged based on screen orientation.

在LandScape中

In LandScape

ExoPlayerActivity.this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN || View.SYSTEM_UI_FLAG_IMMERSIVE);

要从全屏退出PORTRAIT

To exit from fullscreen in PORTRAIT

ExoPlayerActivity.this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

我编辑了代码,添加了View.SYSTEM_UI_FLAG_IMMERSIVE,以防止当用户单击视频中的控制按钮时显示状态栏.

I edited the code, I added View.SYSTEM_UI_FLAG_IMMERSIVE to prevent status bar from showing when user click on the control button in the video.

这篇关于如何使用exoplayer在横向播放全屏视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆