提交 8fc79be1 编写于 作者: S shuyu

1.1.3

上级 4c06ec8c
......@@ -4,13 +4,13 @@
<dependency>
<groupId>com.shuyu</groupId>
<artifactId>gsyVideoPlayer</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
<type>pom</type>
</dependency>
```
```
compile 'com.shuyu:gsyVideoPlayer:1.1.2'
compile 'com.shuyu:gsyVideoPlayer:1.1.3'
```
......@@ -35,6 +35,12 @@ compile 'com.shuyu:gsyVideoPlayer:1.1.2'
* <h4>3、详情模式</h4>
<img src="https://github.com/CarGuo/GSYVideoPlayer/blob/master/04.gif" width="240px" height="426px"/>
## 1.1.3
* 优化了第一种列表的全屏动画,5.0以上展开和返回过渡顺畅,支持自动旋转的开启与关闭
* GIF 效果
<img src="https://github.com/CarGuo/GSYVideoPlayer/blob/master/0034.gif" width="240px" height="426px"/>
## 1.1.2
* 增加了TAG和position来实现第一种list列表(非ListVideoUtil模式的列表实现)的滑动错位问题
......
......@@ -18,7 +18,7 @@ org.gradle.jvmargs=-Xmx1536m
BINTRAY_USER=
BINTRAY_KEY=
PROJ_GROUP=com.shuyu
PROJ_VERSION=1.1.2
PROJ_VERSION=1.1.3
PROJ_NAME=gsyVideo
PROJ_WEBSITEURL=hhttps://github.com/CarGuo/GSYVideoPlayer
PROJ_ISSUETRACKERURL=
......
......@@ -16,7 +16,6 @@ import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
......@@ -27,8 +26,8 @@ import com.danikula.videocache.HttpProxyCacheServer;
import com.shuyu.gsyvideoplayer.listener.GSYMediaPlayerListener;
import com.shuyu.gsyvideoplayer.listener.VideoAllCallBack;
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
import com.shuyu.gsyvideoplayer.video.GSYBaseVideoPlayer;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
......@@ -36,18 +35,15 @@ import java.util.TimerTask;
import tv.danmaku.ijk.media.player.IMediaPlayer;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.hideSupportActionBar;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.showSupportActionBar;
/**
* Created by shuyu on 2016/11/11.
*/
public abstract class GSYVideoPlayer extends FrameLayout implements View.OnClickListener, View.OnTouchListener, SeekBar.OnSeekBarChangeListener, GSYMediaPlayerListener, TextureView.SurfaceTextureListener {
public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.OnClickListener, View.OnTouchListener, SeekBar.OnSeekBarChangeListener, TextureView.SurfaceTextureListener {
public static final String TAG = "GSYVideoPlayer";
public static final int FULLSCREEN_ID = 83797;
protected static final int CURRENT_STATE_NORMAL = 0; //正常
protected static final int CURRENT_STATE_PREPAREING = 1; //准备中
......@@ -67,26 +63,20 @@ public abstract class GSYVideoPlayer extends FrameLayout implements View.OnClick
public static boolean WIFI_TIP_DIALOG_SHOWED = false;
protected static long CLICK_QUIT_FULLSCREEN_TIME = 0;
protected static Timer UPDATE_PROGRESS_TIMER;
private Context mContext;
protected ImageView mStartButton;
protected SeekBar mProgressBar;
protected ImageView mFullscreenButton;
protected TextView mCurrentTimeTextView, mTotalTimeTextView;
protected ViewGroup mTextureViewContainer;
protected ViewGroup mTopContainer, mBottomContainer;
protected GSYTextureView mTextureView;
protected Surface mSurface;
protected ImageView mBackButton;
protected String mUrl;
protected Object[] mObjects;
protected Map<String, String> mMapHeadData = new HashMap<>();
protected ProgressTimerTask mProgressTimerTask;
protected AudioManager mAudioManager; //音频焦点的监听
......@@ -104,8 +94,6 @@ public abstract class GSYVideoPlayer extends FrameLayout implements View.OnClick
protected float mBrightnessData = -1; //亮度
protected int mCurrentState = -1; //当前的播放状态
protected int mDownPosition; //手指放下的位置
protected int mGestureDownVolume; //手势调节音量的大小
......@@ -142,12 +130,6 @@ public abstract class GSYVideoPlayer extends FrameLayout implements View.OnClick
protected boolean mLooping = false;//// TODO: 2016/11/13 循环
protected boolean mCache = false;//是否播边边缓冲
protected boolean mActionBar = false;//是否需要在利用window实现全屏幕的时候隐藏actionbar
protected boolean mStatusBar = false;//是否需要在利用window实现全屏幕的时候隐藏statusbar
/**
* 当前UI
......@@ -869,89 +851,6 @@ public abstract class GSYVideoPlayer extends FrameLayout implements View.OnClick
}
/**
* 利用window层播放全屏效果
*
* @param context
* @param actionBar 是否有actionBar,有的话需要隐藏
* @param statusBar 是否有状态bar,有的话需要隐藏
*/
public void startWindowFullscreen(final Context context, final boolean actionBar, final boolean statusBar) {
this.mActionBar = actionBar;
this.mStatusBar = statusBar;
hideSupportActionBar(context, actionBar, statusBar);
ViewGroup vp = (ViewGroup) (CommonUtil.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT);
View old = vp.findViewById(FULLSCREEN_ID);
if (old != null) {
vp.removeView(old);
}
if (mTextureViewContainer.getChildCount() > 0) {
mTextureViewContainer.removeAllViews();
}
try {
Constructor<GSYVideoPlayer> constructor = (Constructor<GSYVideoPlayer>) GSYVideoPlayer.this.getClass().getConstructor(Context.class);
GSYVideoPlayer gsyVideoPlayer = constructor.newInstance(getContext());
gsyVideoPlayer.setId(FULLSCREEN_ID);
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
int w = wm.getDefaultDisplay().getWidth();
int h = wm.getDefaultDisplay().getHeight();
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(h, w);
lp.setMargins((w - h) / 2, -(w - h) / 2, 0, 0);
vp.addView(gsyVideoPlayer, lp);
gsyVideoPlayer.setUp(mUrl, mCache, mObjects);
gsyVideoPlayer.setStateAndUi(mCurrentState);
gsyVideoPlayer.addTextureView();
gsyVideoPlayer.setRotation(90);
gsyVideoPlayer.getFullscreenButton().setImageResource(R.drawable.video_shrink);
gsyVideoPlayer.getFullscreenButton().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clearFullscreenLayout();
}
});
gsyVideoPlayer.getBackButton().setVisibility(VISIBLE);
gsyVideoPlayer.getBackButton().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clearFullscreenLayout();
}
});
GSYVideoManager.instance().setLastListener(this);
GSYVideoManager.instance().setListener(gsyVideoPlayer);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 退出window层播放全屏效果
*/
public void clearFullscreenLayout() {
showSupportActionBar(mContext, mActionBar, mStatusBar);
ViewGroup vp = (ViewGroup) (CommonUtil.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT);
View oldF = vp.findViewById(FULLSCREEN_ID);
GSYVideoPlayer gsyVideoPlayer = null;
if (oldF != null) {
gsyVideoPlayer = (GSYVideoPlayer) oldF;
vp.removeView(oldF);
}
mCurrentState = GSYVideoManager.instance().getLastState();
if (gsyVideoPlayer != null) {
mCurrentState = gsyVideoPlayer.getCurrentState();
}
GSYVideoManager.instance().setListener(GSYVideoManager.instance().lastListener());
GSYVideoManager.instance().setLastListener(null);
setStateAndUi(mCurrentState);
addTextureView();
CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis();
}
/**
* 滑动改变亮度
*
......@@ -1034,8 +933,11 @@ public abstract class GSYVideoPlayer extends FrameLayout implements View.OnClick
return mPlayPosition;
}
public void setPlayPosition(int playPostion) {
this.mPlayPosition = playPostion;
/**
* 设置播放位置防止错位
*/
public void setPlayPosition(int playPosition) {
this.mPlayPosition = playPosition;
}
/**
......
......@@ -8,6 +8,7 @@ import android.net.NetworkInfo;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.internal.view.ContextThemeWrapper;
import android.util.TypedValue;
import android.view.WindowManager;
import java.util.Formatter;
......@@ -79,6 +80,21 @@ public class CommonUtil {
return result;
}
/**
* 获取ActionBar高度
*
* @param activity activity
* @return ActionBar高度
*/
public static int getActionBarHeight(Activity activity) {
TypedValue tv = new TypedValue();
if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
return TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
}
return 0;
}
public static void hideSupportActionBar(Context context, boolean actionBar, boolean statusBar) {
if (actionBar) {
ActionBar ab = CommonUtil.getAppCompActivity(context).getSupportActionBar();
......
......@@ -7,6 +7,7 @@ import android.view.OrientationEventListener;
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.R;
import com.shuyu.gsyvideoplayer.video.GSYBaseVideoPlayer;
/**
* 处理屏幕旋转的的逻辑
......@@ -16,7 +17,7 @@ import com.shuyu.gsyvideoplayer.R;
public class OrientationUtils {
private Activity activity;
private GSYVideoPlayer gsyVideoPlayer;
private GSYBaseVideoPlayer gsyVideoPlayer;
private int screenType = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
private OrientationEventListener orientationEventListener;
......@@ -28,7 +29,7 @@ public class OrientationUtils {
* @param activity
* @param gsyVideoPlayer
*/
public OrientationUtils(Activity activity, GSYVideoPlayer gsyVideoPlayer) {
public OrientationUtils(Activity activity, GSYBaseVideoPlayer gsyVideoPlayer) {
this.activity = activity;
this.gsyVideoPlayer = gsyVideoPlayer;
init();
......
package com.shuyu.gsyvideoplayer.video;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.transition.TransitionManager;
import android.util.AttributeSet;
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.GSYVideoManager;
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.R;
import com.shuyu.gsyvideoplayer.listener.GSYMediaPlayerListener;
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import java.lang.reflect.Constructor;
import java.util.Map;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.getActionBarHeight;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.getStatusBarHeight;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.hideSupportActionBar;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.showSupportActionBar;
/**
* Created by shuyu on 2016/11/17.
*/
public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMediaPlayerListener {
protected static final int FULLSCREEN_ID = 83797;
protected static long CLICK_QUIT_FULLSCREEN_TIME = 0;
protected boolean mActionBar = false;//是否需要在利用window实现全屏幕的时候隐藏actionbar
protected boolean mStatusBar = false;//是否需要在利用window实现全屏幕的时候隐藏statusbar
protected boolean mCache = false;//是否播边边缓冲
protected int[] mListItemRect;//当前item框的屏幕位置
protected int[] mListItemSize;//当前item的大小
protected int mCurrentState = -1; //当前的播放状态
protected boolean mRotateViewAuto = true; //是否自动旋转
protected Context mContext;
protected String mUrl;
protected Object[] mObjects;
protected ViewGroup mTextureViewContainer;
private OrientationUtils mOrientationUtils;
private Handler mHandler = new Handler();
public GSYBaseVideoPlayer(Context context) {
super(context);
}
public GSYBaseVideoPlayer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GSYBaseVideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
private ViewGroup getViewGroup() {
return (ViewGroup) (CommonUtil.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT);
}
/**
* 移除没用的
*/
private void removeVideo(ViewGroup vp) {
View old = vp.findViewById(FULLSCREEN_ID);
if (old != null) {
if (old.getParent() != null) {
ViewGroup viewGroup = (ViewGroup) old.getParent();
vp.removeView(viewGroup);
}
}
}
/**
* 保存大小和状态
*/
private void saveLocationStatus(Context context, boolean statusBar, boolean actionBar) {
getLocationOnScreen(mListItemRect);
int statusBarH = getStatusBarHeight(context);
int actionBerH = getActionBarHeight((Activity) context);
if (statusBar) {
mListItemRect[1] = mListItemRect[1] - statusBarH;
}
if (actionBar) {
mListItemRect[1] = mListItemRect[1] - actionBerH;
}
mListItemSize[0] = getWidth();
mListItemSize[1] = getHeight();
}
/**
* 全屏
*/
private void resolveFullVideoShow(Context context, GSYBaseVideoPlayer gsyVideoPlayer, int h, int w) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) gsyVideoPlayer.getLayoutParams();
lp.setMargins(0, 0, 0, 0);
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
lp.gravity = Gravity.CENTER;
gsyVideoPlayer.setLayoutParams(lp);
mOrientationUtils = new OrientationUtils((Activity) context, gsyVideoPlayer);
mOrientationUtils.setEnable(mRotateViewAuto);
}
/**
* 恢复
*/
private void resolveNormalVideoShow(View oldF, ViewGroup vp, GSYVideoPlayer gsyVideoPlayer) {
if (oldF.getParent() != null) {
ViewGroup viewGroup = (ViewGroup) oldF.getParent();
vp.removeView(viewGroup);
}
mCurrentState = GSYVideoManager.instance().getLastState();
if (gsyVideoPlayer != null) {
mCurrentState = gsyVideoPlayer.getCurrentState();
}
GSYVideoManager.instance().setListener(GSYVideoManager.instance().lastListener());
GSYVideoManager.instance().setLastListener(null);
setStateAndUi(mCurrentState);
addTextureView();
CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis();
}
/**
* 利用window层播放全屏效果
*
* @param context
* @param actionBar 是否有actionBar,有的话需要隐藏
* @param statusBar 是否有状态bar,有的话需要隐藏
*/
public void startWindowFullscreen(final Context context, final boolean actionBar, final boolean statusBar) {
hideSupportActionBar(context, actionBar, statusBar);
this.mActionBar = actionBar;
this.mStatusBar = statusBar;
mListItemRect = new int[2];
mListItemSize = new int[2];
final ViewGroup vp = getViewGroup();
removeVideo(vp);
if (mTextureViewContainer.getChildCount() > 0) {
mTextureViewContainer.removeAllViews();
}
saveLocationStatus(context, statusBar, actionBar);
try {
Constructor<GSYBaseVideoPlayer> constructor = (Constructor<GSYBaseVideoPlayer>) GSYBaseVideoPlayer.this.getClass().getConstructor(Context.class);
final GSYBaseVideoPlayer gsyVideoPlayer = constructor.newInstance(getContext());
gsyVideoPlayer.setId(FULLSCREEN_ID);
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
final int w = wm.getDefaultDisplay().getWidth();
final int h = wm.getDefaultDisplay().getHeight();
FrameLayout.LayoutParams lpParent = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setBackgroundColor(Color.BLACK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(getWidth(), getHeight());
lp.setMargins(mListItemRect[0], mListItemRect[1], 0, 0);
frameLayout.addView(gsyVideoPlayer, lp);
vp.addView(frameLayout, lpParent);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
TransitionManager.beginDelayedTransition(vp);
resolveFullVideoShow(context, gsyVideoPlayer, h, w);
}
}, 300);
} else {
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(getWidth(), getHeight());
frameLayout.addView(gsyVideoPlayer, lp);
vp.addView(frameLayout, lpParent);
resolveFullVideoShow(context, gsyVideoPlayer, h, w);
}
gsyVideoPlayer.setUp(mUrl, mCache, mObjects);
gsyVideoPlayer.setStateAndUi(mCurrentState);
gsyVideoPlayer.addTextureView();
gsyVideoPlayer.getFullscreenButton().setImageResource(R.drawable.video_shrink);
gsyVideoPlayer.getFullscreenButton().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clearFullscreenLayout();
}
});
gsyVideoPlayer.getBackButton().setVisibility(VISIBLE);
gsyVideoPlayer.getBackButton().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clearFullscreenLayout();
}
});
GSYVideoManager.instance().setLastListener(this);
GSYVideoManager.instance().setListener(gsyVideoPlayer);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 退出window层播放全屏效果
*/
public void clearFullscreenLayout() {
int delay = mOrientationUtils.backToProtVideo();
mOrientationUtils.setEnable(false);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
backToNormal();
}
}, delay);
}
/**
* 回到正常效果
*/
private void backToNormal() {
showSupportActionBar(mContext, mActionBar, mStatusBar);
final ViewGroup vp = getViewGroup();
final View oldF = vp.findViewById(FULLSCREEN_ID);
final GSYVideoPlayer gsyVideoPlayer;
if (oldF != null) {
gsyVideoPlayer = (GSYVideoPlayer) oldF;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
TransitionManager.beginDelayedTransition(vp);
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) gsyVideoPlayer.getLayoutParams();
lp.setMargins(mListItemRect[0], mListItemRect[1], 0, 0);
lp.width = mListItemSize[0];
lp.height = mListItemSize[1];
//注意配置回来,不然动画效果会不对
lp.gravity = Gravity.NO_GRAVITY;
gsyVideoPlayer.setLayoutParams(lp);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
resolveNormalVideoShow(oldF, vp, gsyVideoPlayer);
}
}, 400);
} else {
resolveNormalVideoShow(oldF, vp, gsyVideoPlayer);
}
} else {
resolveNormalVideoShow(null, vp, null);
}
}
/**
* 设置播放URL
*
* @param url
* @param cacheWithPlay 是否边播边缓存
* @param objects
* @return
*/
public abstract boolean setUp(String url, boolean cacheWithPlay, Object... objects);
/**
* 设置播放URL
*
* @param url
* @param cacheWithPlay 是否边播边缓存
* @param mapHeadData
* @param objects
* @return
*/
public abstract boolean setUp(String url, boolean cacheWithPlay, Map<String, String> mapHeadData, Object... objects);
/**
* 设置播放显示状态
*
* @param state
*/
protected abstract void setStateAndUi(int state);
/**
* 添加播放的view
*/
protected abstract void addTextureView();
/**
* 获取全屏按键
*/
public abstract ImageView getFullscreenButton();
/**
* 获取返回按键
*/
public abstract ImageView getBackButton();
public boolean isRotateViewAuto() {
return mRotateViewAuto;
}
/**
* 自动旋转
*/
public void setRotateViewAuto(boolean rotateViewAuto) {
this.mRotateViewAuto = rotateViewAuto;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册