悬浮窗和开播离开

This commit is contained in:
18401019693 2022-11-04 14:58:40 +08:00
parent 50b598d8a1
commit 6656aebff9
4 changed files with 95 additions and 73 deletions

View File

@ -6,9 +6,11 @@ import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode; import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.provider.MediaStore; import android.provider.MediaStore;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
@ -195,4 +197,24 @@ public class BitmapUtil {
canvas.drawBitmap(bitmap, 0, 0, paint); canvas.drawBitmap(bitmap, 0, 0, paint);
return bm; return bm;
} }
/**
* 镜像Bitmap
*
* @param bitmap
* @return
*/
public Bitmap convertMirror(Bitmap bitmap) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Bitmap newb = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
Canvas cv = new Canvas(newb);
Matrix m = new Matrix();
//m.postScale(1, -1); //镜像垂直翻转
m.postScale(-1, 1); //镜像水平翻转
//m.postRotate(-90); //旋转-90度
Bitmap new2 = Bitmap.createBitmap(bitmap, 0, 0, w, h, m, true);
cv.drawBitmap(new2, new Rect(0, 0, new2.getWidth(), new2.getHeight()), new Rect(0, 0, w, h), null);
return newb;
}
} }

View File

@ -7,7 +7,9 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.RelativeLayout;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.lzf.easyfloat.EasyFloat; import com.lzf.easyfloat.EasyFloat;
@ -24,6 +26,7 @@ import com.yunbao.common.dialog.HintDialog;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.HttpClient; import com.yunbao.common.http.HttpClient;
import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.views.floatingview.APPEasyFloat; import com.yunbao.common.views.floatingview.APPEasyFloat;
import com.yunbao.common.views.floatingview.FloatingMagnetView; import com.yunbao.common.views.floatingview.FloatingMagnetView;
@ -68,6 +71,15 @@ public class LiveFloatView implements Function1<FloatCallbacks.Builder, Unit> {
.setMagnetViewListener(new MagnetViewListener() { .setMagnetViewListener(new MagnetViewListener() {
@Override @Override
public void invoke(FloatingMagnetView magnetView) { 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(130);
cardParams.width = DpUtil.dp2px(230);
} else {
cardParams.height = DpUtil.dp2px(224);
cardParams.width = DpUtil.dp2px(126);
}
TXCloudVideoView videoView = magnetView.findViewById(R.id.video_view); TXCloudVideoView videoView = magnetView.findViewById(R.id.video_view);
mPlayer = new V2TXLivePlayerImpl(mContext); mPlayer = new V2TXLivePlayerImpl(mContext);
mPlayer.setRenderView(videoView); mPlayer.setRenderView(videoView);
@ -182,10 +194,19 @@ public class LiveFloatView implements Function1<FloatCallbacks.Builder, Unit> {
@Override @Override
public void invoke(View view) { public void invoke(View view) {
TXCloudVideoView videoView = view.findViewById(R.id.video_view); TXCloudVideoView videoView = view.findViewById(R.id.video_view);
CardView layout = view.findViewById(R.id.layout);
mPlayer = new V2TXLivePlayerImpl(mContext); mPlayer = new V2TXLivePlayerImpl(mContext);
mPlayer.setRenderView(videoView); mPlayer.setRenderView(videoView);
mPlayer.startPlay(url); mPlayer.startPlay(url);
RelativeLayout.LayoutParams cardParams = (RelativeLayout.LayoutParams) layout.getLayoutParams();
if (mLiveBean.getLandscape() == 1) {
cardParams.height = DpUtil.dp2px(130);
cardParams.width = DpUtil.dp2px(230);
} else {
cardParams.height = DpUtil.dp2px(224);
cardParams.width = DpUtil.dp2px(126);
}
layout.setLayoutParams(cardParams);
ViewClicksAntiShake.clicksAntiShake(view.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() { ViewClicksAntiShake.clicksAntiShake(view.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override @Override
public void onViewClicks() { public void onViewClicks() {

View File

@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="210dp" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:id="@+id/layout"
android:layout_width="230dp" android:layout_width="230dp"
android:layout_height="130dp" android:layout_height="130dp"
android:layout_marginStart="25dp" android:layout_marginStart="25dp"

View File

@ -14,6 +14,8 @@ import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_start_dr_pk_view;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -21,14 +23,15 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.lzy.okgo.callback.Callback; import com.bumptech.glide.Glide;
import com.lzy.okgo.model.Progress; import com.bumptech.glide.request.target.CustomTarget;
import com.lzy.okgo.model.Response; import com.bumptech.glide.request.transition.Transition;
import com.lzy.okgo.request.base.Request;
import com.opensource.svgaplayer.SVGAImageView; import com.opensource.svgaplayer.SVGAImageView;
import com.tencent.trtc.TRTCCloudDef; import com.tencent.trtc.TRTCCloudDef;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
@ -45,6 +48,7 @@ import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.HttpClient; import com.yunbao.common.http.HttpClient;
import com.yunbao.common.http.JsonBean; import com.yunbao.common.http.JsonBean;
import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.BitmapUtil;
import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DateFormatUtil; import com.yunbao.common.utils.DateFormatUtil;
import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DialogUitl;
@ -90,6 +94,7 @@ import java.util.List;
import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.RCRTCEngine;
import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback;
import cn.rongcloud.rtc.base.RCRTCRect;
import cn.rongcloud.rtc.base.RTCErrorCode; import cn.rongcloud.rtc.base.RTCErrorCode;
import io.rong.imlib.IRongCallback; import io.rong.imlib.IRongCallback;
import io.rong.imlib.RongIMClient; import io.rong.imlib.RongIMClient;
@ -224,15 +229,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
break; break;
case Constants.LIVE_FUNC_MIC://語音 case Constants.LIVE_FUNC_MIC://語音
ToastUtil.show("開發中,敬請期待"); ToastUtil.show("開發中,敬請期待");
/* //连麦说是有问题暂时隐藏
LiveMicUserDialogFragment fragment = new LiveMicUserDialogFragment();
Bundle bundle = new Bundle();
bundle.putString(Constants.LIVE_UID, mLiveUid);
bundle.putString(Constants.STREAM, mStream);
bundle.putString("By", "1");
fragment.setArguments(bundle);
fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveUserMoreDialogFragment");
LiveMicUserDialogFragment.activity = ((LiveRyAnchorActivity) mContext);*/
break; break;
case Constants.LIVE_FUNC_DR://多人PK case Constants.LIVE_FUNC_DR://多人PK
if (isDRPK != 1) { if (isDRPK != 1) {
@ -343,60 +339,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
openRedPackSendWindow(); openRedPackSendWindow();
break; break;
case Constants.LIVE_FUNC_ZSLK://暫時離開 case Constants.LIVE_FUNC_ZSLK://暫時離開
if (leave == 0) { leaveLive();
leave = 1;
mLivePushViewHolder.leave.setVisibility(View.VISIBLE);
sendSystemMessage(WordUtil.getString(R.string.live_anchor_leave));
} else {
leave = 0;
mLivePushViewHolder.leave.setVisibility(View.GONE);
sendSystemMessage(WordUtil.getString(R.string.live_anchor_come_back));
}
HttpClient.getInstance().get("Live.isLeave", "Live.isLeave")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("isleave", leave)
.params("token", CommonAppConfig.getInstance().getToken())
.execute(new Callback<JsonBean>() {
@Override
public void onStart(Request<JsonBean, ? extends Request> request) {
}
@Override
public void onSuccess(Response<JsonBean> response) {
}
@Override
public void onCacheSuccess(Response<JsonBean> response) {
}
@Override
public void onError(Response<JsonBean> response) {
}
@Override
public void onFinish() {
}
@Override
public void uploadProgress(Progress progress) {
}
@Override
public void downloadProgress(Progress progress) {
}
@Override
public JsonBean convertResponse(okhttp3.Response response) throws Throwable {
return null;
}
});
break; break;
case Constants.LIVE_FUNC_WKS: case Constants.LIVE_FUNC_WKS:
String url = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid; String url = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid;
@ -428,6 +371,45 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
} }
} }
/**
* 主播展示离开直播间
*/
private void leaveLive() {
RCRTCRect rect = new RCRTCRect(0f, 0f, 1.0f);
if (leave == 0) {
leave = 1;
Glide.with(mContext).asBitmap().load(R.mipmap.zslk).into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(BitmapUtil.getInstance().convertMirror(resource), rect);
sendSystemMessage(WordUtil.getString(R.string.live_anchor_leave));
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
} else if (leave == 1) {
leave = 0;
// 清除水印
boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(null, rect);
sendSystemMessage(WordUtil.getString(R.string.live_anchor_come_back));
}
HttpClient.getInstance().get("Live.isLeave", "Live.isLeave")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("isleave", leave)
.params("token", CommonAppConfig.getInstance().getToken())
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
}
});
}
/** /**
* 打开心愿单窗口 * 打开心愿单窗口
@ -475,9 +457,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
if (mLiveRoomViewHolder != null) { if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.changeFaceUnityView(); mLiveRoomViewHolder.changeFaceUnityView();
} }
/* LiveBeautyDialogFragment fragment = new LiveBeautyDialogFragment();
fragment.setiBeautyModule(BeautyManager.iBeautyModule, BeautyManager.iLookupModule, BeautyManager.iBeautyBodyModule);
fragment.show(getSupportFragmentManager(), "LiveBeautyDialogFragment");*/
} }
/** /**
@ -485,7 +464,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
*/ */
public void light() { public void light() {
if (mLiveRoomViewHolder != null) { if (mLiveRoomViewHolder != null) {
// mLiveRoomViewHolder.playLightAnim();
} }
} }