exoplay切换全屏_如何使用exoplayer在横向播放全屏视频

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);

}

}

btw in case you are not using FrameLayout but RelativeLayout

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

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();

}

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.

In LandScape

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

To exit from fullscreen in PORTRAIT

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

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个灵活的视频播放器。 MediaPlayer与VideoView完全分开,可以替换为其他播放器内核,如ExoPlayer和ijkPlayer。 可以完全自定义播放器视图,我们称之为控制面板。 此外,可以使用MediaPlayerManager来控制播放行为,例如全屏模式,小屏幕模式以及RecyclerView中的智能匹配模式。Features全屏,小屏播放内部支持RecyclerView中播放自定义UIAPP内全局播放静音循环播放手势操作(小窗:单指拖动,双指缩放;全屏:音量,亮度,快进)ijkPlayer支持ExoPlayer支持重力感应支持PreviewDownloadDemo DownloadGetting startedbuild.gradledependencies {     // required     implementation 'org.salient.artvideoplayer:artplayer-java:0.6.0'     // Default control panel: optional     implementation 'org.salient.artvideoplayer:artplayer-ui:0.6.0'      //ijkPlayer: optional      implementation 'org.salient.artvideoplayer:artplayer-ijk:0.6.0'      implementation "org.salient.artvideoplayer:artplayer-armv7a:0.6.0"       //Other ABIs: optional      implementation "org.salient.artvideoplayer:artplayer-armv5:0.6.0"      implementation "org.salient.artvideoplayer:artplayer-x86:0.6.0"      // Other ABIs: optional (minSdk version >= 21)      implementation "org.salient.artvideoplayer:artplayer-arm64:0.6.0"      implementation "org.salient.artvideoplayer:artplayer-x86_64:0.6.0"      //ExoPlayer2 : optional      implementation "org.salient.artvideoplayer:artplayer-exo:0.6.0" }Usagejavaimport org.salient.artplayer.VideoView;VideoView videoView = new VideoView(this); videoView.setUp("http://vfx.mtime.cn/Video/2018/06/27/mp4/180627094726195356.mp4"); videoView.setControlPanel(new ControlPanel(this)); videoView.start();xmlAndroidManifest.xml <!-- required -->Activity@Overridepublic void onBackPressed() {  if (MediaPlayerManager.instance().backPress(this)) {      return;   }  super.onBackPressed(); }@Overrideprotected void onPause() {  super.onPause();  MediaPlayerManager.instance().pause(); }@Overrideprotected void onDestroy() {  super.onDestroy();  MediaPlayerMa
SurfaceView播放视频可以通过创建一个新的Activity来实现全屏播放。具体实现可以参考以下步骤: 1. 创建一个新的Activity,例如FullScreenActivity。 2. 在FullScreenActivity中设置布局文件,用来展示视频播放器。可以使用VideoView或者SurfaceView来展示视频。 3. 传递视频播放地址到FullScreenActivity中。可以使用Intent来传递地址。 4. 在FullScreenActivity中启动视频播放器,并且设置全屏标志。 5. 在视频播放完成或者用户退出全屏播放时,关闭FullScreenActivity,回到原来的Activity。 以下是示例代码: 在原来的Activity中,启动FullScreenActivity: ```java Intent intent = new Intent(this, FullScreenActivity.class); intent.putExtra("videoUrl", videoUrl); startActivity(intent); ``` 在FullScreenActivity中,设置布局文件和全屏标志,并且启动视频播放器: ```java public class FullScreenActivity extends AppCompatActivity { private VideoView videoView; private String videoUrl; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_full_screen); // 获取视频播放地址 videoUrl = getIntent().getStringExtra("videoUrl"); // 设置全屏标志 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // 启动视频播放器 videoView = findViewById(R.id.video_view); videoView.setVideoPath(videoUrl); videoView.start(); } @Override public void onBackPressed() { // 关闭FullScreenActivity,回到原来的Activity finish(); } } ``` 在布局文件activity_full_screen.xml中,使用SurfaceView或者VideoView来展示视频: ```xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <VideoView android:id="@+id/video_view" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值