语音SDK进房动态选择
This commit is contained in:
@@ -28,12 +28,14 @@ import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
|
||||
import com.yizhuan.xchat_android_core.home.bean.BannerInfo;
|
||||
import com.yizhuan.xchat_android_core.manager.AudioEngineManager;
|
||||
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
||||
import com.yizhuan.xchat_android_core.manager.EngineType;
|
||||
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||||
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
||||
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterInfo;
|
||||
import com.yizhuan.xchat_android_core.monsterhunting.model.MonsterHuntingModel;
|
||||
import com.yizhuan.xchat_android_core.patriarch.exception.PmRoomLimitException;
|
||||
import com.yizhuan.xchat_android_core.public_chat_hall.manager.PublicChatHallDataManager;
|
||||
import com.yizhuan.xchat_android_core.room.bean.RoomAudioSdkType;
|
||||
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
||||
import com.yizhuan.xchat_android_core.room.giftvalue.helper.GiftValueMrg;
|
||||
import com.yizhuan.xchat_android_core.room.model.AvRoomModel;
|
||||
@@ -139,17 +141,7 @@ public class AvRoomPresenter extends BaseMvpPresenter<IAvRoomView> {
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(roomQueueInfoSparseArray -> {
|
||||
long uid = AuthModel.get().getCurrentUid();
|
||||
AudioEngineManager.get().startRtcEngine(uid);
|
||||
//成功进入房间发送log 到阿里
|
||||
StatisticManager.Instance().sendAliyunLog(LogFactory.create(
|
||||
LogProtocol.LogLevel.LEVEL_VERBOSE,
|
||||
LogProtocol.Topic.TOPIC_IM_LOG,
|
||||
LogProtocol.Event.EVENT_IM_CHANNEL
|
||||
)
|
||||
.append("roomUid", String.valueOf(roomInfo.getUid()))
|
||||
.append("uid", String.valueOf(AuthModel.get().getCurrentUid()))
|
||||
.append("type", "1"));
|
||||
|
||||
AudioEngineManager.get().startRtcEngine(uid,roomInfo.getAudioSdkType());
|
||||
if (getMvpView() != null) {
|
||||
getMvpView().enterRoomSuccess();
|
||||
}
|
||||
@@ -254,7 +246,7 @@ public class AvRoomPresenter extends BaseMvpPresenter<IAvRoomView> {
|
||||
if (roomQueueInfo != null) {
|
||||
JsonObject valueJsonObj = jsonParser.parse(entry.value).getAsJsonObject();
|
||||
if (valueJsonObj != null) {
|
||||
chatRoomMember = mGson.fromJson(valueJsonObj,MicMemberInfo.class);
|
||||
chatRoomMember = mGson.fromJson(valueJsonObj, MicMemberInfo.class);
|
||||
accounts.add(chatRoomMember.getAccount());
|
||||
roomQueueInfo.mChatRoomMember = chatRoomMember;
|
||||
}
|
||||
|
@@ -6,8 +6,10 @@ import com.netease.nim.uikit.common.util.log.LogUtil;
|
||||
import com.yizhuan.xchat_android_core.manager.agora.RtcEngineManager;
|
||||
import com.yizhuan.xchat_android_core.manager.wj.WJAudioConstant;
|
||||
import com.yizhuan.xchat_android_core.manager.wj.WJAudioEngineManager;
|
||||
import com.yizhuan.xchat_android_core.room.bean.RoomAudioSdkType;
|
||||
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
||||
import com.yizhuan.xchat_android_core.user.UserModel;
|
||||
import com.yizhuan.xchat_android_core.utils.LogUtils;
|
||||
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
||||
|
||||
import io.agora.ktvkit.KTVKit;
|
||||
@@ -25,7 +27,6 @@ public class AudioEngineManager {
|
||||
}
|
||||
|
||||
private AudioEngineManager() {
|
||||
initRtcEngine(EngineType.TYPE_AGORA);
|
||||
}
|
||||
|
||||
public static AudioEngineManager get() {
|
||||
@@ -35,6 +36,7 @@ public class AudioEngineManager {
|
||||
public void initRtcEngine(EngineType engineType) {
|
||||
switch (engineType) {
|
||||
case TYPE_WJ:
|
||||
// if (iAudioEngine instanceof WJAudioEngineManager) return;
|
||||
if (UserModel.get().getCacheLoginUserInfo() != null) {
|
||||
WJAudioConstant.BUSINESS_UID = String.valueOf(UserModel.get().getCacheLoginUserInfo().getErbanNo());
|
||||
}
|
||||
@@ -42,13 +44,20 @@ public class AudioEngineManager {
|
||||
break;
|
||||
case TYPE_AGORA:
|
||||
default:
|
||||
this.iAudioEngine = new RtcEngineManager(BasicConfig.INSTANCE.getAppContext());
|
||||
this.iAudioEngine = RtcEngineManager.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void startRtcEngine(long uid) {
|
||||
public void startRtcEngine(long uid, String audioSdkType) {
|
||||
LogUtils.d("audioSdkType= "+audioSdkType);
|
||||
RoomInfo curRoomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (curRoomInfo == null) return;
|
||||
if (RoomAudioSdkType.WUJIE.equals(audioSdkType)) {
|
||||
AudioEngineManager.get().initRtcEngine(EngineType.TYPE_WJ);
|
||||
} else {
|
||||
AudioEngineManager.get().initRtcEngine(EngineType.TYPE_AGORA);
|
||||
}
|
||||
joinChannel(curRoomInfo.getRoomId(), uid);
|
||||
if (curRoomInfo.getUid() == uid && curRoomInfo.getType() != RoomInfo.ROOMTYPE_HOME_PARTY) {
|
||||
//设置用户角色为主播,轰趴房不能默认设置房主为主播
|
||||
|
@@ -112,7 +112,6 @@ public final class RtcEngineManager {
|
||||
eventHandler.isEnter = true;
|
||||
if (mRtcEngine == null) {
|
||||
try {
|
||||
|
||||
mRtcEngine = RtcEngine.create(BasicConfig.INSTANCE.getAppContext(), XChatConstants.AGORA_KEY, eventHandler);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.yizhuan.xchat_android_core.manager.agora;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.os.Message;
|
||||
|
||||
import com.orhanobut.logger.Logger;
|
||||
@@ -9,16 +8,12 @@ import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
||||
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||||
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
||||
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
||||
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import io.agora.rtc.Constants;
|
||||
import io.agora.rtc.IRtcEngineEventHandler;
|
||||
|
||||
import static io.agora.rtc.Constants.AUDIO_RECORDING_QUALITY_LOW;
|
||||
|
||||
/**
|
||||
* @author by 梁馨 on 2020/9/14.
|
||||
*/
|
||||
@@ -27,11 +22,9 @@ public class EngineEventHandler extends IRtcEngineEventHandler {
|
||||
public static String TAG = EngineEventHandler.class.getSimpleName();
|
||||
|
||||
private WeakReference<RtcEngineManager> mReference;
|
||||
private volatile boolean isEnter;
|
||||
|
||||
EngineEventHandler(RtcEngineManager manager) {
|
||||
mReference = new WeakReference<>(manager);
|
||||
isEnter = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,21 +53,14 @@ public class EngineEventHandler extends IRtcEngineEventHandler {
|
||||
super.onJoinChannelSuccess(channel, uid, elapsed);
|
||||
Logger.t(TAG).d("onJoinChannelSuccess" + channel + "uid:" + uid);
|
||||
//声网进入频道成功日志
|
||||
RtcEngineManager rtcEngineManager = mReference.get();
|
||||
if (rtcEngineManager != null && isEnter) {
|
||||
isEnter = false;
|
||||
if (!rtcEngineManager.inRoom) {
|
||||
IMNetEaseManager.get().joinAvRoom();
|
||||
}
|
||||
if (rtcEngineManager.needRecord && rtcEngineManager.mRtcEngine != null) {
|
||||
rtcEngineManager.mRtcEngine.startAudioRecording(Environment.getExternalStorageDirectory()
|
||||
+ File.separator + BasicConfig.INSTANCE.getAppContext().getPackageName()
|
||||
+ "/audio/" + System.currentTimeMillis() + ".aac", AUDIO_RECORDING_QUALITY_LOW);
|
||||
}
|
||||
|
||||
rtcEngineManager.inRoom = true;
|
||||
rtcEngineManager.uid = uid;
|
||||
RtcEngineManager manager = mReference.get();
|
||||
if (manager != null) {
|
||||
Message message = manager.mRtcEngineHandler.obtainMessage();
|
||||
message.what = RtcEngineHandler.notifyJoinAvRoom;
|
||||
manager.mRtcEngineHandler.sendMessage(message);
|
||||
manager.uid = uid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -129,23 +115,6 @@ public class EngineEventHandler extends IRtcEngineEventHandler {
|
||||
@Override
|
||||
public void onAudioVolumeIndication(AudioVolumeInfo[] speakers, int totalVolume) {
|
||||
super.onAudioVolumeIndication(speakers, totalVolume);
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
|
||||
if (speakers.length > 0) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (AudioVolumeInfo speaker : speakers) {
|
||||
stringBuilder.append(speaker.uid);
|
||||
stringBuilder.append(",");
|
||||
}
|
||||
if (stringBuilder.length() > 0) {
|
||||
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RtcEngineManager manager = mReference.get();
|
||||
if (manager != null) {
|
||||
Message message = manager.mRtcEngineHandler.obtainMessage();
|
||||
|
@@ -53,7 +53,7 @@ public class RtcEngineHandler extends Handler {
|
||||
+ "/audio/" + System.currentTimeMillis() + ".aac", AUDIO_RECORDING_QUALITY_LOW);
|
||||
}
|
||||
|
||||
} else if (msg.what == 1) {//onAudioVolumeIndication 说话声音音量提示回调
|
||||
} else if (msg.what == onAudioVolumeIndication) {//onAudioVolumeIndication 说话声音音量提示回调
|
||||
IRtcEngineEventHandler.AudioVolumeInfo[] speakers = (IRtcEngineEventHandler.AudioVolumeInfo[]) msg.obj;
|
||||
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (roomInfo == null) return;
|
||||
@@ -87,8 +87,6 @@ public class RtcEngineHandler extends Handler {
|
||||
new RoomEvent().setEvent(RoomEvent.SPEAK_STATE_CHANGE)
|
||||
.setMicPositionList(rtcEngineManager.speakQueueMembersPosition)
|
||||
);
|
||||
} else if (msg.what == 2) {//onUserMuteAudio 用户静音回调
|
||||
Integer uid = (Integer) msg.obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.yizhuan.xchat_android_core.manager.agora;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
@@ -19,6 +18,9 @@ import java.util.Locale;
|
||||
import io.agora.rtc.Constants;
|
||||
import io.agora.rtc.RtcEngine;
|
||||
|
||||
import static io.agora.rtc.Constants.AUDIO_PROFILE_MUSIC_STANDARD;
|
||||
import static io.agora.rtc.Constants.AUDIO_SCENARIO_GAME_STREAMING;
|
||||
|
||||
|
||||
/**
|
||||
* @author by 梁馨 on 2020/9/14.
|
||||
@@ -30,34 +32,36 @@ public class RtcEngineManager extends BaseEngine {
|
||||
public Handler mRtcEngineHandler = new RtcEngineHandler(this);
|
||||
public EngineEventHandler mEngineEventHandler = new EngineEventHandler(this);
|
||||
|
||||
public RtcEngineManager(Context context) {
|
||||
super(context);
|
||||
isAudienceRole = true;
|
||||
this.isMute = true;
|
||||
this.isRemoteMute = false;
|
||||
private static final class Helper {
|
||||
private static final RtcEngineManager INSTANCE = new RtcEngineManager();
|
||||
}
|
||||
|
||||
private RtcEngineManager( ) {
|
||||
super(BasicConfig.INSTANCE.getAppContext());
|
||||
}
|
||||
|
||||
public static RtcEngineManager get() {
|
||||
return RtcEngineManager.Helper.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterChannel(long channelId, long uid) {
|
||||
isMute = false;
|
||||
isRemoteMute = false;
|
||||
needRecord = false;
|
||||
inRoom = false;
|
||||
isAudienceRole = false;
|
||||
Logger.t(TAG).d("enterChannel channelId:%d", channelId);
|
||||
|
||||
if (mRtcEngine == null) {
|
||||
try {
|
||||
mEngineEventHandler = new EngineEventHandler(this);
|
||||
mRtcEngine = RtcEngine.create(BasicConfig.INSTANCE.getAppContext(), XChatConstants.AGORA_KEY, mEngineEventHandler);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(
|
||||
"NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
|
||||
}
|
||||
if (mRtcEngineHandler == null) {
|
||||
mRtcEngineHandler = new RtcEngineHandler(this);
|
||||
}
|
||||
|
||||
|
||||
//设置频道模式为直播
|
||||
mRtcEngine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
|
||||
mRtcEngine.setAudioProfile(Constants.AUDIO_PROFILE_MUSIC_STANDARD,
|
||||
Constants.AUDIO_SCENARIO_GAME_STREAMING);
|
||||
mRtcEngine.setAudioProfile(AUDIO_PROFILE_MUSIC_STANDARD, AUDIO_SCENARIO_GAME_STREAMING);
|
||||
mRtcEngine.enableAudioVolumeIndication(600, 3, false);
|
||||
mRtcEngine.setDefaultAudioRoutetoSpeakerphone(true);
|
||||
mRtcEngine.setExternalVideoSource(true, false, true);
|
||||
@@ -73,8 +77,8 @@ public class RtcEngineManager extends BaseEngine {
|
||||
}
|
||||
|
||||
//先清除频道信息
|
||||
stopAudioMixing();
|
||||
mRtcEngine.leaveChannel();
|
||||
//stopAudioMixing();
|
||||
//mRtcEngine.leaveChannel();
|
||||
|
||||
mRtcEngine.joinChannel(null, String.valueOf(channelId), null, (int) uid);
|
||||
}
|
||||
@@ -106,7 +110,7 @@ public class RtcEngineManager extends BaseEngine {
|
||||
|
||||
@Override
|
||||
public void reEnterChannel(long channelId, long uid) {
|
||||
enterChannel(channelId,uid);
|
||||
enterChannel(channelId, uid);
|
||||
setRemoteMute(isRemoteMute);
|
||||
setMute(isMute);
|
||||
}
|
||||
@@ -155,23 +159,14 @@ public class RtcEngineManager extends BaseEngine {
|
||||
public void setRemoteMute(long uid, boolean mute) {
|
||||
Logger.t(TAG).d("setRemoteMute uid:%s mute:%s", uid, mute);
|
||||
|
||||
if (uid == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (mRtcEngine != null) {
|
||||
//当蒙圈显示的时候房间需要静音,但是在房间的话还是不静音好点吧
|
||||
mRtcEngine.muteRemoteAudioStream((int) uid, mute);
|
||||
// if (result == 0) {
|
||||
// isRemoteMute = mute;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setRole(int role) {
|
||||
Logger.t(TAG).d("setRole role=" + role + ",isAudienceRole:" + isAudienceRole );
|
||||
Logger.t(TAG).d("setRole role=" + role + ",isAudienceRole:" + isAudienceRole);
|
||||
|
||||
if (mRtcEngine != null) {
|
||||
mRtcEngine.setClientRole(role);
|
||||
@@ -281,7 +276,6 @@ public class RtcEngineManager extends BaseEngine {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setChatRoomOnlineStatus(boolean status) {
|
||||
|
||||
|
@@ -0,0 +1,9 @@
|
||||
package com.yizhuan.xchat_android_core.room.bean;
|
||||
|
||||
/**
|
||||
*房间语音SDK类型
|
||||
*/
|
||||
public interface RoomAudioSdkType {
|
||||
String SHENGWANG = "shengwang"; //声网
|
||||
String WUJIE = "wujie"; //无界
|
||||
}
|
@@ -181,6 +181,11 @@ public class RoomInfo implements Parcelable,Serializable {
|
||||
|
||||
private boolean canOpenBlindDate;
|
||||
|
||||
/**
|
||||
* {@link RoomAudioSdkType}
|
||||
*/
|
||||
private String audioSdkType;
|
||||
|
||||
// /**
|
||||
// * 房间角标
|
||||
// */
|
||||
|
Reference in New Issue
Block a user