package com.example.gsyvideoplayer.switchplay; import android.app.Activity; import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityOptionsCompat; import androidx.core.view.ViewCompat; import androidx.appcompat.app.AppCompatActivity; import android.view.View; import com.example.gsyvideoplayer.R; import com.shuyu.gsyvideoplayer.GSYVideoManager; import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack; import com.shuyu.gsyvideoplayer.utils.OrientationUtils; /** * 切换详情 */ public class SwitchDetailActivity extends AppCompatActivity { public static final String URL = "url"; private static final String OPTION_VIEW = "view"; SwitchVideo detailPlayer; private boolean isPlay = true; private boolean isPause; private OrientationUtils orientationUtils; public static void startTActivity(Activity activity, View transitionView) { Intent intent = new Intent(activity, SwitchDetailActivity.class); // 这里指定了共享的视图元素 ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, transitionView, OPTION_VIEW); ActivityCompat.startActivity(activity, intent, options.toBundle()); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.switch_activity_detail_player); detailPlayer = (SwitchVideo) findViewById(R.id.detail_player); //增加title detailPlayer.getTitleTextView().setVisibility(View.GONE); detailPlayer.getBackButton().setVisibility(View.GONE); //外部辅助的旋转,帮助全屏 orientationUtils = new OrientationUtils(this, detailPlayer); //初始化不打开外部的旋转 orientationUtils.setEnable(false); SwitchUtil.optionPlayer(detailPlayer, getIntent().getStringExtra(URL), true, "这是title"); SwitchUtil.clonePlayState(detailPlayer); detailPlayer.setIsTouchWiget(true); detailPlayer.setVideoAllCallBack(new GSYSampleCallBack() { @Override public void onPrepared(String url, Object... objects) { super.onPrepared(url, objects); //开始播放了才能旋转和全屏 orientationUtils.setEnable(true); } @Override public void onQuitFullscreen(String url, Object... objects) { super.onQuitFullscreen(url, objects); if (orientationUtils != null) { orientationUtils.backToProtVideo(); } } }); detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //直接横屏 orientationUtils.resolveByClick(); //第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar detailPlayer.startWindowFullscreen(SwitchDetailActivity.this, true, true); } }); detailPlayer.setSurfaceToPlay(); // 这里指定了被共享的视图元素 ViewCompat.setTransitionName(detailPlayer, OPTION_VIEW); } @Override public void onBackPressed() { if (orientationUtils != null) { orientationUtils.backToProtVideo(); } if (GSYVideoManager.backFromWindowFull(this)) { return; } super.onBackPressed(); } @Override protected void onPause() { detailPlayer.getCurrentPlayer().onVideoPause(); super.onPause(); isPause = true; } @Override protected void onResume() { detailPlayer.getCurrentPlayer().onVideoResume(false); super.onResume(); isPause = false; } @Override protected void onDestroy() { super.onDestroy(); detailPlayer.getGSYVideoManager().setListener(detailPlayer.getGSYVideoManager().lastListener()); detailPlayer.getGSYVideoManager().setLastListener(null); GSYVideoManager.releaseAllVideos(); if (orientationUtils != null) orientationUtils.releaseListener(); SwitchUtil.release(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); //如果旋转了就全屏 if (isPlay && !isPause) { detailPlayer.onConfigurationChanged(this, newConfig, orientationUtils, true, true); } } }