diff --git a/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java b/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java index b0d2ac354..3eff44af7 100644 --- a/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java +++ b/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java @@ -2,6 +2,7 @@ package com.yunbao.common.views.weight; import android.app.Activity; import android.os.Bundle; +import android.os.Handler; import android.util.Log; import android.view.Gravity; import android.view.View; @@ -13,11 +14,14 @@ import com.lzf.easyfloat.enums.ShowPattern; import com.lzf.easyfloat.interfaces.FloatCallbacks; import com.lzf.easyfloat.interfaces.OnInvokeView; import com.tencent.live2.V2TXLivePlayer; +import com.tencent.live2.V2TXLivePlayerObserver; import com.tencent.live2.impl.V2TXLivePlayerImpl; import com.tencent.rtmp.ui.TXCloudVideoView; import com.yunbao.common.R; import com.yunbao.common.bean.LiveBean; import com.yunbao.common.dialog.HintDialog; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.views.floatingview.APPEasyFloat; @@ -66,6 +70,20 @@ public class LiveFloatView implements Function1 { mPlayer = new V2TXLivePlayerImpl(mContext); mPlayer.setRenderView(videoView); mPlayer.startPlay(url); + mPlayer.setObserver(new V2TXLivePlayerObserver() { + @Override + public void onWarning(V2TXLivePlayer player, int code, String msg, Bundle extraInfo) { + super.onWarning(player, code, msg, extraInfo); + Log.e(TAG, msg + "==============" + code); + } + + @Override + public void onError(V2TXLivePlayer player, int code, String msg, Bundle extraInfo) { + super.onError(player, code, msg, extraInfo); + Log.e(TAG, msg + "==============" + code); + + } + }); ViewClicksAntiShake.clicksAntiShake(magnetView.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { @@ -81,14 +99,10 @@ public class LiveFloatView implements Function1 { } }); ViewClicksAntiShake.clicksAntiShake(videoView, () -> { - if (mPlayer != null && mPlayer.isPlaying() == 1) { - mPlayer.stopPlay(); - APPEasyFloat.getInstance().dismiss(mContext); - } else if (mPlayer != null) { - mPlayer.stopPlay(); - APPEasyFloat.getInstance().dismiss(mContext); - RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal); - } + mPlayer.stopPlay(); + APPEasyFloat.getInstance().dismiss(mContext); + new Handler().post(liveCheck); + }); } @@ -168,6 +182,7 @@ public class LiveFloatView implements Function1 { mPlayer = new V2TXLivePlayerImpl(mContext); mPlayer.setRenderView(videoView); mPlayer.startPlay(url); + ViewClicksAntiShake.clicksAntiShake(view.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { @@ -183,13 +198,10 @@ public class LiveFloatView implements Function1 { } }); ViewClicksAntiShake.clicksAntiShake(videoView, () -> { - if (mPlayer != null && mPlayer.isPlaying() == 1) { - mPlayer.stopPlay(); - EasyFloat.dismiss("LiveFloatView", true); - } else if (mPlayer != null) { - mPlayer.stopPlay(); - RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal); - } + + mPlayer.stopPlay(); + new Handler().post(liveCheck); + }); } @@ -207,4 +219,30 @@ public class LiveFloatView implements Function1 { } + private Runnable liveCheck = new Runnable() { + @Override + public void run() { + HttpClient.getInstance().get("Live.checkLive", "") + .params("liveuid", mLiveBean.getUid()) + .params("stream", mLiveBean.getStream()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + + RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal); + + } else { + //判断是否有直播悬浮窗,有直接关闭 + if (EasyFloat.isShow("LiveFloatView")) { + EasyFloat.dismiss("LiveFloatView", true); + } else { + APPEasyFloat.getInstance().dismiss(mContext); + } + } + } + }); + } + }; + }