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

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

问题描述

我正在使用 exoplayer 在我的 android 应用程序中播放来自 url 的视频.在纵向中,一切都按预期工作(在活动中使用 viewpager、fragments 和 tabs).我的目标是在用户处于横向时全屏播放视频.这意味着只有视频会横向播放,所有其他细节都会消失并在纵向时恢复到原始布局.我怎样才能做到这一点?或者实现这一目标的最佳方法是什么?任何示例代码将不胜感激.

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.

推荐答案

我是菜鸟,所以这是我能提供的最好的帮助应用了这段代码,效果很好.

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.

在景观中

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 以防止用户单击视频中的控制按钮时显示状态栏.

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天全站免登陆