提交 18d2a091 编写于 作者: S shuyu

1.3.7 优化了暂停的时候全屏/恢复全屏会是黑色的问题

上级 3b17371f
......@@ -15,6 +15,8 @@
## [简书详解入口](http://www.jianshu.com/p/9fe377dd9750)
## 下方个版本说明,可以当做简单的wiki使用~。
```
<dependency>
<groupId>com.shuyu</groupId>
......
......@@ -77,10 +77,10 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
protected ImageView mFullscreenButton;
protected TextView mCurrentTimeTextView, mTotalTimeTextView;
protected ViewGroup mTopContainer, mBottomContainer;
protected GSYTextureView mTextureView;
protected Surface mSurface;
protected ImageView mBackButton;
protected ProgressTimerTask mProgressTimerTask;
protected AudioManager mAudioManager; //音频焦点的监听
......@@ -160,6 +160,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
mStartButton = findViewById(R.id.start);
mSmallClose = findViewById(R.id.small_close);
mBackButton = (ImageView) findViewById(R.id.back);
mCoverImageView = (ImageView) findViewById(R.id.cover);
mFullscreenButton = (ImageView) findViewById(R.id.fullscreen);
mProgressBar = (SeekBar) findViewById(R.id.progress);
mCurrentTimeTextView = (TextView) findViewById(R.id.current);
......@@ -489,6 +490,8 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
mSurface = new Surface(surface);
GSYVideoManager.instance().setDisplay(mSurface);
//显示暂停切换显示的图片
showPauseCover();
}
@Override
......@@ -506,7 +509,8 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
//如果播放的是暂停全屏了
releasePauseCover();
}
/**
......@@ -638,6 +642,36 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
return false;
}
/**
* 显示暂停切换显示的bitmap
*/
protected void showPauseCover() {
try {
if (mCurrentState == CURRENT_STATE_PAUSE && mFullPauseBitmap != null
&& !mFullPauseBitmap.isRecycled()) {
mCoverImageView.setImageBitmap(mFullPauseBitmap);
mCoverImageView.setVisibility(VISIBLE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 销毁暂停切换显示的bitmap
*/
protected void releasePauseCover() {
try {
if (mCurrentState != CURRENT_STATE_PAUSE && mFullPauseBitmap != null
&& !mFullPauseBitmap.isRecycled()) {
mCoverImageView.setImageResource(R.drawable.empty_drawable);
mCoverImageView.setVisibility(GONE);
mFullPauseBitmap = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
protected void showProgressDialog(float deltaX,
String seekTime, int seekTimePosition,
......
......@@ -2,6 +2,7 @@ package com.shuyu.gsyvideoplayer.video;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Handler;
......@@ -10,10 +11,10 @@ import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.shuyu.gsyvideoplayer.GSYTextureView;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.R;
......@@ -65,6 +66,8 @@ public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMedia
protected int mCurrentState = -1; //当前的播放状态
private int mSystemUiVisibility;
protected float mSpeed = 1;//播放速度,只支持6.0以上
protected boolean mRotateViewAuto = true; //是否自动旋转
......@@ -93,13 +96,18 @@ public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMedia
protected VideoAllCallBack mVideoAllCallBack;
private OrientationUtils mOrientationUtils; //旋转工具类
protected Map<String, String> mMapHeadData = new HashMap<>();
private Handler mHandler = new Handler();
protected GSYTextureView mTextureView;
private int mSystemUiVisibility;
protected ImageView mCoverImageView; //内部使用,请勿操作哟~
protected Bitmap mFullPauseBitmap = null;//暂停时的全屏图片;
private OrientationUtils mOrientationUtils; //旋转工具类
private Handler mHandler = new Handler();
public GSYBaseVideoPlayer(Context context) {
......@@ -186,6 +194,7 @@ public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMedia
* 恢复
*/
private void resolveNormalVideoShow(View oldF, ViewGroup vp, GSYVideoPlayer gsyVideoPlayer) {
if (oldF != null && oldF.getParent() != null) {
ViewGroup viewGroup = (ViewGroup) oldF.getParent();
vp.removeView(viewGroup);
......@@ -238,6 +247,9 @@ public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMedia
removeVideo(vp, FULLSCREEN_ID);
//处理暂停的逻辑
pauseFullCoverLogic();
if (mTextureViewContainer.getChildCount() > 0) {
mTextureViewContainer.removeAllViews();
}
......@@ -277,6 +289,7 @@ public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMedia
resolveFullVideoShow(context, gsyVideoPlayer);
}
gsyVideoPlayer.mHadPlay = mHadPlay;
gsyVideoPlayer.mFullPauseBitmap = mFullPauseBitmap;
gsyVideoPlayer.setUp(mUrl, mCache, mCachePath, mMapHeadData, mObjects);
gsyVideoPlayer.setStateAndUi(mCurrentState);
gsyVideoPlayer.addTextureView();
......@@ -336,6 +349,8 @@ public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMedia
final GSYVideoPlayer gsyVideoPlayer;
if (oldF != null) {
gsyVideoPlayer = (GSYVideoPlayer) oldF;
//如果暂停了
pauseFullBackCoverLogic(gsyVideoPlayer);
if (mShowFullAnimation) {
TransitionManager.beginDelayedTransition(vp);
......@@ -362,6 +377,35 @@ public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMedia
}
}
/**
* 全屏的暂停的时候返回页面不黑色
*/
private void pauseFullCoverLogic() {
if (mCurrentState == GSYVideoPlayer.CURRENT_STATE_PAUSE && mTextureView != null
&& (mFullPauseBitmap == null || mFullPauseBitmap.isRecycled())) {
mFullPauseBitmap = mTextureView.getBitmap();
}
}
/**
* 全屏的暂停返回的时候返回页面不黑色
*/
private void pauseFullBackCoverLogic(GSYBaseVideoPlayer gsyVideoPlayer) {
//如果是暂停状态
if (gsyVideoPlayer.mCurrentState == GSYVideoPlayer.CURRENT_STATE_PAUSE
&& gsyVideoPlayer.mTextureView != null) {
//全屏的位图还在,说明没播放,直接用原来的
if (gsyVideoPlayer.mFullPauseBitmap != null
&& !gsyVideoPlayer.mFullPauseBitmap.isRecycled()) {
mFullPauseBitmap = gsyVideoPlayer.mFullPauseBitmap;
} else {
//不在了说明已经播放过,还是暂停的话,我们拿回来就好
mFullPauseBitmap = gsyVideoPlayer.mTextureView.getBitmap();
}
}
}
/**
* 显示小窗口
*/
......
......@@ -57,8 +57,6 @@ public class StandardGSYVideoPlayer extends GSYVideoPlayer {
protected RelativeLayout mThumbImageViewLayout;//封面父布局
protected ImageView mCoverImageView; //未使用
private View mThumbImageView; //封面
protected Dialog mBrightnessDialog;
......@@ -110,7 +108,7 @@ public class StandardGSYVideoPlayer extends GSYVideoPlayer {
mBottomProgressBar = (ProgressBar) findViewById(R.id.bottom_progressbar);
mTitleTextView = (TextView) findViewById(R.id.title);
mThumbImageViewLayout = (RelativeLayout) findViewById(R.id.thumb);
mCoverImageView = (ImageView) findViewById(R.id.cover);
mLoadingProgressBar = (ENDownloadView) findViewById(R.id.loading);
mThumbImageViewLayout.setVisibility(GONE);
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="#00000000"
android:startColor="#00000000"/>
</shape>
\ No newline at end of file
......@@ -21,8 +21,7 @@
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#222222" />
android:layout_alignParentTop="true" />
<RelativeLayout
android:id="@+id/thumb"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册