add[声望升级-多人PK]

This commit is contained in:
Martin 2024-04-19 18:27:56 +08:00
parent 583740e866
commit 4147e3c5f5
11 changed files with 306 additions and 338 deletions

View File

@ -76,6 +76,21 @@ public class SWAuManager extends BaseCacheManager {
//mRtcEngine.startPreview();
}
/**
* 更新主播视图
* @param frameLayout
*/
public void updateMyChannelView(FrameLayout frameLayout,int uid) {
mRtcEngine.setupLocalVideo(null);
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
frameLayout.addView(surfaceView);
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid);
mRtcEngine.setupRemoteVideo(videoCanvas);
}
/**
* 加入房间
*/
@ -101,14 +116,7 @@ public class SWAuManager extends BaseCacheManager {
}
public void joinExRoomEx(String strUid, String token, String channelName) {
int uid;
if (StringUtil.isEmpty(strUid)) {
uid = 0;
} else {
uid = Integer.parseInt(strUid);
}
public void joinExRoomEx(int strUid, String token, String channelName) {
// 创建 ChannelMediaOptions 对象并进行配置
ChannelMediaOptions options = new ChannelMediaOptions();
// 根据场景将用户角色设置为 AUDIENCE (观众)
@ -119,23 +127,24 @@ public class SWAuManager extends BaseCacheManager {
options.autoSubscribeAudio = true;
RtcConnection rtcConnection = new RtcConnection();
rtcConnection.channelId = "g99411"; //對方主播的頻道
rtcConnection.localUid = 99412;//自己的ID
rtcConnection.channelId = channelName; //對方主播的頻道
rtcConnection.localUid = Integer.parseInt(CommonAppConfig.getInstance().getUid());//自己的ID
mRtcEngine.joinChannelEx(token, rtcConnection, options, new IRtcEngineEventHandler() {
@Override
public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
super.onJoinChannelSuccess(channel, uid, elapsed);
L.eSw("onJoinChannelSuccess:" + channel + " uid " +uid+ " elapsed: " + elapsed);
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
pkContainer1.addView(surfaceView);
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, 99411);
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
L.eSw("onJoinChannelSuccess:" + channel + " uid " +uid+ " elapsed: " + elapsed);
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
pkContainer1.addView(surfaceView);
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, strUid);
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
}
});
}
@Override
@ -146,6 +155,18 @@ public class SWAuManager extends BaseCacheManager {
});
}
/**
* 退出对方直播间
* @param uid 自己的ID
* @param liveUid 对方直播间号
*/
public void exitChannelToUid(int uid, String liveUid){
RtcConnection rtcConnection = new RtcConnection();
rtcConnection.channelId = getChannelName(liveUid); //對方主播的頻道
rtcConnection.localUid = uid;//自己的ID
mRtcEngine.leaveChannelEx(rtcConnection);
}
public static String getChannelName(String liveUid) {
return CommonAppConfig.SWChannelPrefix + liveUid;
}

View File

@ -123,7 +123,7 @@ public class SWManager extends BaseCacheManager {
anchorContainer.addView(surfaceView);
Config config = new Config(mContext, mRtcEngine, FURenderer.INSTANCE.mFURenderKit, null, CaptureMode.Agora, 0, false, new CameraConfig(MirrorMode.MIRROR_NONE,MirrorMode.MIRROR_NONE));
faceUnityBeautyAPI.initialize(config);
faceUnityBeautyAPI.enable(true);
faceUnityBeautyAPI.enable(false);
faceUnityBeautyAPI.setBeautyPreset(BeautyPreset.CUSTOM);
//FaceUnityBeautyManage.getInstance().mFURenderKit.setFaceBeauty();

View File

@ -315,7 +315,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
private void initFaceManager() {
manager = new FaceManager();
manager.initFURender(mContext);
manager.drawRongFrame(mContext);
//暂时去掉
//manager.drawRongFrame(mContext);
}
public boolean isStartPreview() {
@ -1353,34 +1354,39 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
if (obj != null) {
if (obj.getString("ispk").equals("0")) {
IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() {
// TODO: 2024/4/19 邀请主播进行多人连麦
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LIVE_DRPK)
.param("action", 1)
.param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName())
.param("pkuid", pkUid)
.param("uid", CommonAppConfig.getInstance().getUid())
.param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar())
.param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName());
msg1.create();
String targetId = "g" + pkUid;
Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM;
TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString());
Message message = Message.obtain(targetId, conversationType, messageContent);
RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() {
@Override
public void onSuccess() {
if (!extra.equals(SOCKET_LIVE_DRPK_RANDOM)) {
if (WordUtil.isNewZh()) {
ToastUtil.show("邀请 " + pkUid + " 发送成功");
} else {
ToastUtil.show("invite " + pkUid + " successful");
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
dismiss();
}
});
public void onAttached(Message message) {
}
@Override
public void onFailed(RTCErrorCode rtcErrorCode) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dismiss();
}
});
//todo 安卓端状态码说明文档https://docs.rongcloud.cn/v4/views/rtc/call/code/android.html
Log.e("ry", rtcErrorCode + "aaaaaa" + CommonAppConfig.getInstance().getUid() + "VDSSSS" + pkUid);
public void onSuccess(Message message) {
if (SocketRyClient.mSocketHandler != null) {
SocketRyClient.mSocketHandler.processBroadcast(message.toString() + "");
}
}
@Override
public void onError(Message message, RongIMClient.ErrorCode errorCode) {
Log.e("tx", "aaa" + errorCode.toString());
ToastUtil.show(errorCode.code + ":" + errorCode.msg);
}
});
} else {

View File

@ -490,7 +490,6 @@ public class LiveAudienceEvent extends BaseModel {
SUD_GAME_CREATE_ROOM(75, "主播创建sud游戏"),
PK_RANK_START(76, "PK排位赛开始"),
GuardSpecialEffect(77, "PK排位赛开始");
private int type;
private String name;

View File

@ -387,7 +387,7 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener {
//接受PK回调
private void pkAccept() {
mTRTCCloud1 = LivePushTxViewHolder.mTRTCCloud.createSubCloud();
/*mTRTCCloud1 = LivePushTxViewHolder.mTRTCCloud.createSubCloud();
mTRTCParams1 = new TRTCCloudDef.TRTCParams();
mTRTCParams1.sdkAppId = GenerateTestUserSig.SDKAPPID;
mTRTCParams1.userId = CommonAppConfig.getInstance().getUid() + "pk";
@ -396,7 +396,7 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener {
mTRTCParams1.role = TRTCCloudDef.TRTCRoleAudience;
mTRTCCloud1.enterRoom(mTRTCParams1, TRTC_APP_SCENE_LIVE);
mTRTCCloud1.startRemoteView(mApplyUid, LivePushTxViewHolder.mPreView1);
mTRTCCloud1.setListener(new TRTCCloudImplListener(mContext));
mTRTCCloud1.setListener(new TRTCCloudImplListener(mContext));*/
LivePushTxViewHolder.btn_close.setVisibility(View.VISIBLE);
SocketLinkMicPkUtil.linkMicPkAccept(mSocketClient, mApplyUid, mApplyUrl, mApplyNmae);
onLinkMicPkStart(mApplyUid, mApplyUrl, mApplyNmae);
@ -734,19 +734,9 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener {
mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE);
}
if (mAcceptPk) {
LivePushTxViewHolder.btn_close.setVisibility(View.VISIBLE);
//把画面设置成九宫格
dr_pk_view.setVisibility(View.VISIBLE);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mPreView.getLayoutParams();
params.width = mPreView.getWidth() / 2;
params.height = DpUtil.dp2px(250);
params.topMargin = DpUtil.dp2px(130);
mPreView.setLayoutParams(params);
HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive")
.params("uid", CommonAppConfig.getInstance().getUid())
@ -757,7 +747,6 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener {
@Override
public void onSuccess(int code, String msgs, String[] info) {
if (code == 0) {
HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("roomid", u.getId())
@ -768,15 +757,6 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener {
public void onSuccess(int code, String msgs, String[] info) {
if (code == 0) {
JSONObject obj = JSON.parseObject(info[0]);
if (LiveLinkMicPkPresenter.mTRTCCloud1 != null && LivePushTxViewHolder.mTRTCCloud != null) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mContext.getResources().getDimensionPixelOffset(R.dimen.live_view));
params.weight = 1;
params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
LivePushTxViewHolder.mPreView.setLayoutParams(params);
LivePushTxViewHolder.mPreView1.setLayoutParams(params);
}
List<DrPkbean> list = JSON.parseArray(obj.getString("userlist"), DrPkbean.class);
for (int ii = 0, size = list.size(); ii < size; ii++) {
@ -786,31 +766,6 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener {
}
for (int i = 0, size = list.size(); i < size; i++) {
if (!String.valueOf(list.get(i).getId()).equals(CommonAppConfig.getInstance().getUid())) {
Log.i("tsss11", list.size() + "啊啊啊" + list.get(i).getId() + "");
mTRTCCloud1 = LivePushTxViewHolder.mTRTCCloud.createSubCloud();
mTRTCParams1 = new TRTCCloudDef.TRTCParams();
mTRTCParams1.sdkAppId = GenerateTestUserSig.SDKAPPID;
mTRTCParams1.userId = CommonAppConfig.getInstance().getUid() + "pk";
mTRTCParams1.roomId = list.get(i).getId();
mTRTCParams1.userSig = GenerateTestUserSig.genTestUserSig(mTRTCParams1.userId);
mTRTCParams1.role = TRTCCloudDef.TRTCRoleAudience;
if (i == 1) {
mTRTCCloud1.enterRoom(mTRTCParams1, TRTC_APP_SCENE_LIVE);
mTRTCCloud1.startRemoteView(list.get(i).getId() + "", LivePushTxViewHolder.dr1_preview);
mTRTCCloud1.setListener(new LiveLinkMicPkPresenter.TRTCCloudImplListener(mContext));
} else if (i == 2) {
mTRTCCloud1.enterRoom(mTRTCParams1, TRTC_APP_SCENE_LIVE);
mTRTCCloud1.startRemoteView(list.get(i).getId() + "", LivePushTxViewHolder.dr2_preview);
mTRTCCloud1.setListener(new LiveLinkMicPkPresenter.TRTCCloudImplListener(mContext));
} else if (i == 3) {
mTRTCCloud1.enterRoom(mTRTCParams1, TRTC_APP_SCENE_LIVE);
mTRTCCloud1.startRemoteView(list.get(i).getId() + "", LivePushTxViewHolder.dr3_preview);
mTRTCCloud1.setListener(new LiveLinkMicPkPresenter.TRTCCloudImplListener(mContext));
} else if (i == 4) {
mTRTCCloud1.enterRoom(mTRTCParams1, TRTC_APP_SCENE_LIVE);
mTRTCCloud1.startRemoteView(list.get(i).getId() + "", LivePushTxViewHolder.dr4_preview);
mTRTCCloud1.setListener(new LiveLinkMicPkPresenter.TRTCCloudImplListener(mContext));
}
Log.i("ssxcs", list.get(i).getId() + "");
final SocketSendBean msg = new SocketSendBean()
.param("_method_", Constants.SOCKET_LIVE_DRPK)
@ -842,8 +797,6 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener {
}
});
}
}
});

View File

@ -1243,99 +1243,90 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
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() {
if (finalAgree) {
HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom")
.params("uid", CommonAppConfig.getInstance().getUid())
.params("roomid", u.getId())
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
Log.i("多人PK", "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info));
final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LIVE_DRPK)
.param("action", 10)
.param("uid", CommonAppConfig.getInstance().getUid());
msg1.create();
String targetId = "g" + CommonAppConfig.getInstance().getUid();
Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM;
TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString());
io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent);
RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() {
@Override
public void onAttached(io.rong.imlib.model.Message message) {
}
@Override
public void onSuccess(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) {
}
});
}
}
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 onFailed(RTCErrorCode errorCode) {
ToastUtil.show("接受失败");
}
});
@Override
public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) {
Log.e("ry", "发送失敗");
}
});
if (info.length == 0) {
return;
}
JSONObject obj = JSONObject.parseObject(info[0]);
JSONArray users = obj.getJSONArray("userlist");
//添加水印
// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f);
// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect);
dRjoinOtherRoom(u.getId(), 1);
livePushRyViewHolder.setAnDrPkRtc(u.getId());
for (int i = 0; i < users.size(); i++) {
JSONObject user = users.getJSONObject(i);
Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表");
if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) {
if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) {
/**
* 向指定用户发送跨房间连麦请求
* <P>
* 1: inviterAutoMix为true时
*
* 1.1如果被邀请方在加入邀请方房间之前发布了资源当被邀请方加入邀请者房间成功后服务器会把被邀请方流资源合并到邀请方视图 ·默认仅悬浮布局合流
*
* 1.2如果被邀请方在加入邀请方房间之前没有发布过资源将会在被邀请方发布资源成功后服务器会把被邀请方流资源合并到邀请方视图默认仅悬浮布局合流
*
* 2:无论为true或false双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局一旦主动设置过合流布局后续音视频直播过程中设置的自动合流参数将失效
* <P/>
*/
IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() {
@Override
public void onSuccess() {
}
@Override
public void onFailed(RTCErrorCode errorCode) {
}
});
}
}
}
}
});
}
} else {
ToastUtil.show(msg);
}

View File

@ -309,10 +309,10 @@ 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);
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);
@ -1307,7 +1307,7 @@ public class SocketRyClient {
break;
case 9://pk结束的回调
mListener.onLinkMicPkEnd(map.getString("win_uid"));
EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END));
EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END).setObject(map.getString("uid")));
if (livePushRyViewHolder != null) {
livePushRyViewHolder.onLinkMicAnchorClose();
}

View File

@ -96,7 +96,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
private ViewGroup mSmallContainer;
private ViewGroup mLeftContainer;
private ViewGroup mRightContainer;
private RelativeLayout mPkContainer;
private ViewGroup mPkContainer;
public StyledPlayerView mVideoView;
private FrameLayout playFrameLayout;
@ -158,7 +158,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
mSmallContainer = (ViewGroup) findViewById(R.id.small_container);
mLeftContainer = (ViewGroup) findViewById(R.id.left_container);
mRightContainer = (ViewGroup) findViewById(R.id.right_container);
mPkContainer = (RelativeLayout) findViewById(R.id.pk_container);
mPkContainer = (FrameLayout) findViewById(R.id.pk_container);
mVideoView = (StyledPlayerView) findViewById(R.id.video_view);
ry_view = (FrameLayout) findViewById(R.id.ry_view);
leave = (ImageView) findViewById(R.id.leave);
@ -179,15 +179,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public void initSwEngine(String liveUid) {
this.liveUid = liveUid;
//初始化声网SDK
swAuManager = SWAuManager.get();
swAuManager.setAudienceContainer(ry_view);
swAuManager.initRtcEngine((Activity) mContext);
swAuManager.setupRemoteVideo(Integer.parseInt(liveUid));
//进入主播房间
swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid));
//测试-模拟PK场景加入第二个主播视图
swAuManager.setPkContainer1(playFrameLayout1);
swAuManager.joinExRoomEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid));
}
@Override
@ -232,11 +230,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
mVideoView.setLayoutParams(params);
mVideoView.requestLayout();
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
/* RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
params1.height = RelativeLayout.LayoutParams.MATCH_PARENT;
params1.topMargin = 0;
ry_view.setLayoutParams(params1);
ry_view.requestLayout();
ry_view.requestLayout();*/
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams();
params2.height = RelativeLayout.LayoutParams.MATCH_PARENT;
params2.topMargin = 0;
@ -252,12 +250,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
mVideoView.setLayoutParams(params);
mVideoView.requestLayout();
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
/*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
params1.height = vHeight;
params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
params1.addRule(RelativeLayout.ALIGN_TOP);
ry_view.setLayoutParams(params1);
ry_view.requestLayout();
ry_view.requestLayout();*/
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams();
params2.height = DpUtil.dp2px(270);
params2.topMargin = DpUtil.dp2px(120);
@ -373,12 +371,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
mVideoView.setLayoutParams(params);
mVideoView.requestLayout();
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
/* RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
params1.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
params1.addRule(RelativeLayout.ALIGN_TOP);
ry_view.setLayoutParams(params1);
ry_view.requestLayout();
ry_view.requestLayout();*/
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams();
params2.height = DpUtil.dp2px(270);
params2.topMargin = DpUtil.dp2px(120);
@ -422,11 +420,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
params.addRule(RelativeLayout.ALIGN_TOP);
mVideoView.requestLayout();
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
/*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
params1.height = vHeight;
params1.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top);
params1.addRule(RelativeLayout.ALIGN_TOP);
ry_view.requestLayout();
ry_view.requestLayout();*/
isPk = true;
}
@ -453,11 +451,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
mVideoView.setLayoutParams(params);
mVideoView.requestLayout();
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
/*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
params1.height = height;
params1.topMargin = 0;
ry_view.setLayoutParams(params1);
ry_view.requestLayout();
ry_view.requestLayout();*/
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams();
params2.height = height;
params2.topMargin = 0;
@ -475,7 +473,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
mVideoView.setLayoutParams(params);
mVideoView.requestLayout();
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
/*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
params1.height = height;
params1.topMargin = 0;
params1.addRule(RelativeLayout.ALIGN_TOP);
@ -483,7 +481,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
}
ry_view.setLayoutParams(params1);
ry_view.requestLayout();
ry_view.requestLayout();*/
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams();
params2.height = height;
params2.topMargin = DpUtil.dp2px(120);
@ -668,37 +666,24 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
confirm = "accept";
cancel = "cancel";
}
DialogUitl.Builder builder = new DialogUitl.Builder(mContext)
.setContent(content)
.setTitle(mLiveBean.getUserNiceName())
.setConfirmString(confirm)
.setCancelString(cancel)
.setView(R.layout.dialog_live_mic_invite)
.setClickCallback(new DialogUitl.SimpleCallback() {
DialogUitl.Builder builder = new DialogUitl.Builder(mContext).setContent(content).setTitle(mLiveBean.getUserNiceName()).setConfirmString(confirm).setCancelString(cancel).setView(R.layout.dialog_live_mic_invite).setClickCallback(new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
String[] permissions;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
permissions = new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.RECORD_AUDIO};
} else {
permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO};
}
LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
String[] permissions;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
permissions = new String[]{
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.RECORD_AUDIO
};
} else {
permissions = new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO
};
}
LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() {
@Override
public void run() {
UsertoRY();
public void run() {
UsertoRY();
}
});
}
});
}
});
builder.build().show();
} else if ("endMic".equals(str)) {
@ -776,11 +761,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
EasyFloat.dismiss("Debug");
return;
}
EasyFloat.with(mContext)
.setDragEnable(true)
.setTag("Debug")
.setLayout(debugView)
.show();
EasyFloat.with(mContext).setDragEnable(true).setTag("Debug").setLayout(debugView).show();
}
}
@ -798,79 +779,71 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
break;
}
LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext,
IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR),
ban,
true);
new XPopup.Builder(mContext)
.setPopupCallback(new XPopupCallback() {
@Override
public void onCreated(BasePopupView popupView) {
LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR), ban, true);
new XPopup.Builder(mContext).setPopupCallback(new XPopupCallback() {
@Override
public void onCreated(BasePopupView popupView) {
}
}
@Override
public void beforeShow(BasePopupView popupView) {
@Override
public void beforeShow(BasePopupView popupView) {
}
}
@Override
public void onShow(BasePopupView popupView) {
@Override
public void onShow(BasePopupView popupView) {
}
}
@Override
public void onDismiss(BasePopupView popupView) {
int selectClarity = liveClarityCustomPopup.getSelectClarity();
if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR))
return;
if (selectClarity == PLAY_MODEL_ANCHOR) {
switchStream(srcUrl, PLAY_MODEL_DEF);
setAudiencePlayModel(selectClarity);
} else {
switchStream(srcUrl, selectClarity);
}
IMLoginManager.get(mContext).put(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, selectClarity);
showToast();
}
@Override
public void onDismiss(BasePopupView popupView) {
int selectClarity = liveClarityCustomPopup.getSelectClarity();
if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR))
return;
if (selectClarity == PLAY_MODEL_ANCHOR) {
switchStream(srcUrl, PLAY_MODEL_DEF);
setAudiencePlayModel(selectClarity);
} else {
switchStream(srcUrl, selectClarity);
}
IMLoginManager.get(mContext).put(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, selectClarity);
showToast();
}
private void showToast() {
if (WordUtil.isNewZh()) {
DialogUitl.showToast(mContext, "設置成功\n" +
"正在為你轉換中", 3000);
} else {
DialogUitl.showToast(mContext, "successful\n" +
"It's being converted for you", 3000);
}
}
private void showToast() {
if (WordUtil.isNewZh()) {
DialogUitl.showToast(mContext, "設置成功\n" + "正在為你轉換中", 3000);
} else {
DialogUitl.showToast(mContext, "successful\n" + "It's being converted for you", 3000);
}
}
@Override
public void beforeDismiss(BasePopupView popupView) {
@Override
public void beforeDismiss(BasePopupView popupView) {
}
}
@Override
public boolean onBackPressed(BasePopupView popupView) {
return false;
}
@Override
public boolean onBackPressed(BasePopupView popupView) {
return false;
}
@Override
public void onKeyBoardStateChanged(BasePopupView popupView, int height) {
@Override
public void onKeyBoardStateChanged(BasePopupView popupView, int height) {
}
}
@Override
public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) {
@Override
public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) {
}
}
@Override
public void onClickOutside(BasePopupView popupView) {
@Override
public void onClickOutside(BasePopupView popupView) {
}
})
.asCustom(liveClarityCustomPopup)
.show();
}
}).asCustom(liveClarityCustomPopup).show();
} else if (event.getType() == LiveAudienceEvent.LiveAudienceType.FONT_SIZE) {
int fount = 0;
try {
@ -881,11 +854,24 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
new LiveFontSizeSettingDialog(mContext, fount).setOnItemClickListener(new OnItemClickListener<Integer>() {
@Override
public void onItemClick(Integer bean, int position) {
EventBus.getDefault().post(new LiveAudienceEvent()
.setNums(bean)
.setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE));
EventBus.getDefault().post(new LiveAudienceEvent().setNums(bean).setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE));
}
}).showDialog();
} else if (event.getType() == LiveAudienceEvent.LiveAudienceType.PK_TWO_START) {
//将当前主播画面换个画布展示
swAuManager.updateMyChannelView((FrameLayout) mLeftContainer, Integer.parseInt(liveUid));
ry_view.removeAllViews();
//加入对方主播房间
swAuManager.setPkContainer1((FrameLayout) mRightContainer);
String pkUid = (String) event.getObject();
swAuManager.joinExRoomEx(Integer.parseInt(pkUid), CommonAppConfig.SWToken, SWAuManager.getChannelName(pkUid));
} else if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_PK_END) {
String pkUid = (String) event.getObject();
swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), SWAuManager.getChannelName(pkUid));
swAuManager.updateMyChannelView(ry_view, Integer.parseInt(liveUid));
mLeftContainer.removeAllViews();
mRightContainer.removeAllViews();
}
}
@ -904,9 +890,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
}
RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create()
// 根据实际场景选择音视频直播LIVE_AUDIO_VIDEO 或音频直播LIVE_AUDIO
.setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO)
.setLiveRole(RCRTCLiveRole.AUDIENCE)
.build();
.setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO).setLiveRole(RCRTCLiveRole.AUDIENCE).build();
RCRTCEngine.getInstance().joinRoom(LiveActivity.mLiveUid, roomConfig, new IRCRTCResultDataCallback<RCRTCRoom>() {
@ -1088,8 +1072,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
break;
}
// 示例代码使用480x640分辨率演示
RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig
.Builder.create()
RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig.Builder.create()
//设置分辨率
.setVideoResolution(rcrtcVideoResolution)
//设置帧率
@ -1097,8 +1080,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
//设置最小码率480P下推荐200
.setMinRate(minRate)
//设置最大码率480P下推荐900
.setMaxRate(maxRate)
.build();
.setMaxRate(maxRate).build();
RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config);
// 创建视图渲染视图
// RCRTCVideoView videoView = new RCRTCVideoView(contexts);
@ -1156,11 +1138,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
((RCRTCVideoInputStream) stream).setVideoFrameListener(new IRCRTCVideoInputFrameListener() {
@Override
public void onFrame(RCRTCRemoteVideoFrame videoFrame) {
String debugText = " 2、安卓主播开播 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" +
"rotation:" + videoFrame.getRotation() + "\n" +
"timestampNs:" + videoFrame.getTimestampNs() + "\n" +
"分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" +
"当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n";
String debugText = " 2、安卓主播开播 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" + "rotation:" + videoFrame.getRotation() + "\n" + "timestampNs:" + videoFrame.getTimestampNs() + "\n" + "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n";
//Log.d("ry", "onFrame: " + debugText);
new Handler(Looper.getMainLooper()).post(() -> {
debugView.setText(debugText);
@ -1190,14 +1168,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(true);
HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm")
.params("roomid", LiveActivity.mLiveUid)
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
Log.e("ry", code + "热热热");
}
});
HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm").params("roomid", LiveActivity.mLiveUid).execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
Log.e("ry", code + "热热热");
}
});
}
@Override
@ -1232,16 +1208,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
private void showLoadingDialog() {
if (PLAY_MODEL == PLAY_MODEL_480) return;
new DialogUitl.Builder(mContext)
.setTitle("網絡提示")
.setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。")
.setView(R.layout.dialog_simple_tip)
.setClickCallback(new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
dialog.dismiss();
}
}).build().show();
new DialogUitl.Builder(mContext).setTitle("網絡提示").setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。").setView(R.layout.dialog_simple_tip).setClickCallback(new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
dialog.dismiss();
}
}).build().show();
PLAY_MODEL = PLAY_MODEL_480;
String url = srcUrl;
if (videoLandscape == VIDEO_VERTICAL) {

View File

@ -50,6 +50,7 @@ import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.live.R;
@ -83,6 +84,7 @@ import cn.rongcloud.rtc.base.RCRTCParamsType;
import cn.rongcloud.rtc.base.RTCErrorCode;
import io.agora.beautyapi.faceunity.agora.SWAuManager;
import io.agora.beautyapi.faceunity.agora.SWManager;
import io.rong.imkit.userinfo.db.model.User;
import io.rong.imlib.IRongCallback;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;
@ -228,7 +230,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
UserBean userBean = new UserBean();
userBean.setId(inviterRoomId);
//收到邀请这个时候正在PK或连麦中 自动拒绝对方
if (isPking() == true) {
if (isPking()) {
rtcRoom.getLocalUser().responseJoinOtherRoom(userBean.getId(), userBean.getId(), false, false, "extra", new IRCRTCResultCallback() {
@ -615,18 +617,43 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
//清除 mBigContainer 中的渲染
mBigContainer.removeAllViews();
btn_close.setVisibility(View.VISIBLE);
//设置对方主播的渲染视图 设置到 rightContainer
swManager.setPkContainer1(mRightContainer);
swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,u.getId(), SWAuManager.getChannelName(u.getId()));
}
}
public void setAnDrPkRtc(String uid) {
if (swManager != null && StringUtil.isEmpty(uid)) {
L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid);
//将自己的渲染视图设置到 leftContainer
swManager.updateMyChannelView((FrameLayout) mLeftContainer);
//清除 mBigContainer 中的渲染
mBigContainer.removeAllViews();
btn_close.setVisibility(View.VISIBLE);
//设置对方主播的渲染视图 设置到 rightContainer
swManager.setPkContainer1(mRightContainer);
swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,uid, SWAuManager.getChannelName(uid));
}
}
public void onLinkMicAnchorClose(){
swManager.updateMyChannelView((FrameLayout) mBigContainer);
LivePushRyViewHolder.btn_close.setVisibility(View.GONE);
}
public void onLinkDRMicPkApply(UserBean userBean){
if (mLiveRyLinkMicPkPresenter != null) {
mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(userBean);
}
}
@Override
public void changeToLeft() {
if (mPreView != null) {

View File

@ -130,7 +130,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder {
public void onClick(View view) {
if (pk_nub <= 0) return;
//開始多人PK
HttpClient.getInstance().post("live.startDRPK", "live.startDRPK")
HttpClient.getInstance().get("live.startDRPK", "live.startDRPK")
.params("roomid", CommonAppConfig.getInstance().getUid())
.execute(new HttpCallback() {
@Override

View File

@ -45,12 +45,11 @@
android:src="@mipmap/zslk"
android:visibility="gone" />
<RelativeLayout
<FrameLayout
android:id="@+id/pk_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/live_top">
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_marginTop="130dp">
<com.yunbao.live.custom.MyFrameLayout4
android:id="@+id/left_container"
@ -65,7 +64,7 @@
android:layout_gravity="right"
android:layout_marginBottom="20dp" />
</RelativeLayout>
</FrameLayout>
<com.yunbao.live.custom.MyFrameLayout3