add[声望升级-修复BUG]
This commit is contained in:
@@ -0,0 +1,354 @@
|
||||
package io.agora.beautyapi.faceunity.agora;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.lzf.easyfloat.EasyFloat;
|
||||
import com.lzf.easyfloat.enums.ShowPattern;
|
||||
import com.lzf.easyfloat.interfaces.FloatCallbacks;
|
||||
import com.lzf.easyfloat.interfaces.OnInvokeView;
|
||||
import com.tencent.rtmp.ITXLivePlayListener;
|
||||
import com.tencent.rtmp.TXLivePlayer;
|
||||
import com.tencent.rtmp.ui.TXCloudVideoView;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.Constants;
|
||||
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.DpUtil;
|
||||
import com.yunbao.common.utils.L;
|
||||
import com.yunbao.common.utils.RouteUtil;
|
||||
import com.yunbao.common.views.floatingview.APPEasyFloat;
|
||||
import com.yunbao.common.views.floatingview.FloatingMagnetView;
|
||||
import com.yunbao.common.views.floatingview.MagnetViewListener;
|
||||
import com.yunbao.common.views.weight.ViewClicksAntiShake;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
|
||||
/**
|
||||
* 直播间悬浮窗管理
|
||||
*/
|
||||
public class LiveFloatView implements Function1<FloatCallbacks.Builder, Unit> {
|
||||
|
||||
private static LiveFloatView instance;
|
||||
private LiveOnInvokeView liveOnInvokeView = null;
|
||||
private Activity mContext;
|
||||
private String url;
|
||||
private LiveBean mLiveBean;
|
||||
private int mLiveType;
|
||||
private int mLiveSDK;
|
||||
private int mLiveTypeVal;
|
||||
private FloatCallbacks.Builder builder;
|
||||
private String TAG = "LiveFloatView";
|
||||
private TXLivePlayer mPlayer;
|
||||
private FrameLayout videoFrameLayout;
|
||||
private TXCloudVideoView videoView;
|
||||
private SWAuManager swAuManager;
|
||||
|
||||
public static LiveFloatView getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new LiveFloatView();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void builderFloat(Activity mContext, String url, Class<?> back) {
|
||||
this.mContext = mContext;
|
||||
this.url = url;
|
||||
if (TextUtils.isEmpty(url)) return;
|
||||
APPEasyFloat.getInstance().layout(R.layout.view_flaot_live)
|
||||
.dragEnable(true)
|
||||
.setAutoMoveToEdge(true)
|
||||
.black(back)
|
||||
.setMagnetViewListener(new MagnetViewListener() {
|
||||
@Override
|
||||
public void invoke(FloatingMagnetView magnetView) {
|
||||
CardView layout = magnetView.findViewById(R.id.layout);
|
||||
RelativeLayout.LayoutParams cardParams = (RelativeLayout.LayoutParams) layout.getLayoutParams();
|
||||
if (mLiveBean.getLandscape() == 1) {
|
||||
cardParams.height = DpUtil.dp2px(190);
|
||||
cardParams.width = DpUtil.dp2px(255);
|
||||
} else {
|
||||
cardParams.height = DpUtil.dp2px(224);
|
||||
cardParams.width = DpUtil.dp2px(126);
|
||||
}
|
||||
if(mLiveSDK == Constants.LIVE_SDK_SW){
|
||||
L.eSw("mLiveSDK == Constants.LIVE_S2222222222222222");
|
||||
videoFrameLayout = magnetView.findViewById(R.id.videoFrameLayout);
|
||||
swAuManager = SWAuManager.get();
|
||||
swAuManager.setAudienceContainer(videoFrameLayout);
|
||||
swAuManager.initRtcEngine( mContext);
|
||||
swAuManager.setupRemoteVideo(Integer.parseInt(mLiveBean.getUid()));
|
||||
//进入主播房间
|
||||
swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(mLiveBean.getUid()));
|
||||
}else{
|
||||
videoView = magnetView.findViewById(R.id.video_view);
|
||||
mPlayer = new TXLivePlayer(mContext);
|
||||
mPlayer.setPlayerView(videoView);
|
||||
mPlayer.startPlay(url, TXLivePlayer.PLAY_TYPE_LIVE_FLV);
|
||||
mPlayer.setPlayListener(new ITXLivePlayListener() {
|
||||
@Override
|
||||
public void onPlayEvent(int event, Bundle param) {
|
||||
float videoWidth = param.getInt("EVT_PARAM1", 0);
|
||||
float videoHeight = param.getInt("EVT_PARAM2", 0);
|
||||
Log.e("视频流有", "videoWidth:" + videoWidth + " videoHeight:" + videoHeight);
|
||||
if (mLiveBean.getLandscape() != 1){
|
||||
if (videoWidth > 720) {
|
||||
cardParams.height = DpUtil.dp2px(190);
|
||||
cardParams.width = DpUtil.dp2px(255);
|
||||
} else {
|
||||
cardParams.height = DpUtil.dp2px(224);
|
||||
cardParams.width = DpUtil.dp2px(126);
|
||||
}
|
||||
layout.setLayoutParams(cardParams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetStatus(Bundle bundle) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ViewClicksAntiShake.clicksAntiShake(magnetView.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
if(mLiveSDK == Constants.LIVE_SDK_SW){
|
||||
SWAuManager.get().exitChannelAll();
|
||||
}else{
|
||||
mPlayer.stopPlay(true);
|
||||
}
|
||||
APPEasyFloat.getInstance().dismiss(mContext);
|
||||
if (IMLoginManager.get(mContext).isHint2() && !((FragmentActivity) mContext).getSupportFragmentManager().isDestroyed()) {
|
||||
HintDialog fragment = new HintDialog();
|
||||
Bundle args = new Bundle();
|
||||
args.putString("close", "1");
|
||||
fragment.setArguments(args);
|
||||
fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "HintDialog");
|
||||
}
|
||||
}
|
||||
});
|
||||
if(mLiveSDK == Constants.LIVE_SDK_SW){
|
||||
ViewClicksAntiShake.clicksAntiShake(videoFrameLayout, () -> {
|
||||
mPlayer.stopPlay(true);
|
||||
APPEasyFloat.getInstance().dismiss(mContext);
|
||||
new Handler().post(liveCheck);
|
||||
});
|
||||
}else{
|
||||
ViewClicksAntiShake.clicksAntiShake(videoView, () -> {
|
||||
mPlayer.stopPlay(true);
|
||||
APPEasyFloat.getInstance().dismiss(mContext);
|
||||
new Handler().post(liveCheck);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove() {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
if (mPlayer != null)
|
||||
mPlayer.stopPlay(true);
|
||||
}
|
||||
})
|
||||
.show(mContext);
|
||||
|
||||
}
|
||||
|
||||
public void builderSystemFloat(Activity mContext, String url) {
|
||||
liveOnInvokeView = new LiveOnInvokeView();
|
||||
this.mContext = mContext;
|
||||
this.url = url;
|
||||
if (TextUtils.isEmpty(url)) return;
|
||||
EasyFloat.with(mContext)
|
||||
.setTag(TAG)
|
||||
.setLayout(R.layout.view_flaot_live, liveOnInvokeView)
|
||||
.setShowPattern(ShowPattern.ALL_TIME)
|
||||
.setFilter()
|
||||
.setGravity(Gravity.END | Gravity.CENTER_VERTICAL, 0, 200)
|
||||
.registerCallback(this)
|
||||
.show();
|
||||
}
|
||||
|
||||
public LiveFloatView cacheLiveData(LiveBean mLiveBean, int mLiveType, int mLiveSDK, int mLiveTypeVal) {
|
||||
this.mLiveBean = mLiveBean;
|
||||
this.mLiveType = mLiveType;
|
||||
this.mLiveSDK = Constants.LIVE_SDK_SW;
|
||||
this.mLiveTypeVal = mLiveTypeVal;
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unit invoke(FloatCallbacks.Builder builder) {
|
||||
this.builder = builder;
|
||||
builder.createResult((aBoolean, s, view) -> {
|
||||
Log.e("LiveFloatView", "aBoolean:" + aBoolean + "---------------------s:" + s);
|
||||
if (callback != null) {
|
||||
callback.invoke(aBoolean);
|
||||
}
|
||||
builder.dismiss(() -> {
|
||||
if (mPlayer != null && mPlayer.isPlaying()) {
|
||||
mPlayer.stopPlay(true);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
builder.hide(view12 -> {
|
||||
if (mPlayer != null && mPlayer.isPlaying()) {
|
||||
mPlayer.pause();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 悬浮窗布局管理
|
||||
*/
|
||||
private class LiveOnInvokeView implements OnInvokeView {
|
||||
|
||||
@Override
|
||||
public void invoke(View view) {
|
||||
videoFrameLayout = view.findViewById(R.id.videoFrameLayout);
|
||||
L.eSw("invoke(View view) invoke(View view) invoke(View view) invoke(View view) ");
|
||||
CardView layout = view.findViewById(R.id.layout);
|
||||
RelativeLayout.LayoutParams cardParams = (RelativeLayout.LayoutParams) layout.getLayoutParams();
|
||||
if (mLiveBean.getLandscape() == 1) {
|
||||
cardParams.height = DpUtil.dp2px(190);
|
||||
cardParams.width = DpUtil.dp2px(255);
|
||||
} else {
|
||||
cardParams.height = DpUtil.dp2px(224);
|
||||
cardParams.width = DpUtil.dp2px(126);
|
||||
}
|
||||
layout.setLayoutParams(cardParams);
|
||||
if(mLiveSDK == Constants.LIVE_SDK_SW){
|
||||
L.eSw("mLiveSDK == Constants.LIVE_SDK_SW mLive1111111");
|
||||
swAuManager = SWAuManager.get();
|
||||
swAuManager.setAudienceContainer(videoFrameLayout);
|
||||
swAuManager.initRtcEngine( mContext);
|
||||
swAuManager.setupRemoteVideo(Integer.parseInt(mLiveBean.getUid()));
|
||||
//进入主播房间
|
||||
swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(mLiveBean.getUid()));
|
||||
}else{
|
||||
TXCloudVideoView videoView = view.findViewById(R.id.video_view);
|
||||
mPlayer = new TXLivePlayer(mContext);
|
||||
mPlayer.setPlayerView(videoView);
|
||||
mPlayer.startPlay(url, TXLivePlayer.PLAY_TYPE_LIVE_FLV);
|
||||
mPlayer.setPlayListener(new ITXLivePlayListener() {
|
||||
@Override
|
||||
public void onPlayEvent(int event, Bundle param) {
|
||||
float videoWidth = param.getInt("EVT_PARAM1", 0);
|
||||
float videoHeight = param.getInt("EVT_PARAM2", 0);
|
||||
Log.e("视频流有", "videoWidth:" + videoWidth + " videoHeight:" + videoHeight);
|
||||
if (mLiveBean.getLandscape() != 1){
|
||||
if (videoWidth > 720) {
|
||||
cardParams.height = DpUtil.dp2px(190);
|
||||
cardParams.width = DpUtil.dp2px(255);
|
||||
} else {
|
||||
cardParams.height = DpUtil.dp2px(224);
|
||||
cardParams.width = DpUtil.dp2px(126);
|
||||
}
|
||||
layout.setLayoutParams(cardParams);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetStatus(Bundle bundle) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ViewClicksAntiShake.clicksAntiShake(view.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
if(mLiveSDK == Constants.LIVE_SDK_SW){
|
||||
SWAuManager.get().exitChannelAll();
|
||||
}else{
|
||||
mPlayer.stopPlay(true);
|
||||
}
|
||||
|
||||
EasyFloat.dismiss("LiveFloatView", true);
|
||||
if (IMLoginManager.get(mContext).isHint2() && !((FragmentActivity) mContext).getSupportFragmentManager().isDestroyed()) {
|
||||
HintDialog fragment = new HintDialog();
|
||||
Bundle args = new Bundle();
|
||||
args.putString("close", "1");
|
||||
fragment.setArguments(args);
|
||||
fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "HintDialog");
|
||||
}
|
||||
}
|
||||
});
|
||||
ViewClicksAntiShake.clicksAntiShake(view, () -> {
|
||||
if(mLiveSDK == Constants.LIVE_SDK_SW){
|
||||
SWAuManager.get().exitChannelAll();
|
||||
}else{
|
||||
mPlayer.stopPlay(true);
|
||||
}
|
||||
new Handler().post(liveCheck);
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private LiveFloatViewCallback callback;
|
||||
|
||||
public LiveFloatView setCallback(LiveFloatViewCallback callback) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
public interface LiveFloatViewCallback {
|
||||
void invoke(Boolean aBoolean);
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -309,7 +309,10 @@ public class SWAuManager extends BaseCacheManager {
|
||||
* 退出所有的直播间
|
||||
*/
|
||||
public void exitChannelAll() {
|
||||
mRtcEngine.leaveChannel();
|
||||
L.eSw("exitChannelAll exitChannelAll exitChannelAll");
|
||||
if(mRtcEngine!=null){
|
||||
mRtcEngine.leaveChannel();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getChannelName(String liveUid) {
|
||||
|
||||
Reference in New Issue
Block a user