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

优化SmallVideoHelper支持

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