2715 lines
139 KiB
Java
2715 lines
139 KiB
Java
package com.yunbao.live.presenter;
|
||
|
||
import static com.blankj.utilcode.util.SnackbarUtils.dismiss;
|
||
import static com.lzy.okgo.utils.HttpUtils.runOnUiThread;
|
||
import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK;
|
||
import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK;
|
||
import static com.yunbao.live.activity.LiveRyAnchorActivity.PKing;
|
||
import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK;
|
||
import static com.yunbao.live.views.LivePushRyViewHolder.btn_close;
|
||
import static com.yunbao.live.views.LivePushRyViewHolder.contexts;
|
||
import static com.yunbao.live.views.LivePushRyViewHolder.rcrtcLiveInfo;
|
||
import static com.yunbao.live.views.LivePushRyViewHolder.rtcRoom;
|
||
import static cn.rongcloud.rtc.core.RendererCommon.ScalingType.SCALE_ASPECT_FILL;
|
||
|
||
import android.app.Dialog;
|
||
import android.content.Context;
|
||
import android.graphics.Bitmap;
|
||
import android.graphics.Canvas;
|
||
import android.graphics.Color;
|
||
import android.graphics.Paint;
|
||
import android.graphics.drawable.ColorDrawable;
|
||
import android.os.Handler;
|
||
import android.os.Looper;
|
||
import android.os.Message;
|
||
import android.os.SystemClock;
|
||
import android.text.Html;
|
||
import android.text.TextUtils;
|
||
import android.util.Log;
|
||
import android.view.Gravity;
|
||
import android.view.LayoutInflater;
|
||
import android.view.View;
|
||
import android.view.ViewGroup;
|
||
import android.widget.ImageView;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.PopupWindow;
|
||
import android.widget.RelativeLayout;
|
||
import android.widget.TextView;
|
||
|
||
import com.alibaba.fastjson.JSONArray;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.blankj.utilcode.util.ViewUtils;
|
||
import com.tencent.trtc.TRTCCloud;
|
||
import com.yunbao.common.CommonAppConfig;
|
||
import com.yunbao.common.bean.LiveInfoModel;
|
||
import com.yunbao.common.bean.UserBean;
|
||
import com.yunbao.common.event.AnchorInfoEvent;
|
||
import com.yunbao.common.glide.ImgLoader;
|
||
import com.yunbao.common.http.HttpCallback;
|
||
import com.yunbao.common.http.HttpClient;
|
||
import com.yunbao.common.http.live.LiveNetManager;
|
||
import com.yunbao.common.manager.IMLoginManager;
|
||
import com.yunbao.common.manager.IMRTCManager;
|
||
import com.yunbao.common.manager.RandomPkManager;
|
||
import com.yunbao.common.utils.Bus;
|
||
import com.yunbao.common.utils.DialogUitl;
|
||
import com.yunbao.common.utils.DpUtil;
|
||
import com.yunbao.common.utils.ScreenDimenUtil;
|
||
import com.yunbao.common.utils.StringUtil;
|
||
import com.yunbao.common.utils.ToastUtil;
|
||
import com.yunbao.live.R;
|
||
import com.yunbao.live.activity.LiveAudienceActivity;
|
||
import com.yunbao.live.activity.LiveRyAnchorActivity;
|
||
import com.yunbao.live.bean.LivePKUserListBean;
|
||
import com.yunbao.live.custom.ProgressTextView;
|
||
import com.yunbao.live.event.LiveAudienceEvent;
|
||
import com.yunbao.live.interfaces.ILiveLinkMicViewHolder;
|
||
import com.yunbao.live.socket.SocketRyClient;
|
||
import com.yunbao.live.socket.SocketRyLinkMicPkUtil;
|
||
import com.yunbao.live.socket.SocketSendBean;
|
||
import com.yunbao.live.views.LiveLinkMicPkViewHolder;
|
||
import com.yunbao.live.views.LivePushRyViewHolder;
|
||
|
||
import org.greenrobot.eventbus.EventBus;
|
||
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.ArrayList;
|
||
import java.util.Arrays;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
import java.util.Locale;
|
||
import java.util.Timer;
|
||
import java.util.TimerTask;
|
||
|
||
import cn.rongcloud.rtc.api.RCRTCEngine;
|
||
import cn.rongcloud.rtc.api.RCRTCMixConfig;
|
||
import cn.rongcloud.rtc.api.RCRTCOtherRoom;
|
||
import cn.rongcloud.rtc.api.RCRTCRemoteUser;
|
||
import cn.rongcloud.rtc.api.callback.IRCRTCOtherRoomEventsListener;
|
||
import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback;
|
||
import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback;
|
||
import cn.rongcloud.rtc.api.stream.RCRTCInputStream;
|
||
import cn.rongcloud.rtc.api.stream.RCRTCVideoInputStream;
|
||
import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig;
|
||
import cn.rongcloud.rtc.api.stream.RCRTCVideoView;
|
||
import cn.rongcloud.rtc.base.RCRTCMediaType;
|
||
import cn.rongcloud.rtc.base.RCRTCRoomType;
|
||
import cn.rongcloud.rtc.base.RCRTCStream;
|
||
import cn.rongcloud.rtc.base.RTCErrorCode;
|
||
import io.rong.imlib.IRongCallback;
|
||
import io.rong.imlib.RongIMClient;
|
||
import io.rong.imlib.model.Conversation;
|
||
import io.rong.message.TextMessage;
|
||
|
||
//import cn.rongcloud.rtc.jni.video.RCRect;
|
||
|
||
/**
|
||
* Created by cxf on 2018/11/16.
|
||
* 主播与主播PK逻辑
|
||
*/
|
||
|
||
public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
|
||
|
||
private static final int WHAT_PK_WAIT_RECEIVE = 0;//收到pk申请等待 what
|
||
private static final int WHAT_PK_WAIT_SEND = 1;//发送pk申请等待 what
|
||
private static final int WHAT_PK_TIME = 2;//pk时间变化 what
|
||
private static final int WHAT_PK_TIME2 = 22;//pk时间变化 what
|
||
private static final int LINK_MIC_COUNT_MAX = 10;
|
||
private static int PK_TIME_MAX = 60 * 15;//pk时间 15分钟
|
||
private static final int PK_TIME_MAX_2 = 60;//惩罚时间 1分钟
|
||
private Context mContext;
|
||
private View mRoot;
|
||
private boolean mIsAnchor;//自己是否是主播
|
||
private SocketRyClient mSocketRyClient;
|
||
private ViewGroup mPkContainer;
|
||
private boolean mIsApplyDialogShow;//是否显示了申请PK的弹窗
|
||
private boolean mAcceptPk;//是否接受连麦
|
||
private boolean mIsPk;//是否已经Pk了
|
||
public static String mApplyUid;//正在申请Pk的主播的uid
|
||
private String mApplyUrl;//正在申请Pk的主播的头像
|
||
private String mApplyNmae;//正在申请Pk的主播的名字
|
||
private String mApplyStream;//正在申请Pk的主播的stream
|
||
private String mLiveUid;//自己主播的uid
|
||
private String mUrl;//主播的头像
|
||
public static String mPkUid;//正在Pk的对方主播的uid
|
||
public static String oldmPkUid;//正在Pk的对方主播的uid
|
||
private ProgressTextView mLinkMicWaitProgress;
|
||
private int mPkWaitCount;//Pk弹窗等待倒计时Live
|
||
private int mPkTimeCount;//pk时间
|
||
private PopupWindow mPkPopWindow;
|
||
private Handler mHandler;
|
||
private LiveLinkMicPkViewHolder mLiveLinkMicPkViewHolder;
|
||
private String mPkTimeString1;
|
||
private String mPkTimeString2;
|
||
private boolean mIsPkEnd;//pk是否结束,进入惩罚时间
|
||
private boolean mPkSend;//pk请求是否已经发送
|
||
private int mPkSendWaitCount;//发送pk请求后的等待时间
|
||
private String mSelfStream;
|
||
private int mPkTimeFromServer;
|
||
public static TRTCCloud mTRTCCloud1;
|
||
private View detailsView1, detailsView2, detailsView3, detailsView4;
|
||
private LinearLayout detailsLinearLayout1, detailsLinearLayout2, detailsLinearLayout3, detailsLinearLayout4;
|
||
private LinearLayout linearGrade1, linearGrade2, linearGrade3, linearGrade4;
|
||
private TextView textPkName1, textPkName2, textPkName3, textPkName4;
|
||
private TextView textGrade1, textGrade2, textGrade3, textGrade4;
|
||
private ImageView imageGrade1, imageGrade2, imageGrade3, imageGrade4;
|
||
|
||
public LivePushRyViewHolder livePushRyViewHolder;
|
||
|
||
public static List<RCRTCInputStream> inputStreamList = new ArrayList<>();
|
||
public static List<RCRTCInputStream> inputStreamList1 = new ArrayList<>();
|
||
private boolean DRInitiator = false;//是否是duorenPK发起人
|
||
|
||
public LiveRyLinkMicPkPresenter setDRInitiator(boolean DRInitiator) {
|
||
this.DRInitiator = DRInitiator;
|
||
return this;
|
||
}
|
||
|
||
private IRCRTCOtherRoomEventsListener otherRoomEventsListener = new IRCRTCOtherRoomEventsListener() {
|
||
|
||
@Override
|
||
public void onRemoteUserPublishResource(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, List<RCRTCInputStream> streams) {
|
||
}
|
||
|
||
@Override
|
||
public void onRemoteUserMuteAudio(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) {
|
||
}
|
||
|
||
@Override
|
||
public void onRemoteUserMuteVideo(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) {
|
||
}
|
||
|
||
@Override
|
||
public void onRemoteUserUnpublishResource(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, List<RCRTCInputStream> streams) {
|
||
}
|
||
|
||
@Override
|
||
public void onUserJoined(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) {
|
||
}
|
||
|
||
@Override
|
||
public void onUserLeft(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) {
|
||
}
|
||
|
||
@Override
|
||
public void onUserOffline(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) {
|
||
RCRTCEngine.getInstance().leaveOtherRoom(room.getRoomId(), true, new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onLeaveRoom(RCRTCOtherRoom room, int reasonCode) {
|
||
Log.d("RYM_DG", "Other onLeaveRoom: room = " + room.getRoomId());
|
||
}
|
||
};
|
||
|
||
public LiveRyLinkMicPkPresenter(Context context, ILiveLinkMicViewHolder linkMicViewHolder, boolean isAnchor, View root) {
|
||
mContext = context;
|
||
mIsAnchor = isAnchor;
|
||
mRoot = root;
|
||
mPkContainer = linkMicViewHolder.getPkContainer();
|
||
mPkTimeString1 = "";
|
||
mPkTimeString2 = mContext.getString(R.string.live_pk_time_2);
|
||
//从本地取数据
|
||
String pkTime = CommonAppConfig.getInstance().getAnchorPkTime();
|
||
if (!pkTime.isEmpty()) {
|
||
try {
|
||
int time = Integer.parseInt(pkTime) * 60;
|
||
if (time > 0) {
|
||
PK_TIME_MAX = time;
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
Log.d("PK_TIME_MAX", "" + PK_TIME_MAX);
|
||
mHandler = new Handler() {
|
||
@Override
|
||
public void handleMessage(Message msg) {
|
||
switch (msg.what) {
|
||
case WHAT_PK_WAIT_RECEIVE:
|
||
onApplyPkWait();
|
||
break;
|
||
case WHAT_PK_WAIT_SEND:
|
||
onSendPkWait();
|
||
break;
|
||
case WHAT_PK_TIME:
|
||
changePkTime();
|
||
break;
|
||
|
||
}
|
||
}
|
||
};
|
||
|
||
}
|
||
|
||
public LiveRyLinkMicPkPresenter(Context context, LivePushRyViewHolder linkMicViewHolder, boolean isAnchor, View root) {
|
||
mContext = context;
|
||
mIsAnchor = isAnchor;
|
||
mRoot = root;
|
||
mPkContainer = linkMicViewHolder.getPkContainer();
|
||
livePushRyViewHolder = linkMicViewHolder;
|
||
mPkTimeString1 = "";
|
||
mPkTimeString2 = mContext.getString(R.string.live_pk_time_2);
|
||
//从本地取数据
|
||
String pkTime = CommonAppConfig.getInstance().getAnchorPkTime();
|
||
if (!pkTime.isEmpty()) {
|
||
try {
|
||
int time = Integer.parseInt(pkTime) * 60;
|
||
if (time > 0) {
|
||
PK_TIME_MAX = time;
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
Log.d("PK_TIME_MAX", "" + PK_TIME_MAX);
|
||
mHandler = new Handler() {
|
||
@Override
|
||
public void handleMessage(Message msg) {
|
||
switch (msg.what) {
|
||
case WHAT_PK_WAIT_RECEIVE:
|
||
onApplyPkWait();
|
||
break;
|
||
case WHAT_PK_WAIT_SEND:
|
||
onSendPkWait();
|
||
break;
|
||
case WHAT_PK_TIME2:
|
||
pkCountdownTimer();
|
||
break;
|
||
case WHAT_PK_TIME:
|
||
changePkTime();
|
||
break;
|
||
}
|
||
}
|
||
};
|
||
|
||
}
|
||
|
||
public void setSocketRyClient(SocketRyClient SocketRyClient) {
|
||
mSocketRyClient = SocketRyClient;
|
||
}
|
||
|
||
public void setLiveUid(String liveUid, String url) {
|
||
Log.e("liveUid", liveUid);
|
||
mLiveUid = liveUid;
|
||
mUrl = url;
|
||
}
|
||
|
||
|
||
/**
|
||
* 申请pk弹窗倒计时
|
||
*/
|
||
private void onApplyPkWait() {
|
||
mPkWaitCount--;
|
||
if (mPkWaitCount >= 0) {
|
||
if (mLinkMicWaitProgress != null) {
|
||
mLinkMicWaitProgress.setProgress(mPkWaitCount);
|
||
if (mHandler != null) {
|
||
mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_RECEIVE, getNextSecondTime());
|
||
}
|
||
}
|
||
} else {
|
||
if (mPkPopWindow != null) {
|
||
mPkPopWindow.dismiss();
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 发送pk申请后等待倒计时
|
||
*/
|
||
private void onSendPkWait() {
|
||
mPkSendWaitCount--;
|
||
if (mPkSendWaitCount >= 0) {
|
||
nextSendPkWaitCountDown();
|
||
} else {
|
||
hideSendPkWait();
|
||
if (mIsAnchor) {
|
||
((LiveRyAnchorActivity) mContext).setPkBtnVisible(true);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 进入下一次pk申请等待倒计时
|
||
*/
|
||
private void nextSendPkWaitCountDown() {
|
||
if (mLiveLinkMicPkViewHolder != null) {
|
||
mLiveLinkMicPkViewHolder.setPkWaitProgress(mPkSendWaitCount);
|
||
}
|
||
if (mHandler != null) {
|
||
mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_SEND, getNextSecondTime());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 隐藏pk申请等待
|
||
*/
|
||
private void hideSendPkWait() {
|
||
mPkSend = false;
|
||
if (mHandler != null) {
|
||
mHandler.removeMessages(WHAT_PK_WAIT_SEND);
|
||
}
|
||
if (mLiveLinkMicPkViewHolder != null) {
|
||
mLiveLinkMicPkViewHolder.setPkWaitProgressVisible(false);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 进入下一次pk倒计时
|
||
*/
|
||
int i = 0;
|
||
|
||
private void nextPkTimeCountDown(int is) {
|
||
|
||
if (mHandler != null) {
|
||
mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME, getNextSecondTime());
|
||
}
|
||
if (mLiveLinkMicPkViewHolder != null) {
|
||
String s = mIsPkEnd ? mPkTimeString2 : mPkTimeString1;
|
||
String s1 = StringUtil.getDurationText(mPkTimeCount * 1000);
|
||
Log.i("tag23333", mPkTimeCount + "mPkTimeCount" + s1 + "is" + is);
|
||
if (i == 1 && s1.equals("00:01")) {
|
||
s1 = "00:00";
|
||
i = 0;
|
||
}
|
||
if (rtcRoom != null) {
|
||
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 = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
|
||
livePushRyViewHolder.camera.setLayoutParams(params);
|
||
livePushRyViewHolder.mPreView1.setLayoutParams(params);
|
||
}
|
||
|
||
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]);
|
||
|
||
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"));
|
||
|
||
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) {
|
||
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* pk时间倒计时
|
||
*/
|
||
private void changePkTime() {
|
||
if (mPkTimeCount < 0) return;
|
||
mPkTimeCount--;
|
||
Log.i("vvvs", "mPkTimeCount:" + mPkTimeCount);
|
||
if (mPkTimeCount >= 0) {//
|
||
nextPkTimeCountDown(1);
|
||
if (mContext instanceof LiveAudienceActivity) {
|
||
((LiveAudienceActivity) mContext).setPkStatus(true);
|
||
}
|
||
} else {
|
||
if (mIsPkEnd) {
|
||
onLinkMicPkClose(0);
|
||
if (mIsAnchor) {
|
||
((LiveRyAnchorActivity) mContext).setPkBtnVisible(true);
|
||
}
|
||
if (mContext instanceof LiveAudienceActivity) {
|
||
((LiveAudienceActivity) mContext).setPkStatus(false);
|
||
}
|
||
//如果PK结束Im没有发送关闭PK的消息,倒计时结束自动关闭
|
||
// if (mLiveLinkMicPkViewHolder != null) {
|
||
// mLiveLinkMicPkViewHolder.removeFromParent();
|
||
// mLiveLinkMicPkViewHolder.release();
|
||
// }
|
||
// mLiveLinkMicPkViewHolder = null;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取下一秒钟的时间
|
||
*/
|
||
private long getNextSecondTime() {
|
||
long now = SystemClock.uptimeMillis();
|
||
return now + (1000 - now % 1000);
|
||
}
|
||
|
||
/**
|
||
* 发起主播PK申请
|
||
*/
|
||
public void applyLinkMicPk(String pkUid, String stream) {
|
||
if (mPkSend) {
|
||
ToastUtil.show(R.string.link_mic_apply_waiting);
|
||
return;
|
||
}
|
||
if (mIsPk) {
|
||
ToastUtil.show(R.string.live_link_mic_cannot_pk);
|
||
return;
|
||
}
|
||
mPkSend = true;
|
||
SocketRyLinkMicPkUtil.linkMicPkApply(mSocketRyClient, pkUid, stream);
|
||
ToastUtil.show(R.string.link_mic_apply_pk);
|
||
|
||
if (mLiveLinkMicPkViewHolder == null) {
|
||
mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer);
|
||
mLiveLinkMicPkViewHolder.addToParent();
|
||
mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor);
|
||
|
||
}
|
||
mLiveLinkMicPkViewHolder.setPkWaitProgressVisible(true);
|
||
mPkSendWaitCount = LINK_MIC_COUNT_MAX;
|
||
nextSendPkWaitCountDown();
|
||
if (mIsAnchor) {
|
||
((LiveRyAnchorActivity) mContext).setPkBtnVisible(false);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 主播与主播PK 主播收到其他主播发过来的多人PK申请的回调
|
||
*/
|
||
public void onLinkDRMicPkApply(UserBean u) {
|
||
Log.e("ry", "多人收到");
|
||
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());
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode rtcErrorCode) {
|
||
Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason());
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
/**
|
||
* 主播与主播PK 主播收到其他主播发过来的PK申请的回调
|
||
*/
|
||
public void onLinkMicPkApply(UserBean u, String stream, int by) {
|
||
Log.e("ry", u.getUserNiceName() + "单人收到" + u.getAvatar());
|
||
mApplyUid = u.getId();
|
||
mApplyUrl = u.getAvatar();
|
||
mApplyNmae = u.getUserNiceName();
|
||
if (by != 1) {
|
||
if (mIsApplyDialogShow == false) {
|
||
if (u.isRandomPk()) {
|
||
showPkDialog(u);
|
||
} else {
|
||
showApplyDialog(u);
|
||
}
|
||
}
|
||
} else {
|
||
isPK(u);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 主播与主播PK PK主播发过来的已经接受
|
||
*/
|
||
public void onLinkMicToPk(UserBean u) {
|
||
EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar()));
|
||
Log.e("eve", u.getId() + "");
|
||
/**
|
||
* 加入副房间
|
||
*
|
||
* 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间
|
||
*
|
||
* @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_`
|
||
* @param callBack 加入房间回调
|
||
* @group 房间管理
|
||
*/
|
||
RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START);
|
||
RCRTCEngine.getInstance().joinOtherRoom(u.getId(), new IRCRTCResultDataCallback<RCRTCOtherRoom>() {
|
||
@Override
|
||
public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) {
|
||
rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener);
|
||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||
public void run() {
|
||
//遍历远端用户列表
|
||
for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) {
|
||
//遍历远端用户发布的资源列表
|
||
for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) {
|
||
Log.e("ry", stream.getMediaType() + "类型");
|
||
if (stream.getMediaType() == RCRTCMediaType.VIDEO) {
|
||
//如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示
|
||
RCRTCVideoView remoteView = new RCRTCVideoView(contexts);
|
||
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
|
||
//todo 本demo只演示添加1个远端用户的视图
|
||
livePushRyViewHolder.mPreView1.removeAllViews();
|
||
remoteView.setScalingType(SCALE_ASPECT_FILL);
|
||
livePushRyViewHolder.mPreView1.addView(remoteView);
|
||
}
|
||
//如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅
|
||
inputStreamList.add(stream);
|
||
|
||
|
||
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) {
|
||
Log.w("PkDebug", "PK合流失败,rcrtcLiveInfo为空");
|
||
}
|
||
rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
Log.e("ry", "混成功13");
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
Log.e("ry", "混失败" + errorCode);
|
||
|
||
}
|
||
});
|
||
}
|
||
}
|
||
//开始订阅资源
|
||
rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
Log.i("ry", "订阅资源成功");
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode rtcErrorCode) {
|
||
Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason());
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode rtcErrorCode) {
|
||
Log.i("ry", "11111加入其他房间失败 :" + rtcErrorCode.getReason());
|
||
}
|
||
});
|
||
LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE);
|
||
LiveRyAnchorActivity.isDRPK = 1;
|
||
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 = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
|
||
livePushRyViewHolder.camera.setLayoutParams(params);
|
||
livePushRyViewHolder.mPreView1.setLayoutParams(params);
|
||
livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);
|
||
|
||
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();
|
||
|
||
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("g" + CommonAppConfig.getInstance().getUid(), 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("tx", "发送成功");
|
||
}
|
||
|
||
@Override
|
||
public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) {
|
||
Log.e("tx", "发送失败" + errorCode.getMessage());
|
||
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
private void isPK(UserBean bean) {
|
||
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 = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
|
||
livePushRyViewHolder.camera.setLayoutParams(params);
|
||
livePushRyViewHolder.mPreView1.setLayoutParams(params);
|
||
livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);
|
||
LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE);
|
||
LiveRyAnchorActivity.isDRPK = 1;
|
||
|
||
JSONObject msg1 = new JSONObject();
|
||
msg1.put("uid", CommonAppConfig.getInstance().getUid());
|
||
msg1.put("pkuid", CommonAppConfig.getInstance().getUid());
|
||
msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb());
|
||
msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName());
|
||
EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar()));
|
||
|
||
if (bean != null && bean.isRandomPk()) {
|
||
msg1.put("random_pk", bean.isRandomPk() ? 1 : 0);
|
||
msg1.put("is_ladders", bean.getRankPkImgUrl());
|
||
}
|
||
System.out.println("PK回执 = " + msg1.toString());
|
||
IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback<RCRTCOtherRoom>() {
|
||
@Override
|
||
public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) {
|
||
rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener);
|
||
ToastUtil.show("接受成功");
|
||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||
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,并添加到布局中显示
|
||
RCRTCVideoView remoteView = new RCRTCVideoView(contexts);
|
||
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
|
||
//todo 本demo只演示添加1个远端用户的视图
|
||
livePushRyViewHolder.mPreView1.removeAllViews();
|
||
remoteView.setScalingType(SCALE_ASPECT_FILL);
|
||
livePushRyViewHolder.mPreView1.addView(remoteView);
|
||
}
|
||
//如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅
|
||
inputStreamList.add(stream);
|
||
}
|
||
}
|
||
|
||
Log.e("ry", "asa" + inputStreamList.size());
|
||
//开始订阅资源
|
||
rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
Log.i("ry", "订阅资源成功");
|
||
List<RCRTCStream> streams = new ArrayList<>();
|
||
streams.add(RCRTCEngine.getInstance().getDefaultVideoStream());
|
||
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. 合流画布设置
|
||
rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
Log.e("ry", "混成功14");
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
Log.e("ry", "混失败" + errorCode);
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode rtcErrorCode) {
|
||
Log.i("ry", "订阅资源失败: " + rtcErrorCode);
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode rtcErrorCode) {
|
||
Log.e("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode);
|
||
Log.i("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode);
|
||
}
|
||
});
|
||
|
||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||
public void run() {
|
||
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);
|
||
EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid));
|
||
onLinkMicPkStart(mApplyUid, 2);
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
ToastUtil.show("接受失败");
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
//与用户连麦
|
||
public void setUserMic(String liveid) {
|
||
JSONObject msg1 = new JSONObject();
|
||
msg1.put("uid", CommonAppConfig.getInstance().getUid());
|
||
msg1.put("pkuid", CommonAppConfig.getInstance().getUid());
|
||
msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb());
|
||
msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName());
|
||
|
||
rtcRoom.getLocalUser().responseJoinOtherRoom(liveid, liveid, true, true, msg1.toString(), new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
RCRTCEngine.getInstance().joinOtherRoom(liveid, new IRCRTCResultDataCallback<RCRTCOtherRoom>() {
|
||
@Override
|
||
public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) {
|
||
rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener);
|
||
ToastUtil.show("接受成功");
|
||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||
public void run() {
|
||
Log.e("ry", liveid + "来了!!!!" + rcrtcOtherRoom.getRemoteUsers().size());
|
||
for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) {
|
||
//遍历远端用户发布的资源列表
|
||
for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) {
|
||
Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + rcrtcOtherRoom.getRemoteUsers().size());
|
||
if (stream.getMediaType() == RCRTCMediaType.AUDIO) {
|
||
//音频只需要订阅
|
||
inputStreamList.add(stream);
|
||
}
|
||
}
|
||
}
|
||
|
||
Log.e("ry", "asa" + inputStreamList.size());
|
||
//开始订阅资源
|
||
rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode rtcErrorCode) {
|
||
Log.e("ry", "订阅资源失败: " + rtcErrorCode);
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode rtcErrorCode) {
|
||
Log.e("ry", liveid + "加入其他房间失败 :" + rtcErrorCode);
|
||
Log.i("ry", liveid + "加入其他房间失败 :" + rtcErrorCode);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
ToastUtil.show("接受失败");
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 显示申请PK的弹窗
|
||
*/
|
||
private void showApplyDialog(UserBean u) {
|
||
mIsApplyDialogShow = true;
|
||
mAcceptPk = false;
|
||
View v = LayoutInflater.from(mContext).inflate(R.layout.dialog_link_mic_pk_wait, null);
|
||
mLinkMicWaitProgress = v.findViewById(R.id.pk_wait_progress);
|
||
v.findViewById(R.id.btn_refuse).setOnClickListener(this);
|
||
v.findViewById(R.id.btn_accept).setOnClickListener(this);
|
||
mPkWaitCount = LINK_MIC_COUNT_MAX;
|
||
mPkPopWindow = new PopupWindow(v, DpUtil.dp2px(280), ViewGroup.LayoutParams.WRAP_CONTENT, true);
|
||
mPkPopWindow.setBackgroundDrawable(new ColorDrawable());
|
||
mPkPopWindow.setOutsideTouchable(true);
|
||
mPkPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
||
@Override
|
||
public void onDismiss() {
|
||
if (mHandler != null) {
|
||
mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE);
|
||
}
|
||
if (mAcceptPk) {
|
||
isPK(u);
|
||
} else {
|
||
if (mPkWaitCount < 0) {
|
||
rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() {
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onSuccess() {
|
||
final SocketSendBean msg1 = new SocketSendBean()
|
||
.param("_method_", SOCKET_LINK_MIC_PK)
|
||
.param("action", 8);
|
||
msg1.create();
|
||
|
||
String targetId = u.getId();
|
||
Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE;
|
||
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", "发送失敗" + u.getId());
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
}
|
||
mApplyUid = null;
|
||
mApplyStream = null;
|
||
}
|
||
mIsApplyDialogShow = false;
|
||
mLinkMicWaitProgress = null;
|
||
mPkPopWindow = null;
|
||
}
|
||
});
|
||
mPkPopWindow.showAtLocation(mRoot, Gravity.CENTER, 0, 0);
|
||
if (mHandler != null) {
|
||
mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_RECEIVE, getNextSecondTime());
|
||
}
|
||
}
|
||
|
||
|
||
public static Bitmap fromText(float textSize, String text) {
|
||
Paint paint = new Paint();
|
||
paint.setTextSize(textSize);
|
||
paint.setTextAlign(Paint.Align.LEFT);
|
||
paint.setColor(Color.BLACK);
|
||
|
||
Paint.FontMetricsInt fm = paint.getFontMetricsInt();
|
||
int width = (int) paint.measureText(text);
|
||
int height = fm.descent - fm.ascent;
|
||
|
||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||
Canvas canvas = new Canvas(bitmap);
|
||
canvas.drawText(text, 0, fm.leading - fm.ascent, paint);
|
||
canvas.save();
|
||
|
||
return bitmap;
|
||
}
|
||
|
||
private String TAG = "多人PK";
|
||
|
||
/**
|
||
* 退出多人PK
|
||
*/
|
||
public void leaveDRRoom() {
|
||
//清理PK上面对方的头像
|
||
EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", ""));
|
||
Log.e("ry", "退出多人OKKK" + inputStreamList.size());
|
||
isDRPK = 0;
|
||
runOnUiThread(new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
if (btn_close != null) {
|
||
btn_close.setVisibility(View.GONE);
|
||
}
|
||
}
|
||
});
|
||
|
||
for (int i = 0; i < inputStreamList.size(); i++) {
|
||
Log.e("ry", "退出多人ID" + inputStreamList.get(i).getUserId());
|
||
//退出副房间
|
||
RCRTCEngine.getInstance().leaveOtherRoom(inputStreamList.get(i).getUserId(), true, new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
Log.e("ry", "退出多人成功");
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode rtcErrorCode) {
|
||
Log.e("ry", "退出多人失败" + rtcErrorCode);
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
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 = 720;
|
||
int height = 1280;
|
||
normal.setWidth(width); //视频宽
|
||
normal.setHeight(height); //视频高
|
||
normal.setFps(fps); //视频帧率
|
||
|
||
//2. 合流画布设置
|
||
//(请参照画布和声音配置示例代码)
|
||
//3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高
|
||
ArrayList<RCRTCMixConfig.CustomLayoutList.CustomLayout> list = new ArrayList<>();
|
||
config.setCustomLayouts(list);
|
||
//user1的视频流
|
||
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
|
||
list.add(videoLayout1);
|
||
videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video
|
||
videoLayout1.setX(0); //X 坐标
|
||
videoLayout1.setY(0); //Y 坐标
|
||
videoLayout1.setWidth(720); // 视频窗口的宽
|
||
videoLayout1.setHeight(1280); // 视频窗口的高
|
||
//2. 合流画布设置
|
||
if (rcrtcLiveInfo != null) {
|
||
rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
Log.e("ry", "混成功15");
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
Log.e("ry", "混失败" + errorCode);
|
||
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
leaveHandler.post(leaveRunnable);
|
||
|
||
}
|
||
|
||
private Handler leaveHandler = new Handler(Looper.getMainLooper());
|
||
private Runnable leaveRunnable = new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
//恢复全屏画面
|
||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||
params.topMargin = 0;
|
||
livePushRyViewHolder.camera.setLayoutParams(params);
|
||
livePushRyViewHolder.dr_pk_view.setVisibility(View.GONE);
|
||
inputStreamList.clear();
|
||
inputStreamList1.clear();
|
||
//删除之前其他主播的画面
|
||
livePushRyViewHolder.dr1_preview.removeAllViews();
|
||
livePushRyViewHolder.dr3_preview.removeAllViews();
|
||
livePushRyViewHolder.cameraPreview3.removeAllViews();
|
||
leaveHandler.removeCallbacks(leaveRunnable);
|
||
livePushRyViewHolder.timeTitle.setVisibility(View.GONE);
|
||
livePushRyViewHolder.mPreView.removeView(detailsView1);
|
||
livePushRyViewHolder.cameraPreview3.setVisibility(View.GONE);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 随机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;
|
||
|
||
@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;
|
||
}
|
||
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();
|
||
}
|
||
|
||
private void refusePk(UserBean u) {
|
||
IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra_randm_pk", new IRCRTCResultCallback() {
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onSuccess() {
|
||
final SocketSendBean msg1 = new SocketSendBean()
|
||
.param("_method_", SOCKET_LINK_MIC_PK)
|
||
// .param("randomPk",u.isRandomPk()+"")
|
||
.param("action", 3);
|
||
msg1.create();
|
||
|
||
String targetId = u.getId();
|
||
Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE;
|
||
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", "发送失敗" + u.getId());
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
LiveNetManager.get(mContext).setBanRandomPK(null);
|
||
}
|
||
|
||
/**
|
||
* 显示申请多人PK的弹窗
|
||
*/
|
||
private void showDRApplyDialog(UserBean u) {
|
||
mApplyUid = u.getId();
|
||
mIsApplyDialogShow = true;
|
||
mAcceptPk = false;
|
||
View v = LayoutInflater.from(mContext).inflate(R.layout.dialog_link_mic_pk_wait, null);
|
||
mLinkMicWaitProgress = v.findViewById(R.id.pk_wait_progress);
|
||
v.findViewById(R.id.btn_refuse).setOnClickListener(this);
|
||
v.findViewById(R.id.btn_accept).setOnClickListener(this);
|
||
mPkWaitCount = LINK_MIC_COUNT_MAX;
|
||
mPkPopWindow = new PopupWindow(v, DpUtil.dp2px(280), ViewGroup.LayoutParams.WRAP_CONTENT, true);
|
||
mPkPopWindow.setBackgroundDrawable(new ColorDrawable());
|
||
mPkPopWindow.setOutsideTouchable(true);
|
||
mPkPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
||
@Override
|
||
public void onDismiss() {
|
||
if (mHandler != null) {
|
||
mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE);
|
||
}
|
||
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() {
|
||
|
||
@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;
|
||
IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, agree, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
if (finalAgree == true) {
|
||
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);
|
||
|
||
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) {
|
||
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
ToastUtil.show("接受失败");
|
||
}
|
||
});
|
||
} else {
|
||
ToastUtil.show(msg);
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
|
||
}
|
||
}
|
||
});
|
||
|
||
|
||
} else {
|
||
if (mPkWaitCount < 0) {
|
||
IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() {
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onSuccess() {
|
||
final SocketSendBean msg1 = new SocketSendBean()
|
||
.param("_method_", SOCKET_LINK_MIC_PK)
|
||
.param("action", 8);
|
||
msg1.create();
|
||
|
||
String targetId = u.getId();
|
||
Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE;
|
||
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", "发送失敗" + mApplyUid);
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
} else {
|
||
IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() {
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onSuccess() {
|
||
final SocketSendBean msg1 = new SocketSendBean()
|
||
.param("_method_", SOCKET_LINK_MIC_PK)
|
||
.param("action", 3);
|
||
msg1.create();
|
||
|
||
String targetId = u.getId();
|
||
Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE;
|
||
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", "发送失敗");
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
mApplyUid = null;
|
||
mApplyStream = null;
|
||
}
|
||
mIsApplyDialogShow = false;
|
||
mLinkMicWaitProgress = null;
|
||
mPkPopWindow = null;
|
||
}
|
||
});
|
||
mPkPopWindow.showAtLocation(mRoot, Gravity.CENTER, 0, 0);
|
||
if (mHandler != null) {
|
||
mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_RECEIVE, getNextSecondTime());
|
||
}
|
||
}
|
||
|
||
|
||
//多人PK接受申请画 加入副房间
|
||
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);
|
||
}
|
||
|
||
Log.e("ry", "多人接受成功" + mApplyUid);
|
||
ToastUtil.show("接受成功");
|
||
//遍历远端用户列表
|
||
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(R.string.net_error);
|
||
}
|
||
});
|
||
|
||
} 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());
|
||
}
|
||
});
|
||
//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);
|
||
|
||
}
|
||
});
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode rtcErrorCode) {
|
||
Log.e("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode);
|
||
Log.i("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode);
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 多人PK PK主播发过来的已经接受
|
||
*/
|
||
public void onDRLinkMicToPk(String u) {
|
||
Log.e("eve", 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, new IRCRTCResultDataCallback<RCRTCOtherRoom>() {
|
||
@Override
|
||
public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) {
|
||
rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener);
|
||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||
public void run() {
|
||
|
||
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);
|
||
}
|
||
|
||
//遍历远端用户列表
|
||
for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) {
|
||
//遍历远端用户发布的资源列表
|
||
for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) {
|
||
Log.e("ry111", stream.getMediaType() + "");
|
||
if (stream.getMediaType() == RCRTCMediaType.VIDEO) {
|
||
if (inputStreamList.size() == 0) {
|
||
livePushRyViewHolder.dr1_preview.setVisibility(View.VISIBLE);
|
||
//如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示
|
||
RCRTCVideoView remoteView = new RCRTCVideoView(contexts);
|
||
((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(u, 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(u));
|
||
textPkName2.setText(data.getUserNicename());
|
||
livePushRyViewHolder.dr1_preview.addView(detailsView2);
|
||
detailsLinearLayout2.setVisibility(View.VISIBLE);
|
||
linearGrade2.setVisibility(View.GONE);
|
||
}
|
||
|
||
@Override
|
||
public void onError(String error) {
|
||
|
||
}
|
||
});
|
||
} else if (inputStreamList.size() == 1) {
|
||
livePushRyViewHolder.dr3_preview.setVisibility(View.VISIBLE);
|
||
//如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示
|
||
RCRTCVideoView remoteView = new RCRTCVideoView(contexts);
|
||
((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(u, 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(u);
|
||
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(contexts);
|
||
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
|
||
//todo 本demo只演示添加1个远端用户的视图
|
||
livePushRyViewHolder.cameraPreview3.removeAllViews();
|
||
remoteView.setScalingType(SCALE_ASPECT_FILL);
|
||
livePushRyViewHolder.cameraPreview3.addView(remoteView);
|
||
|
||
LiveNetManager.get(mContext).getLiveInfo(u, 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(u);
|
||
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());
|
||
}
|
||
});
|
||
|
||
//2. 合流画布设置
|
||
rcrtcLiveInfo.setMixConfig(create_Custom_MixConfig(false, inputStreamList), new IRCRTCResultCallback() {
|
||
@Override
|
||
public void onSuccess() {
|
||
Log.e("ry", inputStreamList.size() + "混成功" + u);
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
Log.e("ry", "混失败" + errorCode);
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode rtcErrorCode) {
|
||
Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason());
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 创建自定义合流布局配置
|
||
*
|
||
* @param isCrop 是否裁减画布
|
||
* @param streams 必须为视频流列表
|
||
* @return
|
||
*/
|
||
private RCRTCMixConfig create_Custom_MixConfig(boolean isCrop, List<RCRTCInputStream> streams) {
|
||
Log.e("视频合流", streams.toString());
|
||
Log.e("视频合流", "视频长度:" + streams.size());
|
||
RCRTCMixConfig config = new RCRTCMixConfig();
|
||
//1. 设置自定义合流布局模式
|
||
config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.CUSTOM);
|
||
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); //视频帧率
|
||
|
||
//2. 合流画布设置
|
||
//(请参照画布和声音配置示例代码)
|
||
//3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高
|
||
ArrayList<RCRTCMixConfig.CustomLayoutList.CustomLayout> list = new ArrayList<>();
|
||
|
||
if (streams.size() == 1) {
|
||
//user1的视频流
|
||
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
|
||
videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video
|
||
videoLayout1.setX(0); //X 坐标
|
||
videoLayout1.setY(0); //Y 坐标
|
||
videoLayout1.setWidth(480); // 视频窗口的宽
|
||
videoLayout1.setHeight(720); // 视频窗口的高
|
||
list.add(videoLayout1);
|
||
|
||
//user2的视频流
|
||
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
|
||
videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video
|
||
videoLayout2.setX(480); //X 坐标
|
||
videoLayout2.setY(0); //Y 坐标
|
||
videoLayout2.setWidth(480); // 视频窗口的宽
|
||
videoLayout2.setHeight(720); // 视频窗口的高
|
||
list.add(videoLayout2);
|
||
|
||
} else if (streams.size() == 2) {
|
||
//user1的视频流
|
||
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
|
||
list.add(videoLayout1);
|
||
videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video
|
||
videoLayout1.setX(0); //X 坐标
|
||
videoLayout1.setY(0); //Y 坐标
|
||
videoLayout1.setWidth(480); // 视频窗口的宽
|
||
videoLayout1.setHeight(720); // 视频窗口的高
|
||
|
||
//user2的视频流
|
||
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
|
||
videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video
|
||
videoLayout2.setX(480); //X 坐标
|
||
videoLayout2.setY(0); //Y 坐标
|
||
videoLayout2.setWidth(480); // 视频窗口的宽
|
||
videoLayout2.setHeight(360); // 视频窗口的高
|
||
list.add(videoLayout2);
|
||
|
||
//user3的视频流
|
||
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout3 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
|
||
videoLayout3.setVideoStream(streams.get(1)); // RCRTCStream#MediaType 必须是Video
|
||
videoLayout3.setX(480); //X 坐标
|
||
videoLayout3.setY(360); //Y 坐标
|
||
videoLayout3.setWidth(480); // 视频窗口的宽
|
||
videoLayout3.setHeight(360); // 视频窗口的高
|
||
list.add(videoLayout3);
|
||
|
||
} else if (streams.size() == 3) {
|
||
//user1的视频流
|
||
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
|
||
videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video
|
||
videoLayout1.setX(0); //X 坐标
|
||
videoLayout1.setY(0); //Y 坐标
|
||
videoLayout1.setWidth(480); // 视频窗口的宽
|
||
videoLayout1.setHeight(720); // 视频窗口的高
|
||
list.add(videoLayout1);
|
||
|
||
//user2的视频流
|
||
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
|
||
videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video
|
||
videoLayout2.setX(480); //X 坐标
|
||
videoLayout2.setY(0); //Y 坐标
|
||
videoLayout2.setWidth(480); // 视频窗口的宽
|
||
videoLayout2.setHeight(360); // 视频窗口的高
|
||
list.add(videoLayout2);
|
||
|
||
//user3的视频流
|
||
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout3 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
|
||
videoLayout3.setVideoStream(streams.get(1)); // RCRTCStream#MediaType 必须是Video
|
||
videoLayout3.setX(480); //X 坐标
|
||
videoLayout3.setY(360); //Y 坐标
|
||
videoLayout3.setWidth(480); // 视频窗口的宽
|
||
videoLayout3.setHeight(360); // 视频窗口的高
|
||
list.add(videoLayout3);
|
||
|
||
//user3的视频流
|
||
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout4 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
|
||
videoLayout4.setVideoStream(streams.get(2)); // RCRTCStream#MediaType 必须是Video
|
||
videoLayout4.setX(0); //X 坐标
|
||
videoLayout4.setY(360); //Y 坐标
|
||
videoLayout4.setWidth(480); // 视频窗口的宽
|
||
videoLayout4.setHeight(360); // 视频窗口的高
|
||
list.add(videoLayout4);
|
||
}
|
||
config.setCustomLayouts(list);
|
||
return config;
|
||
}
|
||
|
||
@Override
|
||
public void onClick(View v) {
|
||
int i = v.getId();
|
||
if (i == R.id.btn_refuse) {
|
||
refuseLinkMic();
|
||
|
||
} else if (i == R.id.btn_accept) {
|
||
acceptLinkMic();
|
||
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 拒绝PK
|
||
*/
|
||
private void refuseLinkMic() {
|
||
if (mPkPopWindow != null) {
|
||
mPkPopWindow.dismiss();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 接受PK
|
||
*/
|
||
private void acceptLinkMic() {
|
||
mAcceptPk = true;
|
||
if (mPkPopWindow != null) {
|
||
mPkPopWindow.dismiss();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* pk 进度发送变化
|
||
*
|
||
* @param leftGift
|
||
* @param rightGift
|
||
*/
|
||
public void onPkProgressChanged(long leftGift, long rightGift, LivePKUserListBean bean) {
|
||
if (mLiveLinkMicPkViewHolder != null) {
|
||
mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 进房间的时候PK开始
|
||
*/
|
||
public void onEnterRoomPkStart(String pkUid, long leftGift, long rightGift, int pkTime, LivePKUserListBean bean) {
|
||
mIsPk = true;
|
||
mIsPkEnd = false;
|
||
mPkUid = pkUid;
|
||
mApplyUid = null;
|
||
mApplyStream = null;
|
||
if (mLiveLinkMicPkViewHolder == null) {
|
||
mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer);
|
||
mLiveLinkMicPkViewHolder.addToParent();
|
||
mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor);
|
||
|
||
}
|
||
mLiveLinkMicPkViewHolder.showTime();
|
||
mLiveLinkMicPkViewHolder.onEnterRoomPkStart();
|
||
mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean);
|
||
mPkTimeCount = pkTime;
|
||
Log.d("mPkTimeCount1", "" + mPkTimeCount + ";mPkTimeFromServer=" + mPkTimeFromServer);
|
||
mPkTimeFromServer = pkTime;
|
||
nextPkTimeCountDown(2);
|
||
}
|
||
|
||
/**
|
||
* 修改最终PK数据
|
||
*
|
||
* @param leftGift 左边数据
|
||
* @param rightGift 右边数据
|
||
* @param bean 排位数据
|
||
*/
|
||
public void onPkProgressEnd(long leftGift, long rightGift, LivePKUserListBean bean) {
|
||
if (mLiveLinkMicPkViewHolder != null) {
|
||
mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean, true);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 进房间的时候懲罰开始
|
||
*/
|
||
public void onEnterRoomCFStart(String pkUid, long leftGift, long rightGift, int pkTime, LivePKUserListBean bean) {
|
||
mIsPk = true;
|
||
mIsPkEnd = true;
|
||
mPkUid = pkUid;
|
||
mApplyUid = null;
|
||
mApplyStream = null;
|
||
if (mLiveLinkMicPkViewHolder == null) {
|
||
mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer);
|
||
mLiveLinkMicPkViewHolder.addToParent();
|
||
mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor);
|
||
|
||
}
|
||
mLiveLinkMicPkViewHolder.showTime();
|
||
// -1自己的主播输 0平 1自己的主播赢
|
||
int p = 0;
|
||
if (leftGift < rightGift) {
|
||
p = -1;
|
||
} else if (leftGift > rightGift) {
|
||
p = 1;
|
||
} else if (leftGift == rightGift) {
|
||
p = 0;
|
||
}
|
||
mLiveLinkMicPkViewHolder.new_end(p);
|
||
|
||
mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean);
|
||
mPkTimeCount = pkTime;
|
||
Log.d("mPkTimeCount1", "" + mPkTimeCount + ";mPkTimeFromServer=" + mPkTimeFromServer);
|
||
// mPkTimeFromServer=pkTime;
|
||
//恢复播放画面
|
||
nextPkTimeCountDown(3);
|
||
}
|
||
|
||
|
||
/**
|
||
* 主播与主播PK 所有人收到PK开始的回调
|
||
*/
|
||
public void onLinkMicPkStart(String pkUid, int i) {
|
||
Log.d("tag", i + "mPkTimeCount2");
|
||
mIsPk = true;
|
||
hideSendPkWait();
|
||
mIsPkEnd = false;
|
||
oldmPkUid = pkUid;
|
||
mPkUid = pkUid;
|
||
mApplyUid = null;
|
||
mApplyStream = null;
|
||
if (mLiveLinkMicPkViewHolder == null) {
|
||
mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer);
|
||
mLiveLinkMicPkViewHolder.addToParent();
|
||
mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor);
|
||
if (mContext instanceof LiveAudienceActivity) {
|
||
((LiveAudienceActivity) mContext).getmLivePlayViewHolder().setPkview();
|
||
}
|
||
|
||
}
|
||
mLiveLinkMicPkViewHolder.startAnim();
|
||
EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(pkUid));
|
||
mLiveLinkMicPkViewHolder.showTime();
|
||
mPkTimeCount = 100;
|
||
nextPkTimeCountDown(2);
|
||
if (mIsAnchor) {
|
||
((LiveRyAnchorActivity) mContext).setPkBtnVisible(false);
|
||
mPkTimeCount = PK_TIME_MAX;
|
||
|
||
} else {
|
||
// mPkTimeCount=mPkTimeFromServer;
|
||
mPkTimeCount = PK_TIME_MAX;
|
||
}
|
||
Log.d("mPkTimeCount2", "" + mPkTimeCount + ";mPkTimeFromServer=" + mPkTimeFromServer);
|
||
}
|
||
|
||
|
||
/**
|
||
* 主播与主播PK PK结果的回调
|
||
*/
|
||
int s1 = 0;
|
||
|
||
public void onLinkMicPkEnd(String winUid) {
|
||
Log.i("收", "9");
|
||
|
||
if (mIsPkEnd) {
|
||
return;
|
||
}
|
||
mIsPkEnd = true;
|
||
if (mHandler != null) {
|
||
mHandler.removeMessages(WHAT_PK_TIME);
|
||
}
|
||
if (mLiveLinkMicPkViewHolder != null) {
|
||
if (!TextUtils.isEmpty(winUid)) {
|
||
if ("0".equals(winUid)) {
|
||
mLiveLinkMicPkViewHolder.end(0);
|
||
mLiveLinkMicPkViewHolder.hideTime();
|
||
if (mHandler != null) {
|
||
mHandler.postDelayed(new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
onLinkMicPkClose(0);
|
||
if (mIsAnchor) {
|
||
((LiveRyAnchorActivity) mContext).setPkBtnVisible(true);
|
||
}
|
||
}
|
||
}, 3000);
|
||
}
|
||
} else {
|
||
Log.e("ry1", winUid + "result");
|
||
if (winUid.equals(mLiveUid)) {
|
||
mLiveLinkMicPkViewHolder.end(1);
|
||
} else {
|
||
mLiveLinkMicPkViewHolder.end(-1);
|
||
}
|
||
mPkTimeCount = PK_TIME_MAX_2;//进入惩罚时间
|
||
nextPkTimeCountDown(5);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 主播与主播PK 断开连麦PK的回调
|
||
*/
|
||
public void onLinkMicPkClose(int i) {
|
||
Log.e("ry",mPkUid+"aaaaqwqw"+i);
|
||
|
||
PKing = false;
|
||
LiveRyAnchorActivity.isDRPK = 0;
|
||
|
||
// //恢复播放画面
|
||
if (i == 1) {
|
||
runOnUiThread(new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
if (btn_close != null) {
|
||
btn_close.setVisibility(View.GONE);
|
||
}
|
||
}
|
||
});
|
||
// inputStreamList.clear();
|
||
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 = 720;
|
||
int height = 1280;
|
||
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", "混成功16");
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(RTCErrorCode errorCode) {
|
||
Log.e("ry", "混失败" + errorCode);
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
runOnUiThread(new Runnable() {
|
||
public void run() {
|
||
// try {
|
||
// Thread.sleep(4000);
|
||
if (mContext instanceof LiveAudienceActivity && LiveAudienceActivity.getmLivePlayViewHolder() != null) {
|
||
LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview();
|
||
}
|
||
// } catch (InterruptedException e) {
|
||
// e.printStackTrace();
|
||
// }
|
||
}
|
||
});
|
||
|
||
}
|
||
if (mHandler != null) {
|
||
mHandler.removeCallbacksAndMessages(null);
|
||
}
|
||
if (mPkPopWindow != null) {
|
||
mPkPopWindow.dismiss();
|
||
}
|
||
mPkPopWindow = null;
|
||
mIsPk = false;
|
||
mIsPkEnd = false;
|
||
hideSendPkWait();
|
||
mPkUid = null;
|
||
mApplyUid = null;
|
||
mApplyStream = null;
|
||
if (mLiveLinkMicPkViewHolder != null) {
|
||
mLiveLinkMicPkViewHolder.removeFromParent();
|
||
mLiveLinkMicPkViewHolder.release();
|
||
}
|
||
mLiveLinkMicPkViewHolder = null;
|
||
}
|
||
|
||
/**
|
||
* 主播与主播Pk 对方主播拒绝Pk的回调
|
||
*/
|
||
public void onLinkMicPkRefuse() {
|
||
hideSendPkWait();
|
||
if (mIsAnchor) {
|
||
((LiveRyAnchorActivity) mContext).setPkBtnVisible(true);
|
||
}
|
||
ToastUtil.show(R.string.link_mic_refuse_pk);
|
||
}
|
||
|
||
/**
|
||
* 主播与主播Pk 对方主播无响应的回调
|
||
*/
|
||
public void onLinkMicPkNotResponse() {
|
||
hideSendPkWait();
|
||
if (mIsAnchor) {
|
||
((LiveRyAnchorActivity) mContext).setPkBtnVisible(true);
|
||
}
|
||
ToastUtil.show(R.string.link_mic_anchor_not_response_2);
|
||
}
|
||
|
||
/**
|
||
* 主播与主播Pk 对方主播正在忙的回调
|
||
*/
|
||
public void onLinkMicPkBusy() {
|
||
hideSendPkWait();
|
||
if (mIsAnchor) {
|
||
((LiveRyAnchorActivity) mContext).setPkBtnVisible(true);
|
||
}
|
||
ToastUtil.show(R.string.link_mic_anchor_busy_2);
|
||
}
|
||
|
||
|
||
public void release() {
|
||
if (mHandler != null) {
|
||
mHandler.removeCallbacksAndMessages(null);
|
||
}
|
||
mHandler = null;
|
||
mSocketRyClient = null;
|
||
if (mLiveLinkMicPkViewHolder != null) {
|
||
mLiveLinkMicPkViewHolder.release();
|
||
}
|
||
mLiveLinkMicPkViewHolder = null;
|
||
}
|
||
|
||
|
||
public void clearData() {
|
||
mIsApplyDialogShow = false;
|
||
mAcceptPk = false;
|
||
mIsPk = false;
|
||
mApplyUid = null;
|
||
mApplyStream = null;
|
||
mLiveUid = null;
|
||
mPkUid = null;
|
||
mPkWaitCount = 0;
|
||
mPkTimeCount = 0;
|
||
mIsPkEnd = false;
|
||
mPkSend = false;
|
||
mPkSendWaitCount = 0;
|
||
if (mHandler != null) {
|
||
mHandler.removeCallbacksAndMessages(null);
|
||
}
|
||
if (mLiveLinkMicPkViewHolder != null) {
|
||
mLiveLinkMicPkViewHolder.release();
|
||
mLiveLinkMicPkViewHolder.removeFromParent();
|
||
}
|
||
mLiveLinkMicPkViewHolder = null;
|
||
}
|
||
|
||
|
||
public void setSelfStream(String selfStream) {
|
||
mSelfStream = selfStream;
|
||
}
|
||
|
||
/**
|
||
* 更新Pk分数
|
||
*/
|
||
public void upDataPkScore(JSONArray pkScores, String uid, int time) {
|
||
String userID1 = (String) imageGrade1.getTag();
|
||
String userID2 = (String) imageGrade2.getTag();
|
||
String userID4 = (String) imageGrade4.getTag();
|
||
if (livePushRyViewHolder.timeTitle.getVisibility() == View.GONE) {
|
||
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) livePushRyViewHolder.timeTitle.getLayoutParams();
|
||
layoutParams.topMargin = DpUtil.dp2px(123);
|
||
livePushRyViewHolder.timeTitle.setLayoutParams(layoutParams);
|
||
livePushRyViewHolder.timeTitle.setVisibility(View.VISIBLE);
|
||
String pkTime = StringUtil.getDurationText(time * 1000);
|
||
livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime));
|
||
mPkTimeCount = time;
|
||
pkCountdownTimer();
|
||
}
|
||
int pkScoreSize = pkScores.size();
|
||
if (pkScoreSize == 3) {
|
||
linearGrade1.setVisibility(View.VISIBLE);
|
||
linearGrade2.setVisibility(View.VISIBLE);
|
||
linearGrade4.setVisibility(View.VISIBLE);
|
||
//拿到原始数据
|
||
for (int i = 0; i < pkScores.size(); i++) {
|
||
JSONObject score = pkScores.getJSONObject(i);
|
||
String userID = score.getString("id");
|
||
long userScore = score.getLong("score");
|
||
if (TextUtils.equals(userID, userID1)) {
|
||
textGrade1.setText(String.valueOf(userScore));
|
||
if (!score.containsKey("paiming")) {
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1);
|
||
} else {
|
||
int ranking = score.getIntValue("paiming");
|
||
switch (ranking) {
|
||
case 1:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1);
|
||
break;
|
||
case 2:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade1);
|
||
break;
|
||
case 3:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade1);
|
||
break;
|
||
case 4:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade1);
|
||
break;
|
||
}
|
||
}
|
||
} else if (TextUtils.equals(userID, userID2)) {
|
||
textGrade2.setText(String.valueOf(userScore));
|
||
if (!score.containsKey("paiming")) {
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2);
|
||
} else {
|
||
int ranking = score.getIntValue("paiming");
|
||
switch (ranking) {
|
||
case 1:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2);
|
||
break;
|
||
case 2:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade2);
|
||
break;
|
||
case 3:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade2);
|
||
break;
|
||
case 4:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade2);
|
||
break;
|
||
}
|
||
}
|
||
} else if (TextUtils.equals(userID, userID4)) {
|
||
textGrade4.setText(String.valueOf(userScore));
|
||
if (!score.containsKey("paiming")) {
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4);
|
||
} else {
|
||
int ranking = score.getIntValue("paiming");
|
||
switch (ranking) {
|
||
case 1:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4);
|
||
break;
|
||
case 2:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade4);
|
||
break;
|
||
case 3:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade4);
|
||
break;
|
||
case 4:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade4);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
String userID3 = (String) imageGrade3.getTag();
|
||
linearGrade1.setVisibility(View.VISIBLE);
|
||
linearGrade2.setVisibility(View.VISIBLE);
|
||
linearGrade3.setVisibility(View.VISIBLE);
|
||
linearGrade4.setVisibility(View.VISIBLE);
|
||
//拿到原始数据
|
||
for (int i = 0; i < pkScores.size(); i++) {
|
||
JSONObject score = pkScores.getJSONObject(i);
|
||
String userID = score.getString("id");
|
||
long userScore = score.getLong("score");
|
||
if (TextUtils.equals(userID, userID1)) {
|
||
textGrade1.setText(String.valueOf(userScore));
|
||
if (!score.containsKey("paiming")) {
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1);
|
||
} else {
|
||
int ranking = score.getIntValue("paiming");
|
||
switch (ranking) {
|
||
case 1:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1);
|
||
break;
|
||
case 2:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade1);
|
||
break;
|
||
case 3:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade1);
|
||
break;
|
||
case 4:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade1);
|
||
break;
|
||
}
|
||
}
|
||
} else if (TextUtils.equals(userID, userID2)) {
|
||
textGrade2.setText(String.valueOf(userScore));
|
||
if (!score.containsKey("paiming")) {
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2);
|
||
} else {
|
||
int ranking = score.getIntValue("paiming");
|
||
switch (ranking) {
|
||
case 1:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2);
|
||
break;
|
||
case 2:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade2);
|
||
break;
|
||
case 3:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade2);
|
||
break;
|
||
case 4:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade2);
|
||
break;
|
||
}
|
||
}
|
||
} else if (TextUtils.equals(userID, userID4)) {
|
||
textGrade4.setText(String.valueOf(userScore));
|
||
if (!score.containsKey("paiming")) {
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4);
|
||
} else {
|
||
int ranking = score.getIntValue("paiming");
|
||
switch (ranking) {
|
||
case 1:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4);
|
||
break;
|
||
case 2:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade4);
|
||
break;
|
||
case 3:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade4);
|
||
break;
|
||
case 4:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade4);
|
||
break;
|
||
}
|
||
}
|
||
} else if (TextUtils.equals(userID, userID3)) {
|
||
textGrade3.setText(String.valueOf(userScore));
|
||
if (!score.containsKey("paiming")) {
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade3);
|
||
} else {
|
||
int ranking = score.getIntValue("paiming");
|
||
switch (ranking) {
|
||
case 1:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade3);
|
||
break;
|
||
case 2:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade3);
|
||
break;
|
||
case 3:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade3);
|
||
break;
|
||
case 4:
|
||
ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade3);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* PK倒计时
|
||
*/
|
||
private void pkCountdownTimer() {
|
||
|
||
mPkTimeCount--;
|
||
if (mPkTimeCount > 0) {//
|
||
if (mHandler != null) {
|
||
String s1 = StringUtil.getDurationText(mPkTimeCount * 1000);
|
||
livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1));
|
||
mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME2, getNextSecondTime());
|
||
}
|
||
} else {
|
||
livePushRyViewHolder.timeTitle.setVisibility(View.GONE);
|
||
if (mHandler != null) {
|
||
mHandler.removeCallbacksAndMessages(null);
|
||
}
|
||
Bus.get().post(new LiveAudienceEvent()
|
||
.setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT));
|
||
// endDRGif();
|
||
if (DRInitiator) {
|
||
LiveNetManager.get(mContext).jieshuDRPK("" + IMLoginManager.get(mContext).getUserInfo().getId());
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
}
|