package com.example.gsyvideoplayer.simple; import android.content.res.Configuration; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; import com.example.gsyvideoplayer.R; import com.shuyu.gsyvideoplayer.GSYVideoManager; import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder; import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack; import com.shuyu.gsyvideoplayer.listener.LockClickListener; import com.shuyu.gsyvideoplayer.utils.OrientationUtils; import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer; /** * 简单详情实现模式2 */ public class SimpleDetailActivityMode2 extends AppCompatActivity { StandardGSYVideoPlayer detailPlayer; private boolean isPlay; private boolean isPause; private OrientationUtils orientationUtils; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_simple_detail_player); detailPlayer = (StandardGSYVideoPlayer) findViewById(R.id.detail_player); String url = "http://wdquan-space.b0.upaiyun.com/VIDEO/2018/11/22/ae0645396048_hls_time10.m3u8"; //增加封面 ImageView imageView = new ImageView(this); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setImageResource(R.mipmap.xxx1); //增加title detailPlayer.getTitleTextView().setVisibility(View.GONE); detailPlayer.getBackButton().setVisibility(View.GONE); //外部辅助的旋转,帮助全屏 orientationUtils = new OrientationUtils(this, detailPlayer); //初始化不打开外部的旋转 orientationUtils.setEnable(false); GSYVideoOptionBuilder gsyVideoOption = new GSYVideoOptionBuilder(); gsyVideoOption.setThumbImageView(imageView) .setIsTouchWiget(true) .setRotateViewAuto(false) .setLockLand(false) .setAutoFullWithSize(true) .setShowFullAnimation(false) .setNeedLockFull(true) .setUrl(url) .setCacheWithPlay(false) .setVideoTitle("测试视频") .setVideoAllCallBack(new GSYSampleCallBack() { @Override public void onPrepared(String url, Object... objects) { super.onPrepared(url, objects); //开始播放了才能旋转和全屏 orientationUtils.setEnable(true); isPlay = true; } @Override public void onQuitFullscreen(String url, Object... objects) { super.onQuitFullscreen(url, objects); if (orientationUtils != null) { orientationUtils.backToProtVideo(); } } }).setLockClickListener(new LockClickListener() { @Override public void onClick(View view, boolean lock) { if (orientationUtils != null) { //配合下方的onConfigurationChanged orientationUtils.setEnable(!lock); } } }).build(detailPlayer); detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //直接横屏 orientationUtils.resolveByClick(); //第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar detailPlayer.startWindowFullscreen(SimpleDetailActivityMode2.this, true, true); } }); } @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(); if (isPlay) { detailPlayer.getCurrentPlayer().release(); } if (orientationUtils != null) orientationUtils.releaseListener(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); //如果旋转了就全屏 if (isPlay && !isPause) { detailPlayer.onConfigurationChanged(this, newConfig, orientationUtils, true, true); } } }