语音SDK进房动态选择逻辑优化
This commit is contained in:
@@ -10,7 +10,6 @@ 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.bean.RoomInfo;
|
||||||
import com.yizhuan.xchat_android_core.user.UserModel;
|
import com.yizhuan.xchat_android_core.user.UserModel;
|
||||||
import com.yizhuan.xchat_android_core.utils.LogUtils;
|
import com.yizhuan.xchat_android_core.utils.LogUtils;
|
||||||
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
|
||||||
|
|
||||||
import io.agora.ktvkit.KTVKit;
|
import io.agora.ktvkit.KTVKit;
|
||||||
import io.agora.rtc.Constants;
|
import io.agora.rtc.Constants;
|
||||||
@@ -36,11 +35,10 @@ public class AudioEngineManager {
|
|||||||
public void initRtcEngine(EngineType engineType) {
|
public void initRtcEngine(EngineType engineType) {
|
||||||
switch (engineType) {
|
switch (engineType) {
|
||||||
case TYPE_WJ:
|
case TYPE_WJ:
|
||||||
// if (iAudioEngine instanceof WJAudioEngineManager) return;
|
|
||||||
if (UserModel.get().getCacheLoginUserInfo() != null) {
|
if (UserModel.get().getCacheLoginUserInfo() != null) {
|
||||||
WJAudioConstant.BUSINESS_UID = String.valueOf(UserModel.get().getCacheLoginUserInfo().getErbanNo());
|
WJAudioConstant.BUSINESS_UID = String.valueOf(UserModel.get().getCacheLoginUserInfo().getErbanNo());
|
||||||
}
|
}
|
||||||
this.iAudioEngine = new WJAudioEngineManager(BasicConfig.INSTANCE.getAppContext());
|
this.iAudioEngine = WJAudioEngineManager.get();
|
||||||
break;
|
break;
|
||||||
case TYPE_AGORA:
|
case TYPE_AGORA:
|
||||||
default:
|
default:
|
||||||
@@ -50,9 +48,10 @@ public class AudioEngineManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startRtcEngine(long uid, String audioSdkType) {
|
public void startRtcEngine(long uid, String audioSdkType) {
|
||||||
LogUtils.d("audioSdkType= "+audioSdkType);
|
LogUtils.d("audioSdkType= " + audioSdkType);
|
||||||
RoomInfo curRoomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
RoomInfo curRoomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||||
if (curRoomInfo == null) return;
|
if (curRoomInfo == null) return;
|
||||||
|
if (iAudioEngine != null) iAudioEngine.leaveChannel();
|
||||||
if (RoomAudioSdkType.WUJIE.equals(audioSdkType)) {
|
if (RoomAudioSdkType.WUJIE.equals(audioSdkType)) {
|
||||||
AudioEngineManager.get().initRtcEngine(EngineType.TYPE_WJ);
|
AudioEngineManager.get().initRtcEngine(EngineType.TYPE_WJ);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -1,12 +1,9 @@
|
|||||||
package com.yizhuan.xchat_android_core.manager;
|
package com.yizhuan.xchat_android_core.manager;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class BaseEngine implements IAudioEngine {
|
public abstract class BaseEngine implements IAudioEngine {
|
||||||
protected Context context;
|
|
||||||
/**
|
/**
|
||||||
* 角色-主播
|
* 角色-主播
|
||||||
*/
|
*/
|
||||||
@@ -49,8 +46,7 @@ public abstract class BaseEngine implements IAudioEngine {
|
|||||||
*/
|
*/
|
||||||
public volatile boolean isMusicPlaying = false;
|
public volatile boolean isMusicPlaying = false;
|
||||||
|
|
||||||
public BaseEngine(Context context) {
|
public BaseEngine() {
|
||||||
this.context = context;
|
|
||||||
this.speakQueueMembersPosition = new ArrayList<>();
|
this.speakQueueMembersPosition = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,14 +3,11 @@ package com.yizhuan.xchat_android_core.manager.agora;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
|
||||||
import com.orhanobut.logger.Logger;
|
import com.orhanobut.logger.Logger;
|
||||||
import com.yizhuan.xchat_android_core.BuildConfig;
|
|
||||||
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
||||||
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||||||
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
||||||
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
|
|
||||||
import io.agora.rtc.Constants;
|
import io.agora.rtc.Constants;
|
||||||
import io.agora.rtc.IRtcEngineEventHandler;
|
import io.agora.rtc.IRtcEngineEventHandler;
|
||||||
|
|
||||||
@@ -21,21 +18,10 @@ public class EngineEventHandler extends IRtcEngineEventHandler {
|
|||||||
|
|
||||||
public static String TAG = EngineEventHandler.class.getSimpleName();
|
public static String TAG = EngineEventHandler.class.getSimpleName();
|
||||||
|
|
||||||
private WeakReference<RtcEngineManager> mReference;
|
|
||||||
|
|
||||||
EngineEventHandler(RtcEngineManager manager) {
|
|
||||||
mReference = new WeakReference<>(manager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(int err) {
|
public void onError(int err) {
|
||||||
super.onError(err);
|
super.onError(err);
|
||||||
Logger.t(TAG).d("onError" + err);
|
Logger.t(TAG).d("onError" + err);
|
||||||
|
|
||||||
RtcEngineManager rtcEngineManager = mReference.get();
|
|
||||||
if (rtcEngineManager == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case 1107: {
|
case 1107: {
|
||||||
SingleToastUtil.showToast("发生未知错误,请退出房间重新进入");
|
SingleToastUtil.showToast("发生未知错误,请退出房间重新进入");
|
||||||
@@ -53,7 +39,7 @@ public class EngineEventHandler extends IRtcEngineEventHandler {
|
|||||||
super.onJoinChannelSuccess(channel, uid, elapsed);
|
super.onJoinChannelSuccess(channel, uid, elapsed);
|
||||||
Logger.t(TAG).d("onJoinChannelSuccess" + channel + "uid:" + uid);
|
Logger.t(TAG).d("onJoinChannelSuccess" + channel + "uid:" + uid);
|
||||||
//声网进入频道成功日志
|
//声网进入频道成功日志
|
||||||
RtcEngineManager manager = mReference.get();
|
RtcEngineManager manager = RtcEngineManager.get();
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
Message message = manager.mRtcEngineHandler.obtainMessage();
|
Message message = manager.mRtcEngineHandler.obtainMessage();
|
||||||
message.what = RtcEngineHandler.notifyJoinAvRoom;
|
message.what = RtcEngineHandler.notifyJoinAvRoom;
|
||||||
@@ -115,26 +101,22 @@ public class EngineEventHandler extends IRtcEngineEventHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void onAudioVolumeIndication(AudioVolumeInfo[] speakers, int totalVolume) {
|
public void onAudioVolumeIndication(AudioVolumeInfo[] speakers, int totalVolume) {
|
||||||
super.onAudioVolumeIndication(speakers, totalVolume);
|
super.onAudioVolumeIndication(speakers, totalVolume);
|
||||||
RtcEngineManager manager = mReference.get();
|
RtcEngineManager manager = RtcEngineManager.get();
|
||||||
if (manager != null) {
|
Message message = manager.mRtcEngineHandler.obtainMessage();
|
||||||
Message message = manager.mRtcEngineHandler.obtainMessage();
|
message.what = RtcEngineHandler.onAudioVolumeIndication;
|
||||||
message.what = RtcEngineHandler.onAudioVolumeIndication;
|
message.obj = speakers;
|
||||||
message.obj = speakers;
|
manager.mRtcEngineHandler.sendMessage(message);
|
||||||
manager.mRtcEngineHandler.sendMessage(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUserMuteAudio(int uid, boolean muted) {
|
public void onUserMuteAudio(int uid, boolean muted) {
|
||||||
super.onUserMuteAudio(uid, muted);
|
super.onUserMuteAudio(uid, muted);
|
||||||
RtcEngineManager manager = mReference.get();
|
RtcEngineManager manager = RtcEngineManager.get();
|
||||||
if (manager != null) {
|
if (muted) {
|
||||||
if (muted) {
|
Message message = manager.mRtcEngineHandler.obtainMessage();
|
||||||
Message message = manager.mRtcEngineHandler.obtainMessage();
|
message.what = RtcEngineHandler.onUserMuteAudio;
|
||||||
message.what = RtcEngineHandler.onUserMuteAudio;
|
message.obj = uid;
|
||||||
message.obj = uid;
|
manager.mRtcEngineHandler.sendMessage(message);
|
||||||
manager.mRtcEngineHandler.sendMessage(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +125,7 @@ public class EngineEventHandler extends IRtcEngineEventHandler {
|
|||||||
super.onClientRoleChanged(oldRole, newRole);
|
super.onClientRoleChanged(oldRole, newRole);
|
||||||
//角色切换 麦克风切换
|
//角色切换 麦克风切换
|
||||||
if (newRole == Constants.CLIENT_ROLE_BROADCASTER) {
|
if (newRole == Constants.CLIENT_ROLE_BROADCASTER) {
|
||||||
mReference.get().setMute(mReference.get().isMute);
|
RtcEngineManager.get().setMute(RtcEngineManager.get().isMute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,15 +151,9 @@ public class EngineEventHandler extends IRtcEngineEventHandler {
|
|||||||
public void onRemoteAudioStats(RemoteAudioStats remoteAudioStats) {
|
public void onRemoteAudioStats(RemoteAudioStats remoteAudioStats) {
|
||||||
super.onRemoteAudioStats(remoteAudioStats);
|
super.onRemoteAudioStats(remoteAudioStats);
|
||||||
Logger.t(TAG).d("onRemoteAudioStats uid%d", remoteAudioStats.uid);
|
Logger.t(TAG).d("onRemoteAudioStats uid%d", remoteAudioStats.uid);
|
||||||
|
|
||||||
long uid = (long) remoteAudioStats.uid;
|
long uid = (long) remoteAudioStats.uid;
|
||||||
RtcEngineManager rtcEngineManager = mReference.get();
|
|
||||||
if (rtcEngineManager == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果麦上没有这个人,不接收这个人的声音
|
// 如果麦上没有这个人,不接收这个人的声音
|
||||||
rtcEngineManager.setRemoteMute(uid, !AvRoomDataManager.get().checkIsOnMicByAccount(uid + ""));
|
RtcEngineManager.get().setRemoteMute(uid, !AvRoomDataManager.get().checkIsOnMicByAccount(uid + ""));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,8 +12,9 @@ import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
|||||||
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
||||||
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
|
|
||||||
import io.agora.rtc.Constants;
|
import io.agora.rtc.Constants;
|
||||||
import io.agora.rtc.IRtcEngineEventHandler;
|
import io.agora.rtc.IRtcEngineEventHandler;
|
||||||
@@ -31,16 +32,10 @@ public class RtcEngineHandler extends Handler {
|
|||||||
public static int onAudioVolumeIndication = 1;
|
public static int onAudioVolumeIndication = 1;
|
||||||
public static int onUserMuteAudio = 2;
|
public static int onUserMuteAudio = 2;
|
||||||
|
|
||||||
private WeakReference<RtcEngineManager> mReference;
|
|
||||||
|
|
||||||
RtcEngineHandler(RtcEngineManager manager) {
|
|
||||||
mReference = new WeakReference<>(manager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(@NotNull Message msg) {
|
||||||
super.handleMessage(msg);
|
super.handleMessage(msg);
|
||||||
RtcEngineManager rtcEngineManager = mReference.get();
|
RtcEngineManager rtcEngineManager = RtcEngineManager.get();
|
||||||
if (rtcEngineManager == null) return;
|
if (rtcEngineManager == null) return;
|
||||||
if (msg.what == notifyJoinAvRoom) {
|
if (msg.what == notifyJoinAvRoom) {
|
||||||
if (!rtcEngineManager.inRoom) {
|
if (!rtcEngineManager.inRoom) {
|
||||||
|
@@ -5,6 +5,9 @@ import android.os.Handler;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.orhanobut.logger.Logger;
|
import com.orhanobut.logger.Logger;
|
||||||
import com.yizhuan.xchat_android_constants.XChatConstants;
|
import com.yizhuan.xchat_android_constants.XChatConstants;
|
||||||
import com.yizhuan.xchat_android_core.manager.BaseEngine;
|
import com.yizhuan.xchat_android_core.manager.BaseEngine;
|
||||||
@@ -27,17 +30,19 @@ import static io.agora.rtc.Constants.AUDIO_SCENARIO_GAME_STREAMING;
|
|||||||
*/
|
*/
|
||||||
public class RtcEngineManager extends BaseEngine {
|
public class RtcEngineManager extends BaseEngine {
|
||||||
public static String TAG = RtcEngineManager.class.getSimpleName();
|
public static String TAG = RtcEngineManager.class.getSimpleName();
|
||||||
|
@Nullable
|
||||||
public RtcEngine mRtcEngine;
|
public RtcEngine mRtcEngine;
|
||||||
|
@NonNull
|
||||||
public Handler mRtcEngineHandler = new RtcEngineHandler(this);
|
public final Handler mRtcEngineHandler = new RtcEngineHandler();
|
||||||
public EngineEventHandler mEngineEventHandler = new EngineEventHandler(this);
|
@NonNull
|
||||||
|
public final EngineEventHandler mEngineEventHandler = new EngineEventHandler();
|
||||||
|
|
||||||
private static final class Helper {
|
private static final class Helper {
|
||||||
private static final RtcEngineManager INSTANCE = new RtcEngineManager();
|
private static final RtcEngineManager INSTANCE = new RtcEngineManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RtcEngineManager( ) {
|
private RtcEngineManager() {
|
||||||
super(BasicConfig.INSTANCE.getAppContext());
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RtcEngineManager get() {
|
public static RtcEngineManager get() {
|
||||||
@@ -46,11 +51,6 @@ public class RtcEngineManager extends BaseEngine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enterChannel(long channelId, long uid) {
|
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);
|
Logger.t(TAG).d("enterChannel channelId:%d", channelId);
|
||||||
if (mRtcEngine == null) {
|
if (mRtcEngine == null) {
|
||||||
try {
|
try {
|
||||||
@@ -73,13 +73,7 @@ public class RtcEngineManager extends BaseEngine {
|
|||||||
mRtcEngine.setLogFile(Environment.getExternalStorageDirectory()
|
mRtcEngine.setLogFile(Environment.getExternalStorageDirectory()
|
||||||
+ File.separator + BasicConfig.INSTANCE.getAppContext().getPackageName()
|
+ File.separator + BasicConfig.INSTANCE.getAppContext().getPackageName()
|
||||||
+ "/log/agora-rtc.log");
|
+ "/log/agora-rtc.log");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//先清除频道信息
|
|
||||||
//stopAudioMixing();
|
|
||||||
//mRtcEngine.leaveChannel();
|
|
||||||
|
|
||||||
mRtcEngine.joinChannel(null, String.valueOf(channelId), null, (int) uid);
|
mRtcEngine.joinChannel(null, String.valueOf(channelId), null, (int) uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,9 +97,7 @@ public class RtcEngineManager extends BaseEngine {
|
|||||||
mRtcEngine.leaveChannel();
|
mRtcEngine.leaveChannel();
|
||||||
mRtcEngine = null;
|
mRtcEngine = null;
|
||||||
}
|
}
|
||||||
if (mRtcEngineHandler != null) {
|
mRtcEngineHandler.removeCallbacksAndMessages(null);
|
||||||
mRtcEngineHandler.removeCallbacksAndMessages(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -125,18 +117,12 @@ public class RtcEngineManager extends BaseEngine {
|
|||||||
RtcEngine.destroy();
|
RtcEngine.destroy();
|
||||||
mRtcEngine = null;
|
mRtcEngine = null;
|
||||||
}
|
}
|
||||||
if (mRtcEngineHandler != null) {
|
mRtcEngineHandler.removeCallbacksAndMessages(null);
|
||||||
mRtcEngineHandler.removeCallbacksAndMessages(null);
|
isMute = false;
|
||||||
}
|
|
||||||
if (mEngineEventHandler != null) {
|
|
||||||
mEngineEventHandler = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
isMute = true;
|
|
||||||
isRemoteMute = false;
|
isRemoteMute = false;
|
||||||
needRecord = false;
|
needRecord = false;
|
||||||
inRoom = false;
|
inRoom = false;
|
||||||
isAudienceRole = true;
|
isAudienceRole = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -242,7 +228,7 @@ public class RtcEngineManager extends BaseEngine {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mRtcEngine.stopAudioMixing();
|
mRtcEngine.stopAudioMixing();
|
||||||
int result = 0;
|
int result;
|
||||||
try {
|
try {
|
||||||
result = mRtcEngine.startAudioMixing(filePath, loopback, false, cycle);
|
result = mRtcEngine.startAudioMixing(filePath, loopback, false, cycle);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -271,8 +257,7 @@ public class RtcEngineManager extends BaseEngine {
|
|||||||
if (mRtcEngine == null) {
|
if (mRtcEngine == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int audioMixingDuration = mRtcEngine.getAudioMixingDuration();
|
return mRtcEngine.getAudioMixingDuration();
|
||||||
return audioMixingDuration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
package com.yizhuan.xchat_android_core.manager.wj;
|
package com.yizhuan.xchat_android_core.manager.wj;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.netease.nim.uikit.common.util.log.LogUtil;
|
import com.netease.nim.uikit.common.util.log.LogUtil;
|
||||||
import com.wjhd.wy.WJMediaEngine;
|
import com.wjhd.wy.WJMediaEngine;
|
||||||
import com.wjhd.wy.audio.AudioEngine;
|
import com.wjhd.wy.audio.AudioEngine;
|
||||||
@@ -20,6 +22,7 @@ import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
|||||||
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
||||||
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
||||||
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
||||||
|
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -33,33 +36,37 @@ public class WJAudioEngineManager extends BaseEngine {
|
|||||||
public static final String TAG = "WJAudioEngineManager";
|
public static final String TAG = "WJAudioEngineManager";
|
||||||
|
|
||||||
private String logfileDir;
|
private String logfileDir;
|
||||||
|
@Nullable
|
||||||
private AudioEngine mAudioEngine;
|
private AudioEngine mAudioEngine;
|
||||||
private AudioEngineHandler audioEngineHandler;
|
@NonNull
|
||||||
|
private final AudioEngineHandler audioEngineHandler = new AudioHandler();
|
||||||
|
|
||||||
private AudioRole curRole;
|
private AudioRole curRole;
|
||||||
private boolean isServerKicked = false;
|
private boolean isServerKicked = false;
|
||||||
private boolean isChaRoomInChannel = false;
|
private boolean isChaRoomInChannel = false;
|
||||||
private final AtomicInteger lock = new AtomicInteger(0);
|
private final AtomicInteger lock = new AtomicInteger(0);
|
||||||
|
|
||||||
public WJAudioEngineManager(Context context) {
|
private static final class Helper {
|
||||||
super(context);
|
private static final WJAudioEngineManager INSTANCE = new WJAudioEngineManager();
|
||||||
Log.e(TAG, "WJAudioEngineManager: " + WJMediaEngine.getVersion());
|
}
|
||||||
isAudienceRole = true;
|
|
||||||
|
private WJAudioEngineManager() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WJAudioEngineManager get() {
|
||||||
|
return WJAudioEngineManager.Helper.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void initRtcEngine() {
|
private void initRtcEngine() {
|
||||||
WJAudioConstant.LOG_DIR = logfileDir = Environment.getExternalStorageDirectory().getPath() + File.separator + context.getPackageName() + File.separator + "log";
|
WJAudioConstant.LOG_DIR = logfileDir = Environment.getExternalStorageDirectory().getPath() + File.separator + BasicConfig.INSTANCE.getAppContext().getPackageName() + File.separator + "log";
|
||||||
if (audioEngineHandler == null) {
|
|
||||||
audioEngineHandler = new AudioHandler(this);
|
|
||||||
}
|
|
||||||
if (mAudioEngine == null) {
|
if (mAudioEngine == null) {
|
||||||
try {
|
try {
|
||||||
AudioEngine.setRecordingAudioFrameParameters(44100, 2);
|
AudioEngine.setRecordingAudioFrameParameters(44100, 2);
|
||||||
AudioEngine.setLogFileDir(logfileDir);
|
AudioEngine.setLogFileDir(logfileDir);
|
||||||
AudioEngine.setDebugMode(BuildConfig.DEBUG);//设置是否调试模式,底层默认是false
|
AudioEngine.setDebugMode(BuildConfig.DEBUG);//设置是否调试模式,底层默认是false
|
||||||
mAudioEngine = WJMediaEngine.createAudioEngine(context, WJAudioConstant.APPID, audioEngineHandler);
|
mAudioEngine = WJMediaEngine.createAudioEngine(BasicConfig.INSTANCE.getAppContext(), WJAudioConstant.APPID, audioEngineHandler);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("NEED TO check sdk init fatal error" + Log.getStackTraceString(e));
|
throw new RuntimeException("NEED TO check sdk init fatal error" + Log.getStackTraceString(e));
|
||||||
}
|
}
|
||||||
@@ -122,19 +129,11 @@ public class WJAudioEngineManager extends BaseEngine {
|
|||||||
|
|
||||||
private static class AudioHandler extends AudioEngineHandler {
|
private static class AudioHandler extends AudioEngineHandler {
|
||||||
|
|
||||||
private WeakReference<WJAudioEngineManager> mReference;
|
|
||||||
private boolean isEnter;
|
|
||||||
|
|
||||||
|
|
||||||
AudioHandler(WJAudioEngineManager manager) {
|
|
||||||
mReference = new WeakReference<>(manager);
|
|
||||||
isEnter = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(int err) {
|
public void onError(int err) {
|
||||||
if (err == ErrorCode.LOGIN_JOIN_CHANNEL_ERROR) {
|
if (err == ErrorCode.LOGIN_JOIN_CHANNEL_ERROR) {
|
||||||
WJAudioEngineManager manager = mReference.get();
|
WJAudioEngineManager manager = WJAudioEngineManager.get();
|
||||||
Message message = manager.handler.obtainMessage();
|
Message message = manager.handler.obtainMessage();
|
||||||
message.what = WJAudioConstant.MESSAGE_ENTER_CHANNEL_FAIL;
|
message.what = WJAudioConstant.MESSAGE_ENTER_CHANNEL_FAIL;
|
||||||
message.obj = err;
|
message.obj = err;
|
||||||
@@ -146,15 +145,13 @@ public class WJAudioEngineManager extends BaseEngine {
|
|||||||
@Override
|
@Override
|
||||||
public void onJoinChannelSuccess(long channel, long uid, int elapsed) {
|
public void onJoinChannelSuccess(long channel, long uid, int elapsed) {
|
||||||
super.onJoinChannelSuccess(channel, uid, elapsed);
|
super.onJoinChannelSuccess(channel, uid, elapsed);
|
||||||
WJAudioEngineManager manager = mReference.get();
|
WJAudioEngineManager manager = WJAudioEngineManager.get();
|
||||||
if (manager != null) {
|
Message message = manager.handler.obtainMessage();
|
||||||
Message message = manager.handler.obtainMessage();
|
message.what = WJAudioConstant.MESSAGE_ENTER_CHANNEL_SUCCESS;
|
||||||
message.what = WJAudioConstant.MESSAGE_ENTER_CHANNEL_SUCCESS;
|
manager.handler.sendMessage(message);
|
||||||
manager.handler.sendMessage(message);
|
manager.isServerKicked = false;
|
||||||
manager.isServerKicked = false;
|
manager.channelId = channel;
|
||||||
manager.channelId = channel;
|
manager.uid = uid;
|
||||||
manager.uid = uid;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -174,13 +171,11 @@ public class WJAudioEngineManager extends BaseEngine {
|
|||||||
@Override
|
@Override
|
||||||
public void onAudioVolumeIndication(AudioVolumeInfo[] speakers) {
|
public void onAudioVolumeIndication(AudioVolumeInfo[] speakers) {
|
||||||
super.onAudioVolumeIndication(speakers);
|
super.onAudioVolumeIndication(speakers);
|
||||||
WJAudioEngineManager manager = mReference.get();
|
WJAudioEngineManager manager = WJAudioEngineManager.get();
|
||||||
if (manager != null) {
|
Message message = manager.handler.obtainMessage();
|
||||||
Message message = manager.handler.obtainMessage();
|
message.what = WJAudioConstant.MESSAGE_AUDIO_VOLUME_INDICATION;
|
||||||
message.what = WJAudioConstant.MESSAGE_AUDIO_VOLUME_INDICATION;
|
message.obj = speakers;
|
||||||
message.obj = speakers;
|
manager.handler.sendMessage(message);
|
||||||
manager.handler.sendMessage(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -192,21 +187,14 @@ public class WJAudioEngineManager extends BaseEngine {
|
|||||||
@Override
|
@Override
|
||||||
public void onClientRoleChanged(AudioRole oldRole, AudioRole newRole) {
|
public void onClientRoleChanged(AudioRole oldRole, AudioRole newRole) {
|
||||||
super.onClientRoleChanged(oldRole, newRole);
|
super.onClientRoleChanged(oldRole, newRole);
|
||||||
WJAudioEngineManager manager = mReference.get();
|
WJAudioEngineManager.get().curRole = newRole;
|
||||||
if (manager == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
manager.curRole = newRole;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOfflineTimeOut(long channel, long uid) {
|
public void onOfflineTimeOut(long channel, long uid) {
|
||||||
super.onOfflineTimeOut(channel, uid);
|
super.onOfflineTimeOut(channel, uid);
|
||||||
Log.e(TAG, "onOfflineTimeOut~~~");
|
Log.e(TAG, "onOfflineTimeOut~~~");
|
||||||
WJAudioEngineManager manager = mReference.get();
|
WJAudioEngineManager manager = WJAudioEngineManager.get();
|
||||||
if (manager == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
synchronized (manager.lock) {
|
synchronized (manager.lock) {
|
||||||
manager.isServerKicked = true;
|
manager.isServerKicked = true;
|
||||||
}
|
}
|
||||||
@@ -220,7 +208,7 @@ public class WJAudioEngineManager extends BaseEngine {
|
|||||||
@Override
|
@Override
|
||||||
public void OnMicUniqueIDUpdate(String micUniqueID) {
|
public void OnMicUniqueIDUpdate(String micUniqueID) {
|
||||||
super.OnMicUniqueIDUpdate(micUniqueID);
|
super.OnMicUniqueIDUpdate(micUniqueID);
|
||||||
Log.e(TAG, "OnMicUniqueIDUpdate~~~" );
|
Log.e(TAG, "OnMicUniqueIDUpdate~~~");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,9 +220,6 @@ public class WJAudioEngineManager extends BaseEngine {
|
|||||||
AudioEngine.destroy();
|
AudioEngine.destroy();
|
||||||
mAudioEngine = null;
|
mAudioEngine = null;
|
||||||
}
|
}
|
||||||
if (audioEngineHandler != null) {
|
|
||||||
audioEngineHandler = null;
|
|
||||||
}
|
|
||||||
isMute = false;
|
isMute = false;
|
||||||
isRemoteMute = false;
|
isRemoteMute = false;
|
||||||
needRecord = false;
|
needRecord = false;
|
||||||
@@ -266,14 +251,11 @@ public class WJAudioEngineManager extends BaseEngine {
|
|||||||
}
|
}
|
||||||
WJMediaEngine.destroyAudioEngine();
|
WJMediaEngine.destroyAudioEngine();
|
||||||
mAudioEngine = null;
|
mAudioEngine = null;
|
||||||
if (audioEngineHandler != null) {
|
|
||||||
audioEngineHandler = null;
|
|
||||||
}
|
|
||||||
isMute = false;
|
isMute = false;
|
||||||
isRemoteMute = false;
|
isRemoteMute = false;
|
||||||
needRecord = false;
|
needRecord = false;
|
||||||
inRoom = false;
|
inRoom = false;
|
||||||
isAudienceRole = true;
|
isAudienceRole = false;
|
||||||
curRole = AudioRole.NO_ROLE;
|
curRole = AudioRole.NO_ROLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user