From 7a26e81f67adcb6caa741ff09e524abe228ac3b5 Mon Sep 17 00:00:00 2001 From: 18142669586 <1669783059@qq.com> Date: Wed, 9 Aug 2023 14:13:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=9E=8D=E4=BA=91=E5=90=88?= =?UTF-8?q?=E6=B5=81=E4=B8=8D=E6=88=90=E5=8A=9F=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E9=80=80=E5=87=BA=E7=94=BB=E9=9D=A2=E6=9C=89=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presenter/LiveRyLinkMicPkPresenter.java | 394 +++++++++--------- .../live/views/LivePushRyViewHolder.java | 74 +++- 2 files changed, 272 insertions(+), 196 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index c7502c29e..e5f9130c8 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -1,5 +1,6 @@ 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; @@ -36,6 +37,7 @@ 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; @@ -594,46 +596,46 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { 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); //视频帧率 + 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()); - } + //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); + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); - } - }); - } else { - Log.w("PkDebug", "PK合流失败,rcrtcLiveInfo为空"); - } + } + }); + } else { + Log.w("PkDebug", "PK合流失败,rcrtcLiveInfo为空"); + } } @Override @@ -714,46 +716,45 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { inputStreamList.add(stream); - - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); + 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 videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); + mediaConfig.setVideoConfig(videoConfig); //大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); + 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); //视频帧率 + 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为空"); + //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"); } - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功13"); - } - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); - } - }); + } + }); } } //开始订阅资源 @@ -881,42 +882,42 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { Log.i("ry", "订阅资源成功"); List streams = new ArrayList<>(); streams.add(RCRTCEngine.getInstance().getDefaultVideoStream()); - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); + 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 videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); + mediaConfig.setVideoConfig(videoConfig); //大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); + 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); //视频帧率 + 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"); - } + //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 errorCode) { + Log.e("ry", "混失败" + errorCode); - } - }); + } + }); } @Override @@ -1128,76 +1129,84 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void leaveDRRoom() { //清理PK上面对方的头像 EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); - Log.e("ry", "退出多人OKKK" + inputStreamList.size()); isDRPK = 0; - if (btn_close != null) { - btn_close.setVisibility(View.GONE); - } + 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 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 videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); + mediaConfig.setVideoConfig(videoConfig); //大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); + 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); //视频帧率 + 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 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"); - } + //2. 合流画布设置 + //(请参照画布和声音配置示例代码) + //3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高 + ArrayList 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); + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); - } - }); + } + }); } @@ -1943,32 +1952,32 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - } + //开始订阅资源 + rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, 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", "订阅资源失败: " + rtcErrorCode.getReason()); + } + }); - //2. 合流画布设置 - rcrtcLiveInfo.setMixConfig(create_Custom_MixConfig(false, inputStreamList), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", inputStreamList.size() + "混成功" + u); - } + //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 errorCode) { + Log.e("ry", "混失败" + errorCode); - } - }); + } + }); } } @@ -2179,11 +2188,12 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { /** * 修改最终PK数据 - * @param leftGift 左边数据 + * + * @param leftGift 左边数据 * @param rightGift 右边数据 - * @param bean 排位数据 + * @param bean 排位数据 */ - public void onPkProgressEnd(long leftGift, long rightGift,LivePKUserListBean bean) { + public void onPkProgressEnd(long leftGift, long rightGift, LivePKUserListBean bean) { if (mLiveLinkMicPkViewHolder != null) { mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean, true); } @@ -2321,44 +2331,44 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { 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 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); + 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); //视频帧率 + 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"); - } + //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); + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); - } - }); - } + } + }); + } runOnUiThread(new Runnable() { public void run() { diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index de7b9d3dc..6554c3684 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -1,6 +1,7 @@ package com.yunbao.live.views; 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.LiveActivity.mLiveRyLinkMicPkPresenter; import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.inputStreamList; @@ -55,6 +56,7 @@ import com.yunbao.live.http.LiveHttpConsts; import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.momo.TencentTRTCBeautyManager; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; +import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketSendBean; import org.greenrobot.eventbus.EventBus; @@ -82,6 +84,10 @@ import cn.rongcloud.rtc.base.RCRTCRoomType; import cn.rongcloud.rtc.base.RTCErrorCode; import cn.rongcloud.rtc.core.CameraVideoCapturer; import cn.rongcloud.rtc.core.RendererCommon; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.message.TextMessage; /** * Created by cxf on 2018/10/7. @@ -116,7 +122,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX //修改上面主播的头像 @Subscribe(threadMode = ThreadMode.MAIN) public void onUPAnchorInfo(AnchorInfoEvent e) { - Log.i(TAG, "onUPAnchorInfo: "+e); + Log.i(TAG, "onUPAnchorInfo: " + e); if (e != null) { if (!e.isClear()) { tv_avatarOther_name.setText(e.getUserNiceName()); @@ -218,10 +224,54 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void run() { Log.e("ry", inviterRoomId + extra + "Request"); - UserBean userBean = new UserBean(); userBean.setId(inviterRoomId); - if (extra.equals(SOCKET_LIVE_DRPK)) { + //收到邀请这个时候正在PK或连麦中 自动拒绝对方 + if (isPking() == true) { + + rtcRoom.getLocalUser().responseJoinOtherRoom(userBean.getId(), userBean.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 = userBean.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", "发送失敗" + userBean.getId()); + } + }); + } + }); + + }else if (extra.equals(SOCKET_LIVE_DRPK)) { //收到多人PK申请 if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(userBean); @@ -354,7 +404,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onError(String error) { - ToastUtil.show( R.string.net_error); + ToastUtil.show(R.string.net_error); } }); @@ -381,6 +431,22 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onFinishOtherRoom(String roomId, String userId) { super.onFinishOtherRoom(roomId, userId); + Log.e("ry",roomId+"房间是"+userId); + RCRTCEngine.getInstance().leaveOtherRoom(roomId, true, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry",roomId+"退出啊房间成功"+userId); + + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry",roomId+"退出啊房间失败"+userId); + + } + }); + + if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.leaveDRRoom(); }