add[声望升级-多人PK]

This commit is contained in:
Martin 2024-04-22 18:28:01 +08:00
parent 4147e3c5f5
commit 8228c45a4d
5 changed files with 467 additions and 726 deletions

View File

@ -17,6 +17,9 @@ import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.faceunity.utils.FURenderer;
import java.util.ArrayList;
import java.util.List;
import io.agora.beautyapi.faceunity.BeautyPreset;
import io.agora.beautyapi.faceunity.CameraConfig;
import io.agora.beautyapi.faceunity.CaptureMode;
@ -48,11 +51,10 @@ public class SWManager extends BaseCacheManager {
private int uid;
private VideoEncoderConfiguration cfg;
private FrameLayout anchorContainer; //主播视图
private FrameLayout pkContainer1; //pk主播视图1
private FrameLayout pkContainer2; //pk主播视图2
private FrameLayout pkContainer3; //pk主播视图3
private FrameLayout pkContainer; //pk主播视图1
private FrameLayout linkUserContainer;//连麦用户视图
private onRtcEngineListener onRtcEngineListener;
private List<String> drPkUserInfo = new ArrayList<>();
public void setOnRtcEngineListener(SWManager.onRtcEngineListener onRtcEngineListener) {
this.onRtcEngineListener = onRtcEngineListener;
@ -193,16 +195,6 @@ public class SWManager extends BaseCacheManager {
}
}
/**
* 设置美颜
*/
public void setBeautPreset(){
if(mRtcEngine!=null){
}
}
/**
* 创建直播间
*/
@ -228,6 +220,7 @@ public class SWManager extends BaseCacheManager {
mRtcEngine.setupLocalVideo(videoCanvas);
}
/**
* PK-加入对方主播直播间
* @param strUid
@ -266,7 +259,86 @@ public class SWManager extends BaseCacheManager {
public void run() {
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
pkContainer1.addView(surfaceView);
pkContainer.addView(surfaceView);
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid));
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
}
});
}
@Override
public void onLeaveChannel(RtcStats stats) {
super.onLeaveChannel(stats);
}
@Override
public void onError(int err) {
super.onError(err);
L.eSw("onError:" + err);
}
});
}
/**
* 更新主播视图
* @param frameLayout
* @param channelName 對方直播間通道
* @param toUid 對方主播uid
*/
public void updateDrChannelView(FrameLayout frameLayout,String channelName,String toUid) {
mRtcEngine.setupLocalVideo(null);
RtcConnection rtcConnection = new RtcConnection();
rtcConnection.channelId = channelName; //對方主播的頻道
rtcConnection.localUid = Integer.parseInt(CommonAppConfig.getInstance().getUid());//自己的ID
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
frameLayout.addView(surfaceView);
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid));
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
}
/**
* PK-加入对方主播直播间
* @param strUid
* @param token
* @param toUid
* @param channelName
*/
public void joinChannelDrEx(FrameLayout frameLayout,String strUid, String token, String toUid, String channelName) {
int tempUid;
if (StringUtil.isEmpty(strUid)) {
tempUid = 0;
} else {
tempUid = Integer.parseInt(strUid);
}
// 创建 ChannelMediaOptions 对象并进行配置
ChannelMediaOptions options = new ChannelMediaOptions();
// 根据场景将用户角色设置为 AUDIENCE (观众)
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
options.autoSubscribeVideo = true;
options.autoSubscribeAudio = true;
options.publishMicrophoneTrack = false;
options.publishCameraTrack = false;
RtcConnection rtcConnection = new RtcConnection();
rtcConnection.channelId = channelName; //對方主播的頻道
rtcConnection.localUid = tempUid;//自己的ID
L.eSw("strUid:" + tempUid + "_token:" + token + "_channelName:" + channelName);
mRtcEngine.joinChannelEx(token, rtcConnection, options, new IRtcEngineEventHandler() {
@Override
public void onJoinChannelSuccess(String channel, int scUid, int elapsed) {
super.onJoinChannelSuccess(channel, scUid, elapsed);
L.eSw("onJoinChannelSuccess:" + channel + " uid " + scUid + " elapsed: " + elapsed);
mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
frameLayout.addView(surfaceView);
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid));
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
}
@ -307,15 +379,6 @@ public class SWManager extends BaseCacheManager {
}
}
//设置对方主播视图
private void setupRemoteVideo(int uid) {
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
pkContainer1.addView(surfaceView);
// SurfaceView 对象传入声网实时互动 SDK设置远端视图
mRtcEngine.setupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT, uid));
}
public void setAnchorContainer(FrameLayout anchorContainer) {
this.anchorContainer = anchorContainer;
}
@ -397,16 +460,8 @@ public class SWManager extends BaseCacheManager {
void onOpenSuccess(String channel, int uid);
}
public void setPkContainer1(FrameLayout pkContainer1) {
this.pkContainer1 = pkContainer1;
}
public void setPkContainer2(FrameLayout pkContainer2) {
this.pkContainer2 = pkContainer2;
}
public void setPkContainer3(FrameLayout pkContainer3) {
this.pkContainer3 = pkContainer3;
public void setPkContainer(FrameLayout pkContainer) {
this.pkContainer = pkContainer;
}
public void setLinkUserContainer(FrameLayout linkUserContainer) {

View File

@ -37,6 +37,7 @@ import android.widget.TextView;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.tencent.trtc.TRTCCloud;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.bean.LiveInfoModel;
@ -60,6 +61,7 @@ import com.yunbao.common.utils.WordUtil;
import com.yunbao.live.R;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.activity.LiveRyAnchorActivity;
import com.yunbao.live.bean.DrPkbean;
import com.yunbao.live.bean.LivePKUserListBean;
import com.yunbao.live.custom.ProgressTextView;
import com.yunbao.live.event.LiveAudienceEvent;
@ -161,6 +163,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
public static List<RCRTCInputStream> inputStreamList1 = new ArrayList<>();
private boolean DRInitiator = false;//是否是duorenPK发起人
private List<DrPkbean> drPkbeans = new ArrayList<>();
public LiveRyLinkMicPkPresenter setDRInitiator(boolean DRInitiator) {
this.DRInitiator = DRInitiator;
return this;
@ -395,50 +399,34 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
Log.i("tts2", s1);
mLiveLinkMicPkViewHolder.setTime(s + " " + s1);
if (s1.equals("00:01") && mIsAnchor && !s.contains("懲罰")) {
HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("addtime", "00:00")
.params("type", "0")
.params("sign", "1")
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0) {
JSONObject datas = JSONObject.parseObject(info[0]);
HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK").params("uid", CommonAppConfig.getInstance().getUid()).params("addtime", "00:00").params("type", "0").params("sign", "1").execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0) {
JSONObject datas = JSONObject.parseObject(info[0]);
SocketSendBean seed_msg = new SocketSendBean()
.param("_method_", SOCKET_LINK_MIC_PK)
.param("action", 9)
.param("msgtype", 10)
.param("win_uid", datas.getString("win_uid"))
.param("uid", CommonAppConfig.getInstance().getUid());
seed_msg.create();
String pkUid = datas.getString("pkuid");
Log.i("seed", seed_msg.mResult.toString());
SocketSendBean seed_msg = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid());
seed_msg.create();
String pkUid = datas.getString("pkuid");
Log.i("seed", seed_msg.mResult.toString());
Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid"));
Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid"));
HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2")
.params("GroupId", "g" + pkUid)
.params("jsonstr", seed_msg.mResult.toString())
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2")
.params("GroupId", "g" + CommonAppConfig.getInstance().getUid())
.params("jsonstr", seed_msg.mResult.toString())
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
}
});
}
});
HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
}
});
}
}
});
});
}
}
});
}
}
@ -522,140 +510,14 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
showDRApplyDialog(u);
}
/**
* 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调
*/
public void onLinkDRMicPkApplyOk(UserBean u) {
/**
* 加入副房间
*
* 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间
*
* @param roomId 房间 ID 长度 64 个字符可包含`A-Z``a-z``0-9``+``=``-``_`
* @param callBack 加入房间回调
* @group 房间管理
*/
RCRTCEngine.getInstance().joinOtherRoom("" + u.getId(), new IRCRTCResultDataCallback<RCRTCOtherRoom>() {
@Override
public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) {
rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener);
runOnUiThread(new Runnable() {
@Override
public void run() {
//遍历远端用户列表
for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) {
//遍历远端用户发布的资源列表
for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) {
if (stream.getMediaType() == RCRTCMediaType.VIDEO) {
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
if (i == 1) {
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);
//todo 本demo只演示添加1个远端用户的视图
livePushRyViewHolder.mPreView1.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
livePushRyViewHolder.mPreView1.addView(remoteView);
} else if (i == 2) {
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
// RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
// ((RCRTCVideoInputStream) stream).setVideoView(remoteView);
// //todo 本demo只演示添加1个远端用户的视图
// LivePushRyViewHolder.dr2_preview.removeAllViews();
// remoteView.setScalingType(SCALE_ASPECT_FILL);
// LivePushRyViewHolder.dr2_preview.addView(remoteView);
} else if (i == 3) {
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
// RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
// ((RCRTCVideoInputStream) stream).setVideoView(remoteView);
// //todo 本demo只演示添加1个远端用户的视图
// LivePushRyViewHolder.dr3_preview.removeAllViews();
// remoteView.setScalingType(SCALE_ASPECT_FILL);
// LivePushRyViewHolder.dr3_preview.addView(remoteView);
} else if (i == 4) {
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
// RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
// ((RCRTCVideoInputStream) stream).setVideoView(remoteView);
// //todo 本demo只演示添加1个远端用户的视图
// LivePushRyViewHolder.dr4_preview.removeAllViews();
// remoteView.setScalingType(SCALE_ASPECT_FILL);
// LivePushRyViewHolder.dr4_preview.addView(remoteView);
}
//如果要订阅所有远端用户的流保存所有流信息方便后面统一订阅
inputStreamList.add(stream);
}
//如果要订阅所有远端用户的流保存所有流信息方便后面统一订阅
inputStreamList1.add(stream);
}
}
//开始订阅资源
rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() {
@Override
public void onSuccess() {
Log.i("ry", "订阅资源成功");
RCRTCMixConfig config = new RCRTCMixConfig();
RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig();
config.setMediaConfig(mediaConfig);
//视频输出配置
RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig();
mediaConfig.setVideoConfig(videoConfig);
//大流视频的输出参数
RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout();
videoConfig.setVideoLayout(normal);
//推荐宽帧率参数值可以通过默认视频流的配置获取也可以根据实际需求来自定义设置
//如不设置宽高值则服务端将使用默认宽高 360 * 640
//:发布的视频分辨率为720 * 1280如果不设置则观众端看到的视频分辨率为 360 * 640,
//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致则应从发布的视频流中获取分辨率配置并设置到 mediaConfig
RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig();
int fps = defaultVideoConfig.getVideoFps().getFps();
int width = 960;
int height = 720;
normal.setWidth(width); //视频宽
normal.setHeight(height); //视频高
normal.setFps(fps); //视频帧率
//1. 设置自适应合流布局模式
config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE);
//2. 合流画布设置
if (rcrtcLiveInfo != null) {
rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() {
@Override
public void onSuccess() {
Log.e("ry", "混成功" + u.getId());
}
@Override
public void onFailed(RTCErrorCode errorCode) {
Log.e("ry", "混失败" + errorCode);
}
});
} else {
Log.w("PkDebug", "PK合流失败,rcrtcLiveInfo为空");
}
}
@Override
public void onFailed(RTCErrorCode rtcErrorCode) {
Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason());
ToastUtil.show(mContext.getString(R.string.live_pk_link_error));
}
});
}
});
}
@Override
public void onFailed(RTCErrorCode rtcErrorCode) {
Log.i("ry", "加入其他房间失败 " + rtcErrorCode.getReason());
}
});
if(livePushRyViewHolder!=null){
livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()),-1);
}
}
/**
@ -689,17 +551,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START);
LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE);
LiveRyAnchorActivity.isDRPK = 1;
ScreenDimenUtil util = ScreenDimenUtil.getInstance();
livePushRyViewHolder.setAnPkRtc(u);//设置对方主播视图
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LINK_MIC_PK)
.param("action", 4)
.param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName())
.param("pkuid", u.getId())
.param("uid", CommonAppConfig.getInstance().getUid())
.param("pkhead", u.getAvatar())
.param("pkname", u.getUserNiceName());
final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 4).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", u.getId()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", u.getAvatar()).param("pkname", u.getUserNiceName());
msg1.create();
LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE);
@ -740,14 +594,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
LiveRyAnchorActivity.isDRPK = 1;
/*---------------------------------------------------------------- */
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LINK_MIC_PK)
.param("action", 2) //回复PK申请 2
.param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName())
.param("pkuid", CommonAppConfig.getInstance().getUid())
.param("uid", CommonAppConfig.getInstance().getUid())
.param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar())
.param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName());
final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 2) //回复PK申请 2
.param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName());
msg1.create();
System.out.println("PK回执 = " + msg1.toString());
Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM;
@ -776,8 +624,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
livePushRyViewHolder.setAnPkRtc(bean);
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE));
Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE));
LiveRyAnchorActivity.isDRPK = 1;
LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE);
SocketRyLinkMicPkUtil.linkMicPkAccept(mSocketRyClient, mApplyUid, mApplyUrl, mApplyNmae);
@ -885,9 +732,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
@Override
public void onSuccess() {
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LINK_MIC_PK)
.param("action", 8);
final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8);
msg1.create();
String targetId = u.getId();
@ -1071,82 +916,70 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
* 随机PK拒绝对话框
*/
public void showPkDialog(UserBean u) {
new DialogUitl.Builder(mContext)
.setHtmlCode(Html.fromHtml(
"<font color='#999999' size='12'>有人向您发起PK请求。</font><br/>" +
"<font color='#FB4F4F' size='12'>若拒绝PK将会10分钟内不会再收到任何随机PK请求。</font>"
))
.setConfirmString("接受")
.setCancelString("拒絕")
.setView(R.layout.dialog_live_random_pk)
.setSimpleCallbackView(new DialogUitl.SimpleCallbackView() {
boolean clickCancel = false;
String titleVal;
TimerTask task;
new DialogUitl.Builder(mContext).setHtmlCode(Html.fromHtml("<font color='#999999' size='12'>有人向您发起PK请求。</font><br/>" + "<font color='#FB4F4F' size='12'>若拒绝PK将会10分钟内不会再收到任何随机PK请求。</font>")).setConfirmString("接受").setCancelString("拒絕").setView(R.layout.dialog_live_random_pk).setSimpleCallbackView(new DialogUitl.SimpleCallbackView() {
boolean clickCancel = false;
String titleVal;
TimerTask task;
@Override
public void onShow(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) {
task = new TimerTask() {
int time = 11;
final Handler handler = new Handler(Looper.getMainLooper());
@Override
public void onShow(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) {
task = new TimerTask() {
int time = 11;
final Handler handler = new Handler(Looper.getMainLooper());
@Override
public void run() {
if (titleVal == null) {
titleVal = ((TextView) title).getText().toString();
}
handler.post(() -> ((TextView) title).setText(titleVal + " " + time));
if (time-- == 0) {
handler.post(() -> showClose(dialog, title, context, confirmBtn, cancelBtn));
cancel();
}
}
};
new Timer().schedule(task, 1000, 1000);
}
@Override
public void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) {
dialog.dismiss();
task.cancel();
apply();
}
@Override
public void onCancel(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) {
if (!clickCancel) {
titleVal = "拒絕PK提示";
((TextView) context).setText(Html.fromHtml(
"<font color='#999999' size='12'>若拒絕PK將會關閉你的隨機PK開關。</br>" +
"並且10分鍾不會收到任何隨機PK請求。</font>"
));
((TextView) cancelBtn).setText("堅持拒絕");
clickCancel = true;
return;
public void run() {
if (titleVal == null) {
titleVal = ((TextView) title).getText().toString();
}
handler.post(() -> ((TextView) title).setText(titleVal + " " + time));
if (time-- == 0) {
handler.post(() -> showClose(dialog, title, context, confirmBtn, cancelBtn));
cancel();
}
showClose(dialog, title, context, confirmBtn, cancelBtn);
}
};
new Timer().schedule(task, 1000, 1000);
}
void showClose(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) {
task.cancel();
((TextView) title).setText("您因拒絕隨機PK被限制關閉中");
((TextView) confirmBtn).setText("确定");
((TextView) context).setText("隨機PK可打開時間" + new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis() + 7200000)));//7200000ms=120m=2h
((TextView) context).setTextSize(12);
((TextView) context).setTextColor(Color.parseColor("#999999"));
refusePk(u);
cancelBtn.setVisibility(View.GONE);
confirmBtn.setOnClickListener(v -> {
dialog.dismiss();
});
}
@Override
public void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) {
dialog.dismiss();
task.cancel();
apply();
}
@Override
public void onCancel(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) {
if (!clickCancel) {
titleVal = "拒絕PK提示";
((TextView) context).setText(Html.fromHtml("<font color='#999999' size='12'>若拒絕PK將會關閉你的隨機PK開關。</br>" + "並且10分鍾不會收到任何隨機PK請求。</font>"));
((TextView) cancelBtn).setText("堅持拒絕");
clickCancel = true;
return;
}
showClose(dialog, title, context, confirmBtn, cancelBtn);
}
void showClose(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) {
task.cancel();
((TextView) title).setText("您因拒絕隨機PK被限制關閉中");
((TextView) confirmBtn).setText("确定");
((TextView) context).setText("隨機PK可打開時間" + new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis() + 7200000)));//7200000ms=120m=2h
((TextView) context).setTextSize(12);
((TextView) context).setTextColor(Color.parseColor("#999999"));
refusePk(u);
cancelBtn.setVisibility(View.GONE);
confirmBtn.setOnClickListener(v -> {
dialog.dismiss();
});
}
void apply() {
isPK(u);
}
})
.build().show();
void apply() {
isPK(u);
}
}).build().show();
}
private void refusePk(UserBean u) {
@ -1159,8 +992,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
@Override
public void onSuccess() {
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LINK_MIC_PK)
final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK)
// .param("randomPk",u.isRandomPk()+"")
.param("action", 3);
msg1.create();
@ -1218,126 +1050,121 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
}
if (mAcceptPk) {
HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("pkuid", u.getId())
.params("type", "1")
.params("sign", "1")
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msgs, String[] info) {
if (code == 0) {
Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid);
HttpClient.getInstance().get("live.getdrnum", "live.getdrnum")
.execute(new HttpCallback() {
HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive").params("uid", CommonAppConfig.getInstance().getUid()).params("pkuid", u.getId()).params("type", "1").params("sign", "1").execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msgs, String[] info) {
if (code == 0) {
Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid);
HttpClient.getInstance().get("live.getdrnum", "live.getdrnum").execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info));
if (info.length > 0) {
JSONObject datas = JSONObject.parseObject(info[0]);
boolean agree = true;
if (datas.getIntValue("pk_num_day") <= 0) {
ToastUtil.show("多人PK次数已用完");
agree = false;
}
boolean finalAgree = agree;
if (finalAgree) {
HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", u.getId()).execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info));
if (info.length > 0) {
JSONObject datas = JSONObject.parseObject(info[0]);
boolean agree = true;
if (datas.getIntValue("pk_num_day") <= 0) {
ToastUtil.show("多人PK次数已用完");
agree = false;
}
boolean finalAgree = agree;
if (finalAgree) {
HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("roomid", u.getId())
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
Log.i("多人PK", "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info));
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LIVE_DRPK)
.param("action", 10)
.param("uid", CommonAppConfig.getInstance().getUid());
msg1.create();
String targetId = "g" + CommonAppConfig.getInstance().getUid();
Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM;
TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString());
io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent);
RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() {
@Override
public void onAttached(io.rong.imlib.model.Message message) {
}
@Override
public void onSuccess(io.rong.imlib.model.Message message) {
Log.e("ry", "发送成功");
if (SocketRyClient.mSocketHandler != null) {
SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + "");
}
}
@Override
public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) {
Log.e("ry", "发送失敗");
}
});
if (info.length == 0) {
return;
}
JSONObject obj = JSONObject.parseObject(info[0]);
JSONArray users = obj.getJSONArray("userlist");
//添加水印
// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f);
// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect);
dRjoinOtherRoom(u.getId(), 1);
livePushRyViewHolder.setAnDrPkRtc(u.getId());
for (int i = 0; i < users.size(); i++) {
JSONObject user = users.getJSONObject(i);
Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表");
if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) {
if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) {
/**
* 向指定用户发送跨房间连麦请求
* <P>
* 1: inviterAutoMix为true时
*
* 1.1如果被邀请方在加入邀请方房间之前发布了资源当被邀请方加入邀请者房间成功后服务器会把被邀请方流资源合并到邀请方视图 ·默认仅悬浮布局合流
*
* 1.2如果被邀请方在加入邀请方房间之前没有发布过资源将会在被邀请方发布资源成功后服务器会把被邀请方流资源合并到邀请方视图默认仅悬浮布局合流
*
* 2:无论为true或false双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局一旦主动设置过合流布局后续音视频直播过程中设置的自动合流参数将失效
* <P/>
*/
IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() {
@Override
public void onSuccess() {
}
@Override
public void onFailed(RTCErrorCode errorCode) {
}
});
}
}
}
}
});
}
} else {
ToastUtil.show(msg);
L.eSw("多人PK"+ "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info));
if (info.length == 0) {
return;
}
JSONObject obj = JSONObject.parseObject(info[0]);
drPkbeans = JSONObject.parseArray(obj.getString("userlist"),DrPkbean.class);
for (int i = 0; i <drPkbeans.size(); i++) {
if(!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))){
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LIVE_DRPK)
.param("action", 2)
.param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName())
.param("pkuid", drPkbeans.get(i).getId())
.param("uid", CommonAppConfig.getInstance().getUid())
.param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar())
.param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName());
msg1.create();
String targetId = "g" + drPkbeans.get(i).getId();
Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM;
TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString());
io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent);
RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() {
@Override
public void onAttached(io.rong.imlib.model.Message message) {
}
@Override
public void onSuccess(io.rong.imlib.model.Message message) {
if (SocketRyClient.mSocketHandler != null) {
SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + "");
}
}
@Override
public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) {
Log.e("tx", "aaa" + errorCode.toString());
ToastUtil.show(errorCode.code + ":" + errorCode.msg);
}
});
//dRjoinOtherRoom(u.getId(), 1);
livePushRyViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()),i+2);
}
}
/*for (int i = 0; i < users.size(); i++) {
JSONObject user = users.getJSONObject(i);
Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表");
if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) {
if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) {
*//**
* 向指定用户发送跨房间连麦请求
* <P>
* 1: inviterAutoMix为true时
*
* 1.1如果被邀请方在加入邀请方房间之前发布了资源当被邀请方加入邀请者房间成功后服务器会把被邀请方流资源合并到邀请方视图 ·默认仅悬浮布局合流
*
* 1.2如果被邀请方在加入邀请方房间之前没有发布过资源将会在被邀请方发布资源成功后服务器会把被邀请方流资源合并到邀请方视图默认仅悬浮布局合流
*
* 2:无论为true或false双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局一旦主动设置过合流布局后续音视频直播过程中设置的自动合流参数将失效
* <P/>
*//*
IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() {
@Override
public void onSuccess() {
}
@Override
public void onFailed(RTCErrorCode errorCode) {
}
});
}
}
}*/
}
});
}
} else {
ToastUtil.show(msg);
}
}
}
});
});
}
}
});
} else {
@ -1351,9 +1178,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
@Override
public void onSuccess() {
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LINK_MIC_PK)
.param("action", 8);
final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8);
msg1.create();
String targetId = u.getId();
@ -1393,9 +1218,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
@Override
public void onSuccess() {
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LINK_MIC_PK)
.param("action", 3);
final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 3);
msg1.create();
String targetId = u.getId();
@ -1444,183 +1267,53 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
public void dRjoinOtherRoom(String uid, int i) {
Log.e("ry", uid + "洒洒" + i + "VVVV" + i);
mApplyUid = uid;
RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback<RCRTCOtherRoom>() {
@Override
public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) {
rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener);
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
//把多人PK的View显示出来
if (livePushRyViewHolder.dr_pk_view.getVisibility() == View.GONE) {
ScreenDimenUtil util = ScreenDimenUtil.getInstance();
int mScreenWdith = util.getScreenWdith();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960);
params.weight = 1;
params.topMargin = DpUtil.dp2px(123);
livePushRyViewHolder.dr_pk_view.setLayoutParams(params);
livePushRyViewHolder.camera.setLayoutParams(params);
livePushRyViewHolder.dr_pk_view.setVisibility(View.VISIBLE);
livePushRyViewHolder.dr1_preview.setVisibility(View.GONE);
livePushRyViewHolder.dr2_preview.setVisibility(View.GONE);
livePushRyViewHolder.dr3_preview.setVisibility(View.GONE);
livePushRyViewHolder.dr4_preview.setVisibility(View.GONE);
detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null);
detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1);
linearGrade1 = detailsView1.findViewById(R.id.linear_grade1);
imageGrade1 = detailsView1.findViewById(R.id.image_grade1);
textGrade1 = detailsView1.findViewById(R.id.text_grade1);
imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()));
livePushRyViewHolder.mPreView.addView(detailsView1);
detailsLinearLayout1.setVisibility(View.VISIBLE);
linearGrade1.setVisibility(View.GONE);
}
/*new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
//把多人PK的View显示出来
if (livePushRyViewHolder.dr_pk_view.getVisibility() == View.GONE) {
livePushRyViewHolder.dr_pk_view.setVisibility(View.VISIBLE);
livePushRyViewHolder.dr1_preview.setVisibility(View.GONE);
livePushRyViewHolder.dr2_preview.setVisibility(View.GONE);
livePushRyViewHolder.dr3_preview.setVisibility(View.GONE);
livePushRyViewHolder.dr4_preview.setVisibility(View.GONE);
detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null);
detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1);
linearGrade1 = detailsView1.findViewById(R.id.linear_grade1);
imageGrade1 = detailsView1.findViewById(R.id.image_grade1);
textGrade1 = detailsView1.findViewById(R.id.text_grade1);
imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()));
livePushRyViewHolder.mPreView.addView(detailsView1);
detailsLinearLayout1.setVisibility(View.VISIBLE);
linearGrade1.setVisibility(View.GONE);
}
Log.e("ry", "多人接受成功" + mApplyUid);
ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success");
//遍历远端用户列表
for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) {
Log.e("ry", rcrtcOtherRoom.getRemoteUsers().get(i).getUserId() + "收到rcrtcOtherRoom" + rcrtcOtherRoom.getRemoteUsers().size());
//遍历远端用户发布的资源列表
for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) {
Log.e("ry", i + "收到" + stream.getMediaType() + "实打实打算" + rcrtcOtherRoom.getRemoteUsers().get(i).getUserId());
if (stream.getMediaType() == RCRTCMediaType.VIDEO) {
if (inputStreamList.size() == 0) {
livePushRyViewHolder.dr1_preview.setVisibility(View.VISIBLE);
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
//todo 本demo只演示添加1个远端用户的视图
livePushRyViewHolder.dr1_preview.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
livePushRyViewHolder.dr1_preview.addView(remoteView);
LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback<LiveInfoModel>() {
@Override
public void onSuccess(LiveInfoModel data) {
detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null);
detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2);
linearGrade2 = detailsView2.findViewById(R.id.linear_grade2);
textPkName2 = detailsView2.findViewById(R.id.text_pk_name2);
imageGrade2 = detailsView2.findViewById(R.id.image_grade2);
textGrade2 = detailsView2.findViewById(R.id.text_grade2);
imageGrade2.setTag(String.valueOf(uid));
textPkName2.setText(data.getUserNicename());
livePushRyViewHolder.dr1_preview.addView(detailsView2);
detailsLinearLayout2.setVisibility(View.VISIBLE);
linearGrade2.setVisibility(View.GONE);
}
@Override
public void onError(String error) {
ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred");
}
});
} else if (inputStreamList.size() == 1) {
livePushRyViewHolder.dr3_preview.setVisibility(View.VISIBLE);
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
//todo 本demo只演示添加1个远端用户的视图
livePushRyViewHolder.dr3_preview.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
livePushRyViewHolder.dr3_preview.addView(remoteView);
LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback<LiveInfoModel>() {
@Override
public void onSuccess(LiveInfoModel data) {
detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null);
detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4);
linearGrade4 = detailsView4.findViewById(R.id.linear_grade4);
textPkName4 = detailsView4.findViewById(R.id.text_pk_name4);
imageGrade4 = detailsView4.findViewById(R.id.image_grade4);
textGrade4 = detailsView4.findViewById(R.id.text_grade4);
imageGrade4.setTag(uid);
textPkName4.setText(data.getUserNicename());
livePushRyViewHolder.dr3_preview.addView(detailsView4);
detailsLinearLayout4.setVisibility(View.VISIBLE);
linearGrade4.setVisibility(View.GONE);
}
@Override
public void onError(String error) {
}
});
} else if (inputStreamList.size() == 2) {
livePushRyViewHolder.cameraPreview3.setVisibility(View.VISIBLE);
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
//todo 本demo只演示添加1个远端用户的视图
livePushRyViewHolder.cameraPreview3.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
livePushRyViewHolder.cameraPreview3.addView(remoteView);
LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback<LiveInfoModel>() {
@Override
public void onSuccess(LiveInfoModel data) {
detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null);
detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3);
linearGrade3 = detailsView3.findViewById(R.id.linear_grade3);
textPkName3 = detailsView3.findViewById(R.id.text_pk_name3);
imageGrade3 = detailsView3.findViewById(R.id.image_grade3);
textGrade3 = detailsView3.findViewById(R.id.text_grade3);
imageGrade3.setTag(uid);
textPkName3.setText(data.getUserNicename());
livePushRyViewHolder.cameraPreview3.addView(detailsView3);
detailsLinearLayout3.setVisibility(View.VISIBLE);
linearGrade3.setVisibility(View.GONE);
}
@Override
public void onError(String error) {
}
});
}
inputStreamList.add(stream);
}
inputStreamList1.add(stream);
}
}
//开始订阅资源
rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() {
@Override
public void onSuccess() {
Log.i("ry", "订阅资源成功");
}
@Override
public void onFailed(RTCErrorCode rtcErrorCode) {
Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason());
ToastUtil.show(mContext.getString(R.string.live_pk_link_error));
}
});
//2. 合流画布设置
rcrtcLiveInfo.setMixConfig(create_Custom_MixConfig(false, inputStreamList), new IRCRTCResultCallback() {
@Override
public void onSuccess() {
Log.e("ry", "222混成功");
}
@Override
public void onFailed(RTCErrorCode errorCode) {
Log.e("ry", "混失败" + errorCode);
}
});
//设置多人PK数据
LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback<LiveInfoModel>() {
@Override
public void onSuccess(LiveInfoModel data) {
detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null);
detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2);
linearGrade2 = detailsView2.findViewById(R.id.linear_grade2);
textPkName2 = detailsView2.findViewById(R.id.text_pk_name2);
imageGrade2 = detailsView2.findViewById(R.id.image_grade2);
textGrade2 = detailsView2.findViewById(R.id.text_grade2);
imageGrade2.setTag(String.valueOf(uid));
textPkName2.setText(data.getUserNicename());
livePushRyViewHolder.dr1_preview.addView(detailsView2);
detailsLinearLayout2.setVisibility(View.VISIBLE);
linearGrade2.setVisibility(View.GONE);
}
@Override
public void onError(String error) {
ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred");
}
});
}
@Override
public void onFailed(RTCErrorCode rtcErrorCode) {
Log.e("ry", mApplyUid + "加入其他房间失败 " + rtcErrorCode);
Log.i("ry", mApplyUid + "加入其他房间失败 " + rtcErrorCode);
Log.e("ry", "多人接受成功" + mApplyUid);
ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success");
}
});
});*/
}
/**
@ -2327,7 +2020,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
String pkTime = StringUtil.getDurationText(time * 1000);
livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime));
mPkTimeCount = time;
if (time>0){
if (time > 0) {
String s1 = StringUtil.getDurationText(mPkTimeCount * 1000);
livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1));
mHandler.sendEmptyMessage(WHAT_PK_TIME2);
@ -2529,8 +2222,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
if (mHandler != null) {
mHandler.removeCallbacksAndMessages(null);
}
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT));
Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT));
// endDRGif();
if (DRInitiator) {
LiveNetManager.get(mContext).jieshuDRPK("" + IMLoginManager.get(mContext).getUserInfo().getId());

View File

@ -323,8 +323,6 @@ public class SocketRyClient {
// LiveAudienceActivity.getmLivePlayViewHolder().setPkview();
Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW));
}
} else if (action3 == 5) {
// endDRGif();
LiveRoomViewHolder.d_pk_view.setVisibility(View.GONE);
@ -346,6 +344,7 @@ public class SocketRyClient {
Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW));
isDRPK = 1;
} else if (action3 == 10) {
//显示pk分数
if (!map.getString("uid").equals(CommonAppConfig.getInstance().getUid())) {
// LiveAudienceActivity.getmLivePlayViewHolder().setPkview();
Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW));

View File

@ -84,7 +84,6 @@ import cn.rongcloud.rtc.base.RCRTCParamsType;
import cn.rongcloud.rtc.base.RTCErrorCode;
import io.agora.beautyapi.faceunity.agora.SWAuManager;
import io.agora.beautyapi.faceunity.agora.SWManager;
import io.rong.imkit.userinfo.db.model.User;
import io.rong.imlib.IRongCallback;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;
@ -241,9 +240,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
@Override
public void onSuccess() {
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LINK_MIC_PK)
.param("action", 8);
final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8);
msg1.create();
String targetId = userBean.getId();
@ -497,92 +494,62 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
aheadOfScheduleEndPK(mPkUid, CommonAppConfig.getInstance().getUserBean().getUserNiceName(), (String) tv_avatarOther_name.getTag());
//断开连麦
LiveRyAnchorActivity.isDRPK = 0;
HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout")
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
}
});
HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout").execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
}
});
HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("addtime", "1")
.params("type", "1")
.params("sign", "1")
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0) {
JSONObject datas = JSONObject.parseObject(info[0]);
String pkUid = datas.getString("pkuid");
HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK").params("uid", CommonAppConfig.getInstance().getUid()).params("addtime", "1").params("type", "1").params("sign", "1").execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0) {
JSONObject datas = JSONObject.parseObject(info[0]);
String pkUid = datas.getString("pkuid");
//退出副房间
// TODO: 2024/4/13 退出对方主播直播间
SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),pkUid1);
SWManager.get().updateMyChannelView((FrameLayout) mBigContainer);
btn_close.setVisibility(View.GONE);//隐藏连麦按钮
EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", ""));
closeButtonGone();
//退出副房间
// TODO: 2024/4/13 退出对方主播直播间
SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), pkUid1);
SWManager.get().updateMyChannelView((FrameLayout) mBigContainer);
btn_close.setVisibility(View.GONE);//隐藏连麦按钮
EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", ""));
closeButtonGone();
SocketSendBean seed_msg = new SocketSendBean()
.param("_method_", Constants.SOCKET_LINK_MIC_PK)
.param("action", 9)
.param("msgtype", 10)
.param("win_uid", datas.getString("win_uid"))
.param("uid", CommonAppConfig.getInstance().getUid());
seed_msg.create();
Log.i("seed", seed_msg.mResult.toString());
HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2")
.params("GroupId", "g" + pkUid)
.params("jsonstr", seed_msg.mResult.toString())
.execute(new HttpCallback() {
SocketSendBean seed_msg = new SocketSendBean().param("_method_", Constants.SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid());
seed_msg.create();
Log.i("seed", seed_msg.mResult.toString());
HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
SocketSendBean seed_msgs = new SocketSendBean().param("_method_", Constants.SOCKET_LINK_MIC_PK).param("action", 5).param("msgtype", 10).param("uname", "1").param("uimg", "1").param("pkuid", LiveRyLinkMicPkPresenter.oldmPkUid).param("uid", CommonAppConfig.getInstance().getUid());
seed_msgs.create();
Log.i("seed", seed_msgs.mResult.toString());
HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + LiveRyLinkMicPkPresenter.oldmPkUid).params("jsonstr", seed_msgs.mResult.toString()).execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msgs.mResult.toString()).execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2")
.params("GroupId", "g" + CommonAppConfig.getInstance().getUid())
.params("jsonstr", seed_msg.mResult.toString())
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
SocketSendBean seed_msgs = new SocketSendBean()
.param("_method_", Constants.SOCKET_LINK_MIC_PK)
.param("action", 5)
.param("msgtype", 10)
.param("uname", "1")
.param("uimg", "1")
.param("pkuid", LiveRyLinkMicPkPresenter.oldmPkUid)
.param("uid", CommonAppConfig.getInstance().getUid());
seed_msgs.create();
Log.i("seed", seed_msgs.mResult.toString());
HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2")
.params("GroupId", "g" + LiveRyLinkMicPkPresenter.oldmPkUid)
.params("jsonstr", seed_msgs.mResult.toString())
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2")
.params("GroupId", "g" + CommonAppConfig.getInstance().getUid())
.params("jsonstr", seed_msgs.mResult.toString())
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
}
});
}
});
}
});
}
});
}
});
}
});
}
});
}
});
}
}
});
}
@ -608,6 +575,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
});
}
public void setAnPkRtc(UserBean u) {
if (swManager != null && u != null) {
L.eSw("设置对方主播的视图setAnPkRtc" + u);
@ -619,41 +587,73 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
mBigContainer.removeAllViews();
btn_close.setVisibility(View.VISIBLE);
//设置对方主播的渲染视图 设置到 rightContainer
swManager.setPkContainer1(mRightContainer);
swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,u.getId(), SWAuManager.getChannelName(u.getId()));
swManager.setPkContainer(mRightContainer);
swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId()));
}
}
public void setAnDrPkRtc(String uid) {
if (swManager != null && StringUtil.isEmpty(uid)) {
L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid);
private int currentPosition = 0;
//将自己的渲染视图设置到 leftContainer
swManager.updateMyChannelView((FrameLayout) mLeftContainer);
private String drpkUid3 = "";
public void setAnDrPkRtc(String uid, int position) {
FrameLayout frameLayout = null;
int temp= -1;
if (swManager != null && !StringUtil.isEmpty(uid)) {
L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid + "position:" + position);
if(currentPosition==0){
position = 2;
}
if(position==-1){
temp = currentPosition+1;
}else{
temp = position;
}
switch (temp) {
case 2:
frameLayout = dr2_preview;
dr3_preview.setVisibility(View.GONE);
dr4_preview.setVisibility(View.GONE);
break;
case 3:
drpkUid3 = uid;
frameLayout = dr4_preview;
dr4_preview.setVisibility(View.VISIBLE);
break;
case 4:
dr3_preview.setVisibility(View.VISIBLE);
//將f3->f4 f4->f3
dr3_preview.removeAllViews();
swManager.updateDrChannelView(dr3_preview,SWAuManager.getChannelName(drpkUid3),drpkUid3);
//清除 mBigContainer 中的渲染
mBigContainer.removeAllViews();
dr4_preview.removeAllViews();
frameLayout = dr4_preview;
break;
}
if (temp == 2) {
swManager.updateMyChannelView(dr1_preview);
mBigContainer.removeAllViews();
}
swManager.joinChannelDrEx(frameLayout,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid));
btn_close.setVisibility(View.VISIBLE);
//设置对方主播的渲染视图 设置到 rightContainer
swManager.setPkContainer1(mRightContainer);
swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,uid, SWAuManager.getChannelName(uid));
dr_pk_view.setVisibility(View.VISIBLE);
currentPosition = temp;
}
}
public void onLinkMicAnchorClose(){
public void onLinkMicAnchorClose() {
swManager.updateMyChannelView((FrameLayout) mBigContainer);
LivePushRyViewHolder.btn_close.setVisibility(View.GONE);
}
public void onLinkDRMicPkApply(UserBean userBean){
public void onLinkDRMicPkApply(UserBean userBean) {
if (mLiveRyLinkMicPkPresenter != null) {
mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(userBean);
}
}
@Override
public void changeToLeft() {
if (mPreView != null) {
@ -907,29 +907,20 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
}
String ct = "由於 " + uname + " 退出比賽," + pkname + " 獲得勝利";
SocketSendBean seed_msg = new SocketSendBean()
.param("_method_", Constants.SOCKET_SYSTEM)
.param("action", 1)
.param("ct", ct);
SocketSendBean seed_msg = new SocketSendBean().param("_method_", Constants.SOCKET_SYSTEM).param("action", 1).param("ct", ct);
seed_msg.create();
HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2")
.params("GroupId", "g" + pkUid)
.params("jsonstr", seed_msg.mResult.toString())
.execute(new HttpCallback() {
HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2")
.params("GroupId", "g" + CommonAppConfig.getInstance().getUid())
.params("jsonstr", seed_msg.mResult.toString())
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
}
});
}
});
}
});
}
private Bitmap decodeResource(Resources resources, int id) {
@ -964,10 +955,10 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
});
}
public void setEnableBeauty(boolean flag){
if(swManager!=null){
swManager.setEnableBeauty(flag);
}
public void setEnableBeauty(boolean flag) {
if (swManager != null) {
swManager.setEnableBeauty(flag);
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
@ -983,7 +974,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
@Override
public void onDestroy() {
super.onDestroy();
if(swManager!=null){
if (swManager != null) {
swManager.exitChannelAll();
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -13,6 +14,7 @@
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:orientation="vertical">
<FrameLayout
@ -37,51 +39,53 @@
<LinearLayout
android:id="@+id/dr_pk_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_marginTop="130dp"
android:orientation="vertical"
android:visibility="gone">
android:orientation="horizontal"
android:visibility="visible">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
android:orientation="vertical">
<FrameLayout
android:id="@+id/dr1_preview"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@mipmap/live_icon_vacancy" />
android:background="@mipmap/live_icon_vacancy"
tools:ignore="NestedWeights" />
<FrameLayout
android:id="@+id/dr2_preview"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/dr3_preview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@mipmap/live_icon_vacancy" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
android:orientation="vertical">
<FrameLayout
android:id="@+id/dr3_preview"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/dr2_preview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@mipmap/live_icon_vacancy" />
android:background="@mipmap/live_icon_vacancy"
tools:ignore="NestedWeights" />
<FrameLayout
android:id="@+id/dr4_preview"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@mipmap/live_icon_vacancy" />