主播端多人PK

This commit is contained in:
18401019693 2023-02-03 16:22:48 +08:00
parent 1e595ec526
commit 3de7160538
7 changed files with 777 additions and 258 deletions

View File

@ -5,8 +5,6 @@ import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_DISABLE;
import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_ENABLE;
import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK;
import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK_RANDOM;
import static com.yunbao.live.views.AbsRyLivePushViewHolder.mPreView;
import static com.yunbao.live.views.LivePushRyViewHolder.dr_pk_view;
import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_dr_pk_nub;
import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_start_dr_pk;
import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_start_dr_pk_view;
@ -24,7 +22,6 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -66,11 +63,9 @@ import com.yunbao.common.utils.BitmapUtil;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DateFormatUtil;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.LogUtil;
import com.yunbao.common.utils.MicStatusManager;
import com.yunbao.common.utils.ScreenDimenUtil;
import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
@ -406,7 +401,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
if (code == 0) {
btn_start_dr_pk.setVisibility(View.VISIBLE);
dr_pk_view.setVisibility(View.VISIBLE);
// dr_pk_view.setVisibility(View.VISIBLE);
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LIVE_DRPK)
.param("action", 9)
@ -426,18 +421,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
@Override
public void onSuccess(Message message) {
isDRPK = 1;
btn_start_dr_pk_view.setVisibility(View.VISIBLE);
dr_pk_view.setVisibility(View.VISIBLE);
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);
dr_pk_view.setLayoutParams(params);
mPreView.setLayoutParams(params);
}
@Override
@ -1577,7 +1561,11 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
mLiveRyLinkMicPkPresenter.leaveDRRoom();
}
break;
case LEAVE_PK_SCORE:
if (mLiveRyLinkMicPkPresenter != null) {
mLiveRyLinkMicPkPresenter.upDataPkScore(event.getPkScores(), event.getUid(), event.getTime());
}
break;
case PK_TIME_COUNT:
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.endDRGif();

View File

@ -4,9 +4,7 @@ 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.isDRPK;
import static com.yunbao.live.views.AbsRyLivePushViewHolder.mPreView;
import static com.yunbao.live.views.LivePushRyViewHolder.contexts;
import static com.yunbao.live.views.LivePushRyViewHolder.dr_pk_view;
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;
@ -29,20 +27,24 @@ 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.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.event.FollowEvent;
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;
@ -108,6 +110,7 @@ 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分钟
@ -141,7 +144,14 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
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<>();
@ -224,6 +234,50 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
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 = WordUtil.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;
}
}
};
@ -313,7 +367,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
if (mLiveLinkMicPkViewHolder != null) {
String s = mIsPkEnd ? mPkTimeString2 : mPkTimeString1;
String s1 = StringUtil.getDurationText(mPkTimeCount * 1000);
Log.i("tag23333",mPkTimeCount+"mPkTimeCount"+s1+"is"+is);
Log.i("tag23333", mPkTimeCount + "mPkTimeCount" + s1 + "is" + is);
if (i == 1 && s1.equals("00:01")) {
s1 = "00:00";
i = 0;
@ -324,13 +378,13 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
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.mPreView.setLayoutParams(params);
LivePushRyViewHolder.mPreView1.setLayoutParams(params);
livePushRyViewHolder.camera.setLayoutParams(params);
livePushRyViewHolder.mPreView1.setLayoutParams(params);
}
Log.i("tts", s1);
mLiveLinkMicPkViewHolder.setTime(s + " " + s1);
if ( s1.equals("00:01") && mIsAnchor && !s.contains("懲罰")) {
if (s1.equals("00:01") && mIsAnchor && !s.contains("懲罰")) {
HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("addtime", "00:00")
@ -385,7 +439,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
* pk时间倒计时
*/
private void changePkTime() {
if (mPkTimeCount<0)return;
if (mPkTimeCount < 0) return;
mPkTimeCount--;
Log.i("vvvs", "mPkTimeCount:" + mPkTimeCount);
if (mPkTimeCount >= 0) {//
@ -490,35 +544,36 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);
//todo 本demo只演示添加1个远端用户的视图
LivePushRyViewHolder.dr1_preview.removeAllViews();
livePushRyViewHolder.mPreView1.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.dr1_preview.addView(remoteView);
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);
// 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);
// 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);
// 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);
@ -647,9 +702,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
RCRTCVideoView remoteView = new RCRTCVideoView(contexts);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
//todo 本demo只演示添加1个远端用户的视图
// LivePushRyViewHolder.mPreView1.removeAllViews();
livePushRyViewHolder.mPreView1.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.mPreView1.addView(remoteView);
livePushRyViewHolder.mPreView1.addView(remoteView);
}
//如果要订阅所有远端用户的流保存所有流信息方便后面统一订阅
inputStreamList.add(stream);
@ -727,9 +782,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
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.mPreView.setLayoutParams(params);
LivePushRyViewHolder.mPreView1.setLayoutParams(params);
LivePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);
livePushRyViewHolder.camera.setLayoutParams(params);
livePushRyViewHolder.mPreView1.setLayoutParams(params);
livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LINK_MIC_PK)
@ -771,9 +826,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
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.mPreView.setLayoutParams(params);
LivePushRyViewHolder.mPreView1.setLayoutParams(params);
LivePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);
livePushRyViewHolder.camera.setLayoutParams(params);
livePushRyViewHolder.mPreView1.setLayoutParams(params);
livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);
LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE);
LiveRyAnchorActivity.isDRPK = 1;
@ -807,9 +862,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
RCRTCVideoView remoteView = new RCRTCVideoView(contexts);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
//todo 本demo只演示添加1个远端用户的视图
// LivePushRyViewHolder.mPreView1.removeAllViews();
livePushRyViewHolder.mPreView1.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.mPreView1.addView(remoteView);
livePushRyViewHolder.mPreView1.addView(remoteView);
}
//如果要订阅所有远端用户的流保存所有流信息方便后面统一订阅
inputStreamList.add(stream);
@ -1070,7 +1125,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
/**
* 退出多人PK
*/
public static void leaveDRRoom() {
public void leaveDRRoom() {
//清理PK上面对方的头像
EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", ""));
@ -1143,25 +1198,31 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
}
}
new Handler(Looper.getMainLooper()).post(new Runnable() {
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;
mPreView.setLayoutParams(params);
dr_pk_view.setVisibility(View.GONE);
livePushRyViewHolder.camera.setLayoutParams(params);
livePushRyViewHolder.dr_pk_view.setVisibility(View.GONE);
inputStreamList.clear();
inputStreamList1.clear();
//删除之前其他主播的画面
LivePushRyViewHolder.dr1_preview.removeAllViews();
LivePushRyViewHolder.dr2_preview.removeAllViews();
LivePushRyViewHolder.dr3_preview.removeAllViews();
LivePushRyViewHolder.dr4_preview.removeAllViews();
}
});
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拒绝对话框
@ -1556,15 +1617,28 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
//把多人PK的View显示出来
if (dr_pk_view.getVisibility() == View.GONE) {
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);
dr_pk_view.setLayoutParams(params);
mPreView.setLayoutParams(params);
dr_pk_view.setVisibility(View.VISIBLE);
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);
@ -1577,37 +1651,99 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
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(contexts);
RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
//todo 本demo只演示添加1个远端用户的视图
LivePushRyViewHolder.dr1_preview.removeAllViews();
livePushRyViewHolder.dr1_preview.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.dr1_preview.addView(remoteView);
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) {
}
});
} else if (inputStreamList.size() == 1) {
livePushRyViewHolder.dr3_preview.setVisibility(View.VISIBLE);
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
RCRTCVideoView remoteView = new RCRTCVideoView(contexts);
RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
//todo 本demo只演示添加1个远端用户的视图
LivePushRyViewHolder.dr2_preview.removeAllViews();
livePushRyViewHolder.dr3_preview.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.dr2_preview.addView(remoteView);
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(contexts);
RCRTCVideoView remoteView = new RCRTCVideoView(mContext);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
//todo 本demo只演示添加1个远端用户的视图
LivePushRyViewHolder.dr3_preview.removeAllViews();
livePushRyViewHolder.cameraPreview3.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.dr3_preview.addView(remoteView);
} else if (inputStreamList.size() == 3) {
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
RCRTCVideoView remoteView = new RCRTCVideoView(contexts);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
//todo 本demo只演示添加1个远端用户的视图
LivePushRyViewHolder.dr4_preview.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.dr4_preview.addView(remoteView);
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);
}
@ -1673,6 +1809,31 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
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++) {
//遍历远端用户发布的资源列表
@ -1680,37 +1841,96 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
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();
livePushRyViewHolder.dr1_preview.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.dr1_preview.addView(remoteView);
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.dr2_preview.removeAllViews();
livePushRyViewHolder.dr3_preview.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.dr2_preview.addView(remoteView);
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.dr3_preview.removeAllViews();
livePushRyViewHolder.cameraPreview3.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.dr3_preview.addView(remoteView);
} else if (inputStreamList.size() == 3) {
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
RCRTCVideoView remoteView = new RCRTCVideoView(contexts);
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
//todo 本demo只演示添加1个远端用户的视图
LivePushRyViewHolder.dr4_preview.removeAllViews();
remoteView.setScalingType(SCALE_ASPECT_FILL);
LivePushRyViewHolder.dr4_preview.addView(remoteView);
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);
@ -1770,7 +1990,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
* @param streams 必须为视频流列表
* @return
*/
public static RCRTCMixConfig create_Custom_MixConfig(boolean isCrop, List<RCRTCInputStream> streams) {
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);
@ -1798,7 +2020,27 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
//(请参照画布和声音配置示例代码)
//3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准)设置每个视频流小窗口的坐标及宽高
ArrayList<RCRTCMixConfig.CustomLayoutList.CustomLayout> list = new ArrayList<>();
config.setCustomLayouts(list);
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);
@ -1808,52 +2050,62 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
videoLayout1.setWidth(480); // 视频窗口的宽
videoLayout1.setHeight(720); // 视频窗口的高
for (int i = 0; i < streams.size(); i++) {
Log.e("tttts,", "a" + i + "cccc" + streams.size());
Log.e("tttts", streams.get(i).getUserId() + "");
if (i == 0) {
//user2的视频流
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
list.add(videoLayout2);
videoLayout2.setVideoStream(streams.get(i)); // RCRTCStream#MediaType 必须是Video
videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video
videoLayout2.setX(480); //X 坐标
videoLayout2.setY(0); //Y 坐标
videoLayout2.setWidth(240); // 视频窗口的宽
videoLayout2.setWidth(480); // 视频窗口的宽
videoLayout2.setHeight(360); // 视频窗口的高
Log.e("ttt1112", "0" + "VS" + streams.get(i).getUserId());
} else if (i == 1) {
list.add(videoLayout2);
//user3的视频流
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout3 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
list.add(videoLayout3);
videoLayout3.setVideoStream(streams.get(i)); // RCRTCStream#MediaType 必须是Video
videoLayout3.setX(720); //X 坐标
videoLayout3.setY(0); //Y 坐标
videoLayout3.setWidth(240); // 视频窗口的宽
videoLayout3.setVideoStream(streams.get(1)); // RCRTCStream#MediaType 必须是Video
videoLayout3.setX(480); //X 坐标
videoLayout3.setY(360); //Y 坐标
videoLayout3.setWidth(480); // 视频窗口的宽
videoLayout3.setHeight(360); // 视频窗口的高
Log.e("ttt1112", "1" + "VS" + streams.get(i).getUserId());
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);
} else if (i == 2) {
//user3的视频流
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout4 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
list.add(videoLayout4);
videoLayout4.setVideoStream(streams.get(i)); // RCRTCStream#MediaType 必须是Video
videoLayout4.setX(480); //X 坐标
videoLayout4.setVideoStream(streams.get(2)); // RCRTCStream#MediaType 必须是Video
videoLayout4.setX(0); //X 坐标
videoLayout4.setY(360); //Y 坐标
videoLayout4.setWidth(240); // 视频窗口的宽
videoLayout4.setWidth(480); // 视频窗口的宽
videoLayout4.setHeight(360); // 视频窗口的高
Log.e("ttt1112", "2" + "VS" + streams.get(i).getUserId());
} else if (i == 3) {
//user3的视频流
RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout4 = new RCRTCMixConfig.CustomLayoutList.CustomLayout();
list.add(videoLayout4);
videoLayout4.setVideoStream(streams.get(i)); // RCRTCStream#MediaType 必须是Video
videoLayout4.setX(720); //X 坐标
videoLayout4.setY(360); //Y 坐标
videoLayout4.setWidth(240); // 视频窗口的宽
videoLayout4.setHeight(360); // 视频窗口的高
Log.e("ttt1112", "3" + "VS" + streams.get(i).getUserId());
}
}
config.setCustomLayouts(list);
return config;
}
@ -1886,7 +2138,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
if (mPkPopWindow != null) {
mPkPopWindow.dismiss();
}
}
/**
@ -1978,13 +2229,15 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer);
mLiveLinkMicPkViewHolder.addToParent();
mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor);
if (LiveAudienceActivity.getmLivePlayViewHolder() != null) {
LiveAudienceActivity.getmLivePlayViewHolder().setPkview();
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();
nextPkTimeCountDown(2);
if (mIsAnchor) {
((LiveRyAnchorActivity) mContext).setPkBtnVisible(false);
mPkTimeCount = PK_TIME_MAX;
@ -1993,7 +2246,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
// mPkTimeCount=mPkTimeFromServer;
mPkTimeCount = PK_TIME_MAX;
}
nextPkTimeCountDown(4);
Log.d("mPkTimeCount2", "" + mPkTimeCount + ";mPkTimeFromServer=" + mPkTimeFromServer);
}
@ -2164,6 +2416,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
if (mHandler != null) {
mHandler.removeCallbacksAndMessages(null);
}
mHandler = null;
mSocketRyClient = null;
if (mLiveLinkMicPkViewHolder != null) {
mLiveLinkMicPkViewHolder.release();
@ -2199,4 +2452,224 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
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();
}
}
}

View File

@ -3,8 +3,6 @@ package com.yunbao.live.socket;
import static com.blankj.utilcode.util.SnackbarUtils.dismiss;
import static com.blankj.utilcode.util.ViewUtils.runOnUiThread;
import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK;
import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.leaveDRRoom;
import static com.yunbao.live.views.LivePushRyViewHolder.dr_pk_view;
import static com.yunbao.live.views.LivePushRyViewHolder.rtcRoom;
import static com.yunbao.live.views.LiveRoomViewHolder.getIsHot;
@ -154,7 +152,6 @@ public class SocketRyClient {
public void processBroadcast(String socketMsg) {
L.e("收到socket--->" + socketMsg);
Log.i("SocketRyClient", "socketMsg" + socketMsg);
Log.i("SocketRyClient", "socketMsg" + socketMsg);
if (Constants.SOCKET_STOP_PLAY.equals(socketMsg)) {
@ -282,42 +279,58 @@ public class SocketRyClient {
}
//收到对方同意多人PK邀请
else if (action3 == 2) {
UserBean u = new UserBean();
// u.setUserNiceName(map.getString("uname"));
u.setId(map.getString("uid"));
mListener.onLinkDRMicPkApplyOk(u);
} else if (action3 == 6) {
// UserBean u = new UserBean();
//// u.setUserNiceName(map.getString("uname"));
// u.setId(map.getString("uid"));
// mListener.onLinkDRMicPkApplyOk(u);
} else if (action3 == 6) {//开始Pk
if (LiveRoomViewHolder.mHandler != null) {
LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null);
}
LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, map.getIntValue("drpk_time"));
// LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, map.getIntValue("drpk_time"));
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE)
.setPkScores(map.getJSONArray("userlist"))
.setUid(mLiveUid)
.setTime(map.getIntValue("drpk_time")));
if (livePushRyViewHolder == null) {
LiveAudienceActivity.getmLivePlayViewHolder().setPkview();
// LiveAudienceActivity.getmLivePlayViewHolder().setPkview();
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)
);
}
} else if (action3 == 5) {
// EventBus.getDefault().post(new LiveAudienceEvent()
// .setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT));
// endDRGif();
LiveRoomViewHolder.d_pk_view.setVisibility(View.GONE);
if (LiveRyAnchorActivity.mLiveAnchorViewHolder != null) {
dr_pk_view.setVisibility(View.GONE);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
params.topMargin = 0;
LivePushRyViewHolder.mPreView.setLayoutParams(params);
leaveDRRoom();
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.LEAVE_DR_ROOM));
isDRPK = 0;
} else {
LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview();
// LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview();
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW)
);
}
//創建了多人房間
} else if (action3 == 3) {
if (LiveAudienceActivity.getmLivePlayViewHolder() != null) {
/* if (LiveAudienceActivity.getmLivePlayViewHolder() != null) {
LiveAudienceActivity.getmLivePlayViewHolder().setPkview();
}
}*/
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)
);
isDRPK = 1;
} else if (action3 == 10) {
if (!map.getString("uid").equals(CommonAppConfig.getInstance().getUid())) {
LiveAudienceActivity.getmLivePlayViewHolder().setPkview();
// LiveAudienceActivity.getmLivePlayViewHolder().setPkview();
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)
);
}
}
@ -925,7 +938,12 @@ public class SocketRyClient {
mListener.onSendGift(receiveGiftBean);
}
if (map.getIntValue("drpk_status") == 1) {
LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, 0);
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE)
.setPkScores(map.getJSONArray("userlist"))
.setUid(mLiveUid)
.setTime(0));
// LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, 0);
}
}
@ -1075,16 +1093,8 @@ public class SocketRyClient {
break;
case 5://PK时候断开连麦的回调
if (rtcRoom != null) {
if (LivePushRyViewHolder.mPreView1 != null) {
LivePushRyViewHolder.mPreView1.removeAllViews();
LivePushRyViewHolder.mPreView1.setVisibility(View.GONE);
isDRPK = 0;
leaveDRRoom();
}
LivePushRyViewHolder.btn_close.setVisibility(View.GONE);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
params.topMargin = 0;
LivePushRyViewHolder.mPreView.setLayoutParams(params);
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.DISCONNEXT_PK_TIME));
//断开连麦
HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout")
.execute(new HttpCallback() {

View File

@ -32,9 +32,10 @@ public class AbsRyLivePushViewHolder extends AbsViewHolder implements ILivePushV
protected ViewGroup mLeftContainer;
protected ViewGroup mRightContainer;
protected ViewGroup mPkContainer;
public static FrameLayout mPreView,mPreView1,dr1_preview,dr2_preview,dr3_preview,dr4_preview;
public static ImageView leave;
public FrameLayout mPreView, mPreView1, cameraPreview3, dr1_preview, dr2_preview, dr3_preview, dr4_preview;
public ImageView leave;
protected boolean mOpenCamera;//是否选择了相机
public LinearLayout camera;
//倒计时
protected TextView mCountDownText;

View File

@ -102,11 +102,13 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
public TencentTRTCBeautyManager tencentTRTCBeautyManager;
public static Context contexts;
public static TextView btn_close;
public static LinearLayout dr_pk_view;
public LinearLayout dr_pk_view;
public static RCRTCRoom rtcRoom;
public static RCRTCLiveInfo rcrtcLiveInfo;
private ViewGroup liveActivityContainer;
public FrameLayout timeTitle;
public TextView textTime;
private TextView tv_avatarOther_name;
private ImageView avatarOther;
private LinearLayout goto_room_view;
@ -341,6 +343,8 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
userBean1.setUserNiceName("null");
userBean1.setAvatar("null");
}
mLiveRyLinkMicPkPresenter.onLinkMicToPk(userBean1);
mLiveRyLinkMicPkPresenter.onLinkMicPkStart(inviteeRoomId, 3);
//单人PK减掉次数
if (!RandomPkManager.getInstance().isRandomModel()) {
LiveNetManager.get(mContext).setFreePkNum(new com.yunbao.common.http.base.HttpCallback<HttpCallbackModel>() {
@ -398,14 +402,19 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
super.init();
Bus.getOn(this);
mPreView = (FrameLayout) findViewById(R.id.camera_preview);
camera = (LinearLayout) findViewById(R.id.camera);
mPreView1 = (FrameLayout) findViewById(R.id.camera_preview1);
cameraPreview3 = (FrameLayout) findViewById(R.id.camera_preview3);
dr1_preview = (FrameLayout) findViewById(R.id.dr1_preview);
dr2_preview = (FrameLayout) findViewById(R.id.dr2_preview);
dr3_preview = (FrameLayout) findViewById(R.id.dr3_preview);
dr4_preview = (FrameLayout) findViewById(R.id.dr4_preview);
leave = (ImageView) findViewById(R.id.leave);
dr_pk_view = (LinearLayout) findViewById(R.id.dr_pk_view);
timeTitle = (FrameLayout) findViewById(R.id.time_title);
textTime = (TextView) findViewById(R.id.text_time);
dr_pk_view.setVisibility(View.GONE);
cameraPreview3.setVisibility(View.GONE);
btn_close = (TextView) findViewById(R.id.btn_close);
tv_avatarOther_name = (TextView) findViewById(R.id.tv_avatarOther_name);
avatarOther = (ImageView) findViewById(R.id.avatarOther);
@ -450,6 +459,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
mPreView1.setVisibility(View.GONE);
inputStreamList.clear();
inputStreamList1.clear();
changeToBig();
}
});
}
@ -668,19 +678,28 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
params.width = mPreView.getWidth() / 2;
params.height = DpUtil.dp2px(250);
params.topMargin = DpUtil.dp2px(130);
mPreView.setLayoutParams(params);
camera.setLayoutParams(params);
}
}
@Override
public void changeToBig() {
if (mPreView != null) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mPreView.getLayoutParams();
if (camera != null) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) camera.getLayoutParams();
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
params.topMargin = 0;
mPreView.setLayoutParams(params);
camera.setLayoutParams(params);
}
if (mPreView1.getVisibility()==View.VISIBLE){
mPreView1.removeAllViews();
mPreView1.setVisibility(View.GONE);
inputStreamList.clear();
inputStreamList1.clear();
}
}
public void closeButtonGone(){
btn_close.setVisibility(View.GONE);
}
@Override

View File

@ -5,7 +5,6 @@ import static com.yunbao.live.activity.LiveRyAnchorActivity.PKing;
import static com.yunbao.live.activity.LiveRyAnchorActivity.pk_nub;
import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.START_MESSAGE;
import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.WISH_LIST_UPDATE;
import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.leaveDRRoom;
import android.content.Context;
import android.graphics.drawable.Drawable;
@ -149,7 +148,8 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder {
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
leaveDRRoom();
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.LEAVE_DR_ROOM));
PKing = false;
}

View File

@ -1,33 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="0dp"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/camera_preview3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<FrameLayout
android:id="@+id/camera_preview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
android:visibility="gone" />
<LinearLayout android:id="@+id/dr_pk_view"
<LinearLayout
android:id="@+id/dr_pk_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/camera_preview"
android:layout_marginTop="130dp"
android:orientation="vertical">
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:layout_width="wrap_content"
@ -37,17 +53,17 @@
<FrameLayout
android:id="@+id/dr1_preview"
android:layout_width="100dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@mipmap/live_icon_vacancy"/>
android:layout_weight="1"
android:background="@mipmap/live_icon_vacancy" />
<FrameLayout
android:id="@+id/dr2_preview"
android:layout_width="100dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@mipmap/live_icon_vacancy"/>
android:layout_weight="1"
android:background="@mipmap/live_icon_vacancy" />
</LinearLayout>
@ -59,24 +75,23 @@
<FrameLayout
android:id="@+id/dr3_preview"
android:layout_width="100dp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@mipmap/live_icon_vacancy"/>
android:background="@mipmap/live_icon_vacancy" />
<FrameLayout
android:id="@+id/dr4_preview"
android:layout_width="100dp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@mipmap/live_icon_vacancy"/>
android:background="@mipmap/live_icon_vacancy" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<FrameLayout
@ -85,24 +100,20 @@
android:layout_height="match_parent">
</FrameLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/layout_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical">
android:orientation="vertical"
android:visibility="gone">
<SurfaceView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
@ -112,9 +123,9 @@
android:layout_alignParentRight="true"
android:layout_marginTop="122dp"
android:layout_marginRight="9dp"
android:visibility="gone"
android:background="@drawable/bg_live_other_ico"
android:gravity="center">
android:gravity="center"
android:visibility="gone">
<RelativeLayout
android:layout_width="21dp"
@ -145,56 +156,54 @@
android:textSize="12sp" />
</LinearLayout>
<FrameLayout
android:id="@+id/pk_container"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_marginTop="130dp"
>
android:layout_marginTop="130dp">
<com.yunbao.live.custom.MyFrameLayout4
android:id="@+id/left_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
/>
android:layout_marginBottom="20dp" />
<com.yunbao.live.custom.MyFrameLayout4
android:id="@+id/right_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_marginBottom="20dp"
/>
android:layout_marginBottom="20dp" />
</FrameLayout>
<TextView android:id="@+id/btn_close"
<TextView
android:id="@+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_alignParentRight="true"
android:layout_marginTop="400dp"
android:layout_marginRight="8dp"
android:layout_alignParentRight="true"
android:background="@drawable/background_dedede"
android:paddingLeft="8dp"
android:paddingTop="5dp"
android:paddingRight="8dp"
android:paddingBottom="5dp"
android:text="結束連麥"
android:textSize="13sp"
android:visibility="gone"
android:textColor="@color/color_white"
android:background="@drawable/background_dedede"/>
android:textSize="13sp"
android:visibility="gone" />
<com.yunbao.live.custom.MyFrameLayout3
android:id="@+id/small_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="120dp"
app:mfl3_ratio="0.25"
/>
app:mfl3_ratio="0.25" />
<ImageView
@ -202,7 +211,26 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:scaleType="centerCrop"
android:src="@mipmap/zslk"
android:visibility="gone"
android:scaleType="centerCrop"/>
android:visibility="gone" />
<FrameLayout
android:id="@+id/time_title"
android:layout_width="60dp"
android:layout_height="16.67dp"
android:layout_centerHorizontal="true"
android:background="@mipmap/live_pk_time_bg"
android:visibility="gone">
<TextView
android:id="@+id/text_time"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/pk_time"
android:textColor="@color/white"
android:textSize="8sp" />
<!-- 详情-->
</FrameLayout>
</RelativeLayout>