提交 626300f1 编写于 作者: G guoshuyu

优化SmallVideoHelper支持

上级 05548deb
...@@ -144,7 +144,7 @@ compile 'com.shuyu:gsyVideoPlayer-ex_so:3.0.0' ...@@ -144,7 +144,7 @@ compile 'com.shuyu:gsyVideoPlayer-ex_so:3.0.0'
5、DEMO增加SamllVideoHelper实现小窗口逻辑,更新demo 5、DEMO增加SmallVideoHelper实现小窗口,全屏逻辑,更新demo
......
...@@ -59,7 +59,9 @@ public class ListVideo2Activity extends AppCompatActivity { ...@@ -59,7 +59,9 @@ public class ListVideo2Activity extends AppCompatActivity {
//创建小窗口帮助类 //创建小窗口帮助类
smallVideoHelper = new SmallVideoHelper(this); smallVideoHelper = new SmallVideoHelper(this);
smallVideoHelper.setFullViewContainer(videoFullContainer);
//如果不设置即使用默认的 windowViewContainer
//smallVideoHelper.setFullViewContainer(videoFullContainer);
//配置 //配置
gsySmallVideoHelperBuilder = new SmallVideoHelper.GSYSmallVideoHelperBuilder(); gsySmallVideoHelperBuilder = new SmallVideoHelper.GSYSmallVideoHelperBuilder();
......
...@@ -94,7 +94,8 @@ public class ListVideoAdapter extends BaseAdapter { ...@@ -94,7 +94,8 @@ public class ListVideoAdapter extends BaseAdapter {
notifyDataSetChanged(); notifyDataSetChanged();
//listVideoUtil.setLoop(true); //listVideoUtil.setLoop(true);
smallVideoHelper.setPlayPositionAndTag(position, TAG); smallVideoHelper.setPlayPositionAndTag(position, TAG);
final String url = "https://res.exexm.com/cw_145225549855002"; //final String url = "https://res.exexm.com/cw_145225549855002";
final String url = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4";
gsySmallVideoHelperBuilder.setVideoTitle("title " + position) gsySmallVideoHelperBuilder.setVideoTitle("title " + position)
.setUrl(url); .setUrl(url);
smallVideoHelper.startPlay(); smallVideoHelper.startPlay();
......
...@@ -9,6 +9,7 @@ import android.os.Handler; ...@@ -9,6 +9,7 @@ import android.os.Handler;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder; import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
...@@ -51,6 +52,10 @@ public class SmallVideoHelper { ...@@ -51,6 +52,10 @@ public class SmallVideoHelper {
* 全屏承载布局 * 全屏承载布局
*/ */
private ViewGroup fullViewContainer; private ViewGroup fullViewContainer;
/**
* 全屏承载布局
*/
private ViewGroup windowViewContainer;
/** /**
* 记录列表中item的父布局 * 记录列表中item的父布局
*/ */
...@@ -102,13 +107,14 @@ public class SmallVideoHelper { ...@@ -102,13 +107,14 @@ public class SmallVideoHelper {
public SmallVideoHelper(Context context) { public SmallVideoHelper(Context context) {
gsyVideoPlayer = new StandardGSYVideoPlayer(context); this(context, new StandardGSYVideoPlayer(context));
this.context = context;
} }
public SmallVideoHelper(Context context, StandardGSYVideoPlayer player) { public SmallVideoHelper(Context context, StandardGSYVideoPlayer player) {
gsyVideoPlayer = player; gsyVideoPlayer = player;
this.context = context; this.context = context;
this.windowViewContainer = (ViewGroup) (CommonUtil.scanForActivity(context)).findViewById(Window.ID_ANDROID_CONTENT);
} }
/** /**
...@@ -156,11 +162,17 @@ public class SmallVideoHelper { ...@@ -156,11 +162,17 @@ public class SmallVideoHelper {
* 添加到全屏父布局里 * 添加到全屏父布局里
*/ */
private void resolveFullAdd() { private void resolveFullAdd() {
if(gsyVideoOptionBuilder.isShowFullAnimation()) { if (gsyVideoOptionBuilder.isShowFullAnimation()) {
fullViewContainer.setBackgroundColor(Color.BLACK); if (fullViewContainer != null) {
fullViewContainer.setBackgroundColor(Color.BLACK);
}
} }
resolveChangeFirstLogic(0); resolveChangeFirstLogic(0);
fullViewContainer.addView(gsyVideoPlayer); if (fullViewContainer != null) {
fullViewContainer.addView(gsyVideoPlayer);
} else {
windowViewContainer.addView(gsyVideoPlayer);
}
} }
/** /**
...@@ -176,12 +188,20 @@ public class SmallVideoHelper { ...@@ -176,12 +188,20 @@ public class SmallVideoHelper {
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(listItemSize[0], listItemSize[1]); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(listItemSize[0], listItemSize[1]);
lp.setMargins(listItemRect[0], listItemRect[1], 0, 0); lp.setMargins(listItemRect[0], listItemRect[1], 0, 0);
frameLayout.addView(gsyVideoPlayer, lp); frameLayout.addView(gsyVideoPlayer, lp);
fullViewContainer.addView(frameLayout, lpParent); if (fullViewContainer != null) {
fullViewContainer.addView(frameLayout, lpParent);
} else {
windowViewContainer.addView(frameLayout, lpParent);
}
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
//开始动画 //开始动画
TransitionManager.beginDelayedTransition(fullViewContainer); if (fullViewContainer != null) {
TransitionManager.beginDelayedTransition(fullViewContainer);
} else {
TransitionManager.beginDelayedTransition(windowViewContainer);
}
resolveMaterialFullVideoShow(gsyVideoPlayer); resolveMaterialFullVideoShow(gsyVideoPlayer);
resolveChangeFirstLogic(600); resolveChangeFirstLogic(600);
} }
...@@ -207,20 +227,25 @@ public class SmallVideoHelper { ...@@ -207,20 +227,25 @@ public class SmallVideoHelper {
*/ */
private void resolveToNormal() { private void resolveToNormal() {
int delay = orientationUtils.backToProtVideo(); int delay = orientationUtils.backToProtVideo();
if(!gsyVideoOptionBuilder.isShowFullAnimation()) { if (!gsyVideoOptionBuilder.isShowFullAnimation()) {
delay = 0; delay = 0;
} }
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
isFull = false; isFull = false;
fullViewContainer.removeAllViews(); removeWindowContainer();
if (fullViewContainer != null) {
fullViewContainer.removeAllViews();
}
if (gsyVideoPlayer.getParent() != null) { if (gsyVideoPlayer.getParent() != null) {
((ViewGroup) gsyVideoPlayer.getParent()).removeView(gsyVideoPlayer); ((ViewGroup) gsyVideoPlayer.getParent()).removeView(gsyVideoPlayer);
} }
orientationUtils.setEnable(false); orientationUtils.setEnable(false);
gsyVideoPlayer.setIfCurrentIsFullscreen(false); gsyVideoPlayer.setIfCurrentIsFullscreen(false);
fullViewContainer.setBackgroundColor(Color.TRANSPARENT); if (fullViewContainer != null) {
fullViewContainer.setBackgroundColor(Color.TRANSPARENT);
}
listParent.addView(gsyVideoPlayer, listParams); listParent.addView(gsyVideoPlayer, listParams);
gsyVideoPlayer.getFullscreenButton().setImageResource(gsyVideoPlayer.getEnlargeImageRes()); gsyVideoPlayer.getFullscreenButton().setImageResource(gsyVideoPlayer.getEnlargeImageRes());
gsyVideoPlayer.getBackButton().setVisibility(View.GONE); gsyVideoPlayer.getBackButton().setVisibility(View.GONE);
...@@ -274,15 +299,26 @@ public class SmallVideoHelper { ...@@ -274,15 +299,26 @@ public class SmallVideoHelper {
*/ */
private void resolveChangeFirstLogic(int time) { private void resolveChangeFirstLogic(int time) {
if (gsyVideoOptionBuilder.isLockLand()) { if (gsyVideoOptionBuilder.isLockLand()) {
handler.postDelayed(new Runnable() { if (time > 0) {
@Override handler.postDelayed(new Runnable() {
public void run() { @Override
if (orientationUtils.getIsLand() != 1) { public void run() {
if (orientationUtils.getIsLand() != 1) {
if (fullViewContainer != null) {
fullViewContainer.setBackgroundColor(Color.BLACK);
}
orientationUtils.resolveByClick();
}
}
}, time);
} else {
if (orientationUtils.getIsLand() != 1) {
if (fullViewContainer != null) {
fullViewContainer.setBackgroundColor(Color.BLACK); fullViewContainer.setBackgroundColor(Color.BLACK);
orientationUtils.resolveByClick();
} }
orientationUtils.resolveByClick();
} }
}, time); }
} }
gsyVideoPlayer.setIfCurrentIsFullscreen(true); gsyVideoPlayer.setIfCurrentIsFullscreen(true);
if (gsyVideoOptionBuilder.getVideoAllCallBack() != null) { if (gsyVideoOptionBuilder.getVideoAllCallBack() != null) {
...@@ -320,6 +356,14 @@ public class SmallVideoHelper { ...@@ -320,6 +356,14 @@ public class SmallVideoHelper {
return isPlayView(position, tag); return isPlayView(position, tag);
} }
private boolean removeWindowContainer() {
if (windowViewContainer != null && windowViewContainer.indexOfChild(gsyVideoPlayer) != -1) {
windowViewContainer.removeView(gsyVideoPlayer);
return true;
}
return false;
}
/** /**
* 动态添加视频播放 * 动态添加视频播放
* *
...@@ -402,9 +446,6 @@ public class SmallVideoHelper { ...@@ -402,9 +446,6 @@ public class SmallVideoHelper {
* 全屏按键逻辑 * 全屏按键逻辑
*/ */
public void doFullBtnLogic() { public void doFullBtnLogic() {
if (fullViewContainer == null) {
return;
}
if (!isFull) { if (!isFull) {
resolveToFull(); resolveToFull();
} else { } else {
...@@ -421,6 +462,9 @@ public class SmallVideoHelper { ...@@ -421,6 +462,9 @@ public class SmallVideoHelper {
if (fullViewContainer != null && fullViewContainer.getChildCount() > 0) { if (fullViewContainer != null && fullViewContainer.getChildCount() > 0) {
isFull = true; isFull = true;
resolveMaterialToNormal(gsyVideoPlayer); resolveMaterialToNormal(gsyVideoPlayer);
} else if (windowViewContainer != null && windowViewContainer.indexOfChild(gsyVideoPlayer) != -1) {
isFull = true;
resolveMaterialToNormal(gsyVideoPlayer);
} }
return isFull; return isFull;
} }
...@@ -429,6 +473,7 @@ public class SmallVideoHelper { ...@@ -429,6 +473,7 @@ public class SmallVideoHelper {
* 释放持有的视频 * 释放持有的视频
*/ */
public void releaseVideoPlayer() { public void releaseVideoPlayer() {
removeWindowContainer();
ViewGroup viewGroup = (ViewGroup) gsyVideoPlayer.getParent(); ViewGroup viewGroup = (ViewGroup) gsyVideoPlayer.getParent();
if (viewGroup != null) if (viewGroup != null)
viewGroup.removeAllViews(); viewGroup.removeAllViews();
...@@ -465,6 +510,7 @@ public class SmallVideoHelper { ...@@ -465,6 +510,7 @@ public class SmallVideoHelper {
/** /**
* 设置全屏显示的viewGroup * 设置全屏显示的viewGroup
* 如果不设置即使用默认的 windowViewContainer
* *
* @param fullViewContainer viewGroup * @param fullViewContainer viewGroup
*/ */
......
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
android:layout_width="240dp" android:layout_width="240dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:text="List小窗口列表" /> android:text="List全屏和小窗口列表" />
<Button <Button
android:id="@+id/recycler" android:id="@+id/recycler"
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
android:layout_width="240dp" android:layout_width="240dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:text="recycler小窗口列表" /> android:text="recycler全屏和小窗口列表" />
<Button <Button
android:id="@+id/list_detail" android:id="@+id/list_detail"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册