添加了接口控制文字消息和语音的展示

This commit is contained in:
18401019693 2024-01-15 13:59:46 +08:00
parent 27f136d6ca
commit 24788d7e21
6 changed files with 225 additions and 105 deletions

View File

@ -0,0 +1,27 @@
package com.yunbao.common.bean;
import com.google.gson.annotations.SerializedName;
public class RoomMicStatusModel extends BaseModel{
@SerializedName("mic_status")
private String micStatus;
@SerializedName("im_status")
private String imStatus;
public String getMicStatus() {
return micStatus;
}
public void setMicStatus(String micStatus) {
this.micStatus = micStatus;
}
public String getImStatus() {
return imStatus;
}
public void setImStatus(String imStatus) {
this.imStatus = imStatus;
}
}

View File

@ -48,15 +48,16 @@ public class SudGameInputPopupWindow extends BottomPopupView {
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.send), new ViewClicksAntiShake.ViewClicksCallBack() { ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.send), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override @Override
public void onViewClicks() { public void onViewClicks() {
dialog.dismiss();
if (sudGameInputCallBack != null) { if (sudGameInputCallBack != null) {
String textMessageStr = textMessage.getText().toString(); String textMessageStr = textMessage.getText().toString().trim();
if (!TextUtils.isEmpty(textMessageStr)) { if (!TextUtils.isEmpty(textMessageStr)) {
if (textMessageStr.length() > 100) { if (textMessageStr.length() > 100) {
ToastUtil.show(WordUtil.isNewZh() ? "超出字數限制" : "Exceed word limit"); ToastUtil.show(WordUtil.isNewZh() ? "超出字數限制" : "Exceed word limit");
} else { } else {
sudGameInputCallBack.sendMessage(textMessageStr); sudGameInputCallBack.sendMessage(textMessageStr);
} }
dialog.dismiss();
} else { } else {
ToastUtil.show(WordUtil.getNewString(R.string.cannot_be_empty)); ToastUtil.show(WordUtil.getNewString(R.string.cannot_be_empty));
} }

View File

@ -58,6 +58,7 @@ import com.yunbao.common.bean.RedPacketDetailsBean;
import com.yunbao.common.bean.RedPacketGiftModel; import com.yunbao.common.bean.RedPacketGiftModel;
import com.yunbao.common.bean.RedPacketInfoModel; import com.yunbao.common.bean.RedPacketInfoModel;
import com.yunbao.common.bean.RedPacketListBean; import com.yunbao.common.bean.RedPacketListBean;
import com.yunbao.common.bean.RoomMicStatusModel;
import com.yunbao.common.bean.SearchModel; import com.yunbao.common.bean.SearchModel;
import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.SetAttentsModel;
import com.yunbao.common.bean.SlideInBannerModel; import com.yunbao.common.bean.SlideInBannerModel;
@ -1146,12 +1147,19 @@ public interface PDLiveApi {
@GET("/api/public/?service=Sudgameserver.joinMic") @GET("/api/public/?service=Sudgameserver.joinMic")
Observable<ResponseModel<List<BaseModel>>> joinMic(@Query("room_id") String roomId); Observable<ResponseModel<List<BaseModel>>> joinMic(@Query("room_id") String roomId);
@GET("/api/public/?service=Sudgameserver.onMic") @GET("/api/public/?service=Sudgameserver.onMic")
Observable<ResponseModel<List<BaseModel>>> onMic(@Query("room_id") String roomId); Observable<ResponseModel<List<BaseModel>>> onMic(@Query("room_id") String roomId);
@GET("/api/public/?service=Sudgameserver.offMic") @GET("/api/public/?service=Sudgameserver.offMic")
Observable<ResponseModel<List<BaseModel>>> offMic(@Query("room_id") String roomId); Observable<ResponseModel<List<BaseModel>>> offMic(@Query("room_id") String roomId);
@GET("/api/public/?service=Sudgameserver.leaveMic") @GET("/api/public/?service=Sudgameserver.leaveMic")
Observable<ResponseModel<List<BaseModel>>> leaveMic(@Query("room_id") String roomId); Observable<ResponseModel<List<BaseModel>>> leaveMic(@Query("room_id") String roomId);
@GET("/api/public/?service=Sudgameserver.getRoomMicData") @GET("/api/public/?service=Sudgameserver.getRoomMicData")
Observable<ResponseModel<List<SudGameUserModel>>> getRoomMicData(@Query("room_id") String roomId); Observable<ResponseModel<List<SudGameUserModel>>> getRoomMicData(@Query("room_id") String roomId);
@GET("/api/public/?service=Sudgameserver.getRoomMicStatus")
Observable<ResponseModel<RoomMicStatusModel>> getRoomMicStatus();
} }

View File

@ -56,6 +56,7 @@ import com.yunbao.common.bean.RedPacketDetailsBean;
import com.yunbao.common.bean.RedPacketGiftModel; import com.yunbao.common.bean.RedPacketGiftModel;
import com.yunbao.common.bean.RedPacketInfoModel; import com.yunbao.common.bean.RedPacketInfoModel;
import com.yunbao.common.bean.RedPacketListBean; import com.yunbao.common.bean.RedPacketListBean;
import com.yunbao.common.bean.RoomMicStatusModel;
import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.SetAttentsModel;
import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.StarChallengeStatusModel;
import com.yunbao.common.bean.SudGameUserModel; import com.yunbao.common.bean.SudGameUserModel;
@ -2908,6 +2909,30 @@ public class LiveNetManager {
}).isDisposed(); }).isDisposed();
} }
public void getRoomMicStatus(HttpCallback<RoomMicStatusModel> callback) {
API.get().pdLiveApi(mContext)
.getRoomMicStatus()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ResponseModel<RoomMicStatusModel>>() {
@Override
public void accept(ResponseModel<RoomMicStatusModel> roomMicStatusModelResponseModel) throws Exception {
if (callback != null) {
callback.onSuccess(roomMicStatusModelResponseModel.getData().getInfo());
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
throwable.printStackTrace();
if (callback != null) {
callback.onError(mContext.getString(R.string.net_error));
}
}
}).isDisposed();
}
/** /**
* 直播间取消网络请求 * 直播间取消网络请求
*/ */

View File

@ -245,7 +245,7 @@ public class GameMicManager {
try { try {
getView().onSubscribeSuccess(userID,mute,position); getView().onSubscribeSuccess(userID, mute, position);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -355,35 +355,39 @@ public class GameMicManager {
RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC_HIGH, RCRTCParamsType.AudioScenario.MUSIC_CHATROOM); RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC_HIGH, RCRTCParamsType.AudioScenario.MUSIC_CHATROOM);
} }
public void joinRoom(String roomId) { public void joinRoom(String roomId, boolean imOff) {
mRoomID = roomId; mRoomID = roomId;
RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() if (imOff) {
// 根据实际场景选择音视频直播LIVE_AUDIO_VIDEO 或音频直播LIVE_AUDIO
.setRoomType(RCRTCRoomType.MEETING)
.build(); RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create()
RCRTCEngine.getInstance().joinRoom("v" + roomId, roomConfig, new IRCRTCResultDataCallback<RCRTCRoom>() { // 根据实际场景选择音视频直播LIVE_AUDIO_VIDEO 或音频直播LIVE_AUDIO
@Override .setRoomType(RCRTCRoomType.MEETING)
public void onSuccess(final RCRTCRoom rcrtcRoom) {
GameMicManager.this.mRtcRoom = rcrtcRoom;
// 注册房间回调
rcrtcRoom.registerRoomListener(roomEventsListener);
try {
getView().onJoinRoomSuccess(rcrtcRoom);
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
@Override .build();
public void onFailed(RTCErrorCode rtcErrorCode) { RCRTCEngine.getInstance().joinRoom("v" + roomId, roomConfig, new IRCRTCResultDataCallback<RCRTCRoom>() {
try { @Override
getView().onJoinRoomFailed(rtcErrorCode); public void onSuccess(final RCRTCRoom rcrtcRoom) {
} catch (IllegalStateException e) { GameMicManager.this.mRtcRoom = rcrtcRoom;
e.printStackTrace(); // 注册房间回调
rcrtcRoom.registerRoomListener(roomEventsListener);
try {
getView().onJoinRoomSuccess(rcrtcRoom);
} catch (IllegalStateException e) {
e.printStackTrace();
}
} }
}
}); @Override
public void onFailed(RTCErrorCode rtcErrorCode) {
try {
getView().onJoinRoomFailed(rtcErrorCode);
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
});
}
RongChatRoomClient.getInstance().joinChatRoom("v" + roomId, -1, new IRongCoreCallback.OperationCallback() { RongChatRoomClient.getInstance().joinChatRoom("v" + roomId, -1, new IRongCoreCallback.OperationCallback() {
@Override @Override
public void onSuccess() { public void onSuccess() {
@ -490,7 +494,7 @@ public class GameMicManager {
@Override @Override
public void onError(Message message, RongIMClient.ErrorCode errorCode) { public void onError(Message message, RongIMClient.ErrorCode errorCode) {
Log.i("tx", "发送成功"+errorCode.toString());
} }
}); });
} }
@ -515,9 +519,11 @@ public class GameMicManager {
void onSubscribeSuccess(List<RCRTCInputStream> inputStreamList); void onSubscribeSuccess(List<RCRTCInputStream> inputStreamList);
void onSubscribeFailed(); void onSubscribeFailed();
void onSubscribeSuccess(String userID,boolean mute, int position);
void onSubscribeSuccess(String userID, boolean mute, int position);
void onSubscribeFailed(String userID); void onSubscribeFailed(String userID);
void onUserJoined(RCRTCRemoteUser rcrtcRemoteUser); void onUserJoined(RCRTCRemoteUser rcrtcRemoteUser);
void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser); void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser);

View File

@ -27,6 +27,7 @@ import com.yunbao.common.bean.CreateSudRoomModel;
import com.yunbao.common.bean.CustomSidebarChildModel; import com.yunbao.common.bean.CustomSidebarChildModel;
import com.yunbao.common.bean.CustomSidebarInfoModel; import com.yunbao.common.bean.CustomSidebarInfoModel;
import com.yunbao.common.bean.HttpCallbackModel; import com.yunbao.common.bean.HttpCallbackModel;
import com.yunbao.common.bean.RoomMicStatusModel;
import com.yunbao.common.bean.SudGameChatImModel; import com.yunbao.common.bean.SudGameChatImModel;
import com.yunbao.common.bean.SudGameUserModel; import com.yunbao.common.bean.SudGameUserModel;
import com.yunbao.common.dialog.SudGameInputPopupWindow; import com.yunbao.common.dialog.SudGameInputPopupWindow;
@ -83,6 +84,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti
private SudGameUserListAdapter sudGameUserListAdapter; private SudGameUserListAdapter sudGameUserListAdapter;
private ProcessResultUtil mProcessResultUtil; private ProcessResultUtil mProcessResultUtil;
private List<String> muteUser = new ArrayList<>(); private List<String> muteUser = new ArrayList<>();
private boolean imOff;
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {
@ -118,10 +120,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti
} }
}); });
gameMicManager = new GameMicManager();
gameMicManager.attachView(this);
gameMicManager.config(this);
gameMicManager.joinRoom(mLiveUid);
// 设置禁用麦克风采集 // 设置禁用麦克风采集
RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable);
ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat);
@ -142,27 +141,75 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti
} }
}, 1500); }, 1500);
mProcessResultUtil = new ProcessResultUtil(this); mProcessResultUtil = new ProcessResultUtil(this);
LiveNetManager.get(mContext)
.getRoomMicStatus(new HttpCallback<RoomMicStatusModel>() {
@Override
public void onSuccess(RoomMicStatusModel data) {
gameMicManager = new GameMicManager();
gameMicManager.attachView(SudGameActivity.this);
gameMicManager.config(SudGameActivity.this);
//语音
if (TextUtils.equals(data.getMicStatus(), "1")) {
imOff = true;
gameCloseWheat.setVisibility(View.VISIBLE);
gameSeat.setVisibility(View.VISIBLE);
userList.setVisibility(View.VISIBLE);
} else {
imOff = false;
gameCloseWheat.setVisibility(View.GONE);
gameSeat.setVisibility(View.GONE);
userList.setVisibility(View.GONE);
}
if (TextUtils.equals(data.getImStatus(), "1")) {
findViewById(R.id.game_review_input).setVisibility(View.VISIBLE);
chatList.setVisibility(View.VISIBLE);
} else {
findViewById(R.id.game_review_input).setVisibility(View.GONE);
chatList.setVisibility(View.GONE);
}
gameMicManager.joinRoom(mLiveUid, imOff);
}
@Override
public void onError(String error) {
imOff = false;
//文字
findViewById(R.id.game_review_input).setVisibility(View.GONE);
chatList.setVisibility(View.GONE);
//语音
gameCloseWheat.setVisibility(View.GONE);
gameSeat.setVisibility(View.GONE);
userList.setVisibility(View.GONE);
}
});
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
LiveNetManager.get(mContext) if (gameMicManager != null) {
.leaveMic(mLiveUid, new HttpCallback<HttpCallbackModel>() { gameMicManager.leaveRoom();
@Override gameMicManager.detachView();
public void onSuccess(HttpCallbackModel data) { }
if (!imOff) {
LiveNetManager.get(mContext)
.leaveMic(mLiveUid, new HttpCallback<HttpCallbackModel>() {
@Override
public void onSuccess(HttpCallbackModel data) {
} }
@Override @Override
public void onError(String error) { public void onError(String error) {
}
});
}
}
});
Bus.getOff(this); Bus.getOff(this);
gameMicManager.leaveRoom();
gameMicManager.detachView();
super.onDestroy(); super.onDestroy();
} }
@ -256,28 +303,30 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.game_seat), new ViewClicksAntiShake.ViewClicksCallBack() { ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.game_seat), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override @Override
public void onViewClicks() { public void onViewClicks() {
if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) { if (!imOff && gameMicManager != null) {
if (publishDefault) { if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) {
disable = true; if (publishDefault) {
// 设置禁用麦克风采集 disable = true;
RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); // 设置禁用麦克风采集
ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable);
gameMicManager.unPublishStreams(); ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat);
} else { gameMicManager.unPublishStreams();
if (sudGameUserListAdapter.isMicMax()) {
ToastUtil.show(WordUtil.isNewZh() ? "上麥人數最大7人" : "The maximum number of people on the microphone is 7");
} else { } else {
gameMicManager.publishDefaultAVStream(); if (sudGameUserListAdapter.isMicMax()) {
} ToastUtil.show(WordUtil.isNewZh() ? "上麥人數最大7人" : "The maximum number of people on the microphone is 7");
} else {
gameMicManager.publishDefaultAVStream();
}
}
} else {
mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() {
@Override
public void run() {
}
});
} }
} else {
mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() {
@Override
public void run() {
}
});
} }
@ -286,54 +335,57 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti
ViewClicksAntiShake.clicksAntiShake(gameCloseWheat, new ViewClicksAntiShake.ViewClicksCallBack() { ViewClicksAntiShake.clicksAntiShake(gameCloseWheat, new ViewClicksAntiShake.ViewClicksCallBack() {
@Override @Override
public void onViewClicks() { public void onViewClicks() {
if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) { if (!imOff && gameMicManager != null) {
if (disable) { if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) {
disable = false; if (disable) {
// 设置禁用麦克风采集 disable = false;
RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); // 设置禁用麦克风采集
ImgLoader.display(mContext, R.mipmap.icon_game_open_wheat, gameCloseWheat); RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable);
LiveNetManager.get(mContext) ImgLoader.display(mContext, R.mipmap.icon_game_open_wheat, gameCloseWheat);
.onMic(mLiveUid, new HttpCallback<HttpCallbackModel>() { LiveNetManager.get(mContext)
@Override .onMic(mLiveUid, new HttpCallback<HttpCallbackModel>() {
public void onSuccess(HttpCallbackModel data) { @Override
public void onSuccess(HttpCallbackModel data) {
} }
@Override @Override
public void onError(String error) { public void onError(String error) {
} }
}); });
ToastUtil.show(WordUtil.isNewZh() ? "麥克風已開啟" : "Microphone turned on"); ToastUtil.show(WordUtil.isNewZh() ? "麥克風已開啟" : "Microphone turned on");
} else { } else {
disable = true; disable = true;
// 设置禁用麦克风采集 // 设置禁用麦克风采集
RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable);
ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat);
LiveNetManager.get(mContext) LiveNetManager.get(mContext)
.offMic(mLiveUid, new HttpCallback<HttpCallbackModel>() { .offMic(mLiveUid, new HttpCallback<HttpCallbackModel>() {
@Override @Override
public void onSuccess(HttpCallbackModel data) { public void onSuccess(HttpCallbackModel data) {
} }
@Override @Override
public void onError(String error) { public void onError(String error) {
}
});
ToastUtil.show(WordUtil.isNewZh() ? "麥克風已關閉" : "Microphone turned off");
}
} else {
mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() {
@Override
public void run() {
}
});
ToastUtil.show(WordUtil.isNewZh() ? "麥克風已關閉" : "Microphone turned off");
} }
});
} else {
mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() {
@Override
public void run() {
}
});
}
} }
} }
}); });
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.game_review_input), new ViewClicksAntiShake.ViewClicksCallBack() { ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.game_review_input), new ViewClicksAntiShake.ViewClicksCallBack() {
@ -406,7 +458,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti
LiveNetManager.get(mContext).checkRemainingBalance(mCreateSudRoomModel.getSudGameRoomId(), new HttpCallback<CheckRemainingBalance>() { LiveNetManager.get(mContext).checkRemainingBalance(mCreateSudRoomModel.getSudGameRoomId(), new HttpCallback<CheckRemainingBalance>() {
@Override @Override
public void onSuccess(CheckRemainingBalance data) { public void onSuccess(CheckRemainingBalance data) {
if (TextUtils.equals(String.valueOf(data.getGoldenBeanRemainingBalance() ),"1")) { if (TextUtils.equals(String.valueOf(data.getGoldenBeanRemainingBalance()), "1")) {
gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfIn(true, event.getSeatIndex(), true, 1); gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfIn(true, event.getSeatIndex(), true, 1);
} else { } else {
if (IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) { if (IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) {
@ -466,6 +518,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti
LiveNetManager.get(mContext).getRoomMicData(mLiveUid, new HttpCallback<List<SudGameUserModel>>() { LiveNetManager.get(mContext).getRoomMicData(mLiveUid, new HttpCallback<List<SudGameUserModel>>() {
@Override @Override
public void onSuccess(List<SudGameUserModel> data) { public void onSuccess(List<SudGameUserModel> data) {
gameMicManager.refreshStreams(data); gameMicManager.refreshStreams(data);
sudGameUserListAdapter.refreshSudGameUserList(data, muteUser); sudGameUserListAdapter.refreshSudGameUserList(data, muteUser);
} }
@ -481,7 +534,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti
@Override @Override
public void onJoinRoomFailed(RTCErrorCode rtcErrorCode) { public void onJoinRoomFailed(RTCErrorCode rtcErrorCode) {
ToastUtil.show("加入失败 "+rtcErrorCode.toString()); ToastUtil.show("加入失败 " + rtcErrorCode.toString());
} }
@Override @Override