[Modify]移除zego
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -244,19 +244,6 @@ public class XChatConstants {
|
||||
public static final int KICK_OUT_ROOM_LIMIT_ENTER_TIME = 5 * 60 * 1000;
|
||||
public static final int CODE_IGNORE_TOAST = 5263;
|
||||
public static int SELECT_ANIM_DURATION = 2500;
|
||||
public static long ZEGO_APP_ID = BuildConfig.DEBUG ? 1067458582L : 1094103343L;
|
||||
public static byte[] ZEGO_APP_SIGN = BuildConfig.DEBUG ?
|
||||
new byte[]{
|
||||
(byte) 0x2b, (byte) 0x86, (byte) 0x24, (byte) 0xef, (byte) 0xd9, (byte) 0x96, (byte) 0xf1, (byte) 0x1c, (byte) 0x6b,
|
||||
(byte) 0xa2, (byte) 0x28, (byte) 0xc3, (byte) 0xef, (byte) 0x24, (byte) 0xdd, (byte) 0x64, (byte) 0x2e, (byte) 0xd7,
|
||||
(byte) 0x33, (byte) 0x3f, (byte) 0x33, (byte) 0x90, (byte) 0x07, (byte) 0x53, (byte) 0xeb, (byte) 0xd2, (byte) 0xd2,
|
||||
(byte) 0x4e, (byte) 0xc5, (byte) 0xed, (byte) 0xfd, (byte) 0x43} :
|
||||
new byte[]{
|
||||
(byte) 0x68, (byte) 0x2a, (byte) 0x50, (byte) 0xcf, (byte) 0x47, (byte) 0x12, (byte) 0xfd, (byte) 0x5e, (byte) 0x4b,
|
||||
(byte) 0xb5, (byte) 0x69, (byte) 0xbb, (byte) 0x57, (byte) 0x99, (byte) 0x81, (byte) 0x4c, (byte) 0xb5, (byte) 0x8a,
|
||||
(byte) 0x2e, (byte) 0x95, (byte) 0xb1, (byte) 0xe3, (byte) 0x48, (byte) 0x7f, (byte) 0x86, (byte) 0x01, (byte) 0x78,
|
||||
(byte) 0xf1, (byte) 0xe0, (byte) 0x0c, (byte) 0x7a, (byte) 0xca
|
||||
};
|
||||
|
||||
/**
|
||||
* Adjust配置
|
||||
|
@@ -4,7 +4,6 @@ package com.yizhuan.xchat_android_core.manager;
|
||||
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.trtc.TRtcEngineManager;
|
||||
import com.yizhuan.xchat_android_core.manager.zego.ZegoEngineManager;
|
||||
import com.yizhuan.xchat_android_core.room.bean.RoomAudioSdkType;
|
||||
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
||||
import com.yizhuan.xchat_android_core.utils.LogUtils;
|
||||
@@ -31,9 +30,6 @@ public class AudioEngineManager {
|
||||
|
||||
public void initRtcEngine(EngineType engineType) {
|
||||
switch (engineType) {
|
||||
case TYPE_ZEGO:
|
||||
this.iAudioEngine = ZegoEngineManager.get();
|
||||
break;
|
||||
case TYPE_TRTC:
|
||||
this.iAudioEngine = TRtcEngineManager.get();
|
||||
break;
|
||||
@@ -53,9 +49,6 @@ public class AudioEngineManager {
|
||||
if (audioSdkType == null) audioSdkType = RoomAudioSdkType.SHENGWANG;
|
||||
|
||||
switch (audioSdkType) {
|
||||
case RoomAudioSdkType.ZEGO:
|
||||
initRtcEngine(EngineType.TYPE_ZEGO);
|
||||
break;
|
||||
case RoomAudioSdkType.TRTC:
|
||||
initRtcEngine(EngineType.TYPE_TRTC);
|
||||
break;
|
||||
|
@@ -4,6 +4,5 @@ public enum EngineType {
|
||||
TYPE_AGORA,
|
||||
TYPE_AGORA_QUICKNESS,
|
||||
TYPE_QTT_AUDIO,
|
||||
TYPE_ZEGO,
|
||||
TYPE_TRTC,
|
||||
}
|
||||
|
@@ -1,56 +0,0 @@
|
||||
package com.yizhuan.xchat_android_core.manager.zego;
|
||||
|
||||
import com.zego.zegoaudioroom.ZegoAudioRoomDelegate;
|
||||
import com.zego.zegoaudioroom.ZegoAudioStream;
|
||||
import com.zego.zegoaudioroom.ZegoAudioStreamType;
|
||||
import com.zego.zegoliveroom.entity.ZegoBigRoomMessage;
|
||||
import com.zego.zegoliveroom.entity.ZegoRoomMessage;
|
||||
import com.zego.zegoliveroom.entity.ZegoUserState;
|
||||
|
||||
public class ZegoAudioRoomDelegateWrapper implements ZegoAudioRoomDelegate {
|
||||
@Override
|
||||
public void onKickOut(int i, String s, String s1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(int i, String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamUpdate(ZegoAudioStreamType zegoAudioStreamType, ZegoAudioStream zegoAudioStream) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserUpdate(ZegoUserState[] zegoUserStates, int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateOnlineCount(String s, int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecvRoomMessage(String s, ZegoRoomMessage[] zegoRoomMessages) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecvBigRoomMessage(String s, ZegoBigRoomMessage[] zegoBigRoomMessages) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecvCustomCommand(String s, String s1, String s2, String s3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamExtraInfoUpdated(ZegoAudioStream[] zegoAudioStreams, String s) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,540 +0,0 @@
|
||||
package com.yizhuan.xchat_android_core.manager.zego;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.yizhuan.xchat_android_constants.XChatConstants;
|
||||
import com.yizhuan.xchat_android_core.BuildConfig;
|
||||
import com.yizhuan.xchat_android_library.common.application.Env;
|
||||
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
||||
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
||||
import com.yizhuan.xchat_android_core.manager.BaseEngine;
|
||||
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||||
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
||||
import com.yizhuan.xchat_android_core.music.db.bean.LocalMusicBean;
|
||||
import com.yizhuan.xchat_android_core.music.model.PlayerModel;
|
||||
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
||||
import com.yizhuan.xchat_android_core.utils.LogUtils;
|
||||
import com.yizhuan.xchat_android_library.utils.JavaUtil;
|
||||
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
||||
import com.yizhuan.xchat_android_library.utils.pref.CommonPref;
|
||||
import com.zego.zegoaudioroom.ZegoAudioLivePublisherDelegate;
|
||||
import com.zego.zegoaudioroom.ZegoAudioRoom;
|
||||
import com.zego.zegoaudioroom.ZegoAudioStream;
|
||||
import com.zego.zegoaudioroom.ZegoAudioStreamType;
|
||||
import com.zego.zegoavkit2.ZegoMediaPlayer;
|
||||
import com.zego.zegoavkit2.soundlevel.IZegoSoundLevelCallback;
|
||||
import com.zego.zegoavkit2.soundlevel.ZegoSoundLevelInfo;
|
||||
import com.zego.zegoavkit2.soundlevel.ZegoSoundLevelMonitor;
|
||||
import com.zego.zegoliveroom.ZegoLiveRoom;
|
||||
import com.zego.zegoliveroom.constants.ZegoConstants;
|
||||
import com.zego.zegoliveroom.entity.ZegoPublishStreamQuality;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by MadisonRong on 2019-12-17
|
||||
* <p>
|
||||
* 我们的 uid 对应 zego 的 streamID
|
||||
*/
|
||||
public class ZegoEngineManager extends BaseEngine {
|
||||
|
||||
private static final String TAG = "ZegoEngineManager";
|
||||
|
||||
private ZegoAudioRoom zegoAudioRoom;
|
||||
private ZegoMediaPlayer zegoMediaPlayer;
|
||||
|
||||
/**
|
||||
* 自己说话时候收到的回调,缓存起来
|
||||
*/
|
||||
private volatile ZegoSoundLevelInfo mySoundLevel;
|
||||
|
||||
private final Set<String> playStreamIdSet = new HashSet<>();
|
||||
|
||||
private static final class Helper {
|
||||
private static final ZegoEngineManager INSTANCE = new ZegoEngineManager();
|
||||
}
|
||||
|
||||
|
||||
private ZegoEngineManager() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static ZegoEngineManager get() {
|
||||
return ZegoEngineManager.Helper.INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void enterChannel(long channelId, long uid) {
|
||||
this.uid = uid;
|
||||
initZegoAudioRoom();
|
||||
zegoAudioRoom.loginRoom(String.valueOf(channelId), code -> {
|
||||
//登录没完成就已经leaveChannel了 这里可能会NPE
|
||||
if (zegoAudioRoom == null) return;
|
||||
if (code == 0) {
|
||||
// 重置麦克风和扬声器的状态
|
||||
zegoAudioRoom.enableMic(!isMute);
|
||||
zegoAudioRoom.enableSpeaker(!isRemoteMute);
|
||||
if (isMusicPlaying) {
|
||||
startAudioMixing(PlayerModel.get().getCurrent().getLocalUri(), false, 1);
|
||||
}
|
||||
//IMNetEaseManager.get().joinAvRoom();
|
||||
} else {
|
||||
// 登录失败
|
||||
LogUtils.e("Zego onLoginCompletion: code: " + code);
|
||||
// CrashReport.postCatchedException(new Throwable("enterChannel failed zegoCode = " + code + "channelId = " + channelId));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initZegoAudioRoom() {
|
||||
// 测试环境开关 (可选设置)
|
||||
boolean debug = BuildConfig.DEBUG && CommonPref.instance(BasicConfig.INSTANCE.getAppContext()).getInt(Env.KEY_ENVIRONMENT) == Env.EnvType.Debug.code;
|
||||
ZegoAudioRoom.setUseTestEnv(debug);
|
||||
ZegoLiveRoom.setTestEnv(debug);
|
||||
Log.e(TAG, "initRtcEngine: Env: " + debug);
|
||||
// 根据当前运行模式是否打开调试信息,仅供参考 (可选设置)
|
||||
ZegoAudioRoom.setVerbose(BuildConfig.DEBUG);
|
||||
|
||||
// 设置 UserID 和 UserName。userID 和 userName 来自于 App 自定义的账号系统 (必须设置)
|
||||
ZegoAudioRoom.setUser(String.valueOf(uid), String.valueOf(uid));
|
||||
//调用这个接口,会针对满足条件的应用在支持的机型进行适配启用系统的耳返优化的功能
|
||||
ZegoLiveRoom.setConfig("adapt_to_system_karaoke=" + (enableLoopBack ? "true" : "false"));
|
||||
// 采集率 48K
|
||||
ZegoLiveRoom.setConfig("audio_encoder_samplerate=48000");
|
||||
|
||||
ZegoAudioRoom.setAudioDeviceMode(ZegoConstants.AudioDeviceMode.General);
|
||||
zegoAudioRoom = new ZegoAudioRoom();
|
||||
// 初始化 ZegoAudioRoom 对象。AppID 和 AppSign 由 Zego 分配给各 App。其中,为了安全考虑,建议将 AppSign 存储在 App 的业务后台,需要使用时从后台获取 (必须调用)
|
||||
boolean initWithAppId = zegoAudioRoom.initWithAppId(XChatConstants.ZEGO_APP_ID, XChatConstants.ZEGO_APP_SIGN, BasicConfig.INSTANCE.getAppContext());
|
||||
System.out.println("init Zego App: " + initWithAppId);
|
||||
// 手动推流
|
||||
zegoAudioRoom.setManualPublish(true);
|
||||
zegoAudioRoom.setManualPlay(true);
|
||||
// 双声道
|
||||
// 设置始终生效,直到重新通过此 API 修改该值或者引擎销毁
|
||||
// 0表示使用单声道采集,非0表示使用双声道采集
|
||||
//ZegoAudioDevice.enableCaptureStereo(2);
|
||||
// 设置编码声道数为双声道
|
||||
// zegoAudioRoom.setAudioChannelCount(2);
|
||||
// 回声消除
|
||||
zegoAudioRoom.enableAEC(true);
|
||||
// 耳机插入状态下使用回声消除
|
||||
zegoAudioRoom.enableAECWhenHeadsetDetected(true);
|
||||
// 音频采集自动增益
|
||||
zegoAudioRoom.enableAGC(true);
|
||||
// 开启离散音频包发送
|
||||
zegoAudioRoom.enableDTX(true);
|
||||
// 初始化是否需要耳返
|
||||
zegoAudioRoom.enableLoopback(enableLoopBack);
|
||||
// 设置码率为 128K
|
||||
zegoAudioRoom.setAudioBitrate(128000);
|
||||
// 配合使用双声道
|
||||
//zegoAudioRoom.setLatencyMode(ZegoConstants.LatencyMode.Low3);
|
||||
zegoAudioRoom.setAudioRoomDelegate(new ZegoAudioRoomDelegateWrapper() {
|
||||
@Override
|
||||
public void onDisconnect(int i, String s) {
|
||||
IMNetEaseManager.postRoomEvent(new RoomEvent().setEvent(RoomEvent.RTC_ENGINE_NETWORK_CLOSE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamUpdate(ZegoAudioStreamType zegoAudioStreamType, ZegoAudioStream zegoAudioStream) {
|
||||
super.onStreamUpdate(zegoAudioStreamType, zegoAudioStream);
|
||||
boolean play = zegoAudioStreamType == ZegoAudioStreamType.ZEGO_AUDIO_STREAM_ADD;
|
||||
playStreamId(zegoAudioStream.getStreamId(), play);
|
||||
if (play) {
|
||||
playStreamIdSet.add(zegoAudioStream.getStreamId());
|
||||
} else {
|
||||
playStreamIdSet.remove(zegoAudioStream.getStreamId());
|
||||
}
|
||||
|
||||
LogUtils.d("ZegoAudioStreamType=" + zegoAudioStreamType.name() + " zegoAudioStream=" + zegoAudioStream.getStreamId());
|
||||
}
|
||||
});
|
||||
zegoAudioRoom.setAudioPublisherDelegate(new ZegoAudioLivePublisherDelegate() {
|
||||
@Override
|
||||
public void onPublishStateUpdate(int code, String s, HashMap<String, Object> hashMap) {
|
||||
if (code != 0) {
|
||||
zegoAudioRoom.restartPublishStream();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPublishQualityUpdate(String s, ZegoPublishStreamQuality zegoPublishStreamQuality) {
|
||||
|
||||
}
|
||||
});
|
||||
ZegoSoundLevelMonitor.getInstance().setCycle(600);
|
||||
ZegoSoundLevelMonitor.getInstance()
|
||||
.setCallback(new IZegoSoundLevelCallback() {
|
||||
@Override
|
||||
public void onSoundLevelUpdate(ZegoSoundLevelInfo[] zegoSoundLevelInfos) {
|
||||
// 别人说话的时候收到的回调
|
||||
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (roomInfo == null) return;
|
||||
if (speakQueueMembersPosition.size() > 0) {
|
||||
speakQueueMembersPosition.clear();
|
||||
}
|
||||
if (mySoundLevel != null && mySoundLevel.soundLevel > 0) {
|
||||
addToSpeakerList(mySoundLevel);
|
||||
}
|
||||
if (zegoSoundLevelInfos == null || zegoSoundLevelInfos.length == 0) return;
|
||||
for (ZegoSoundLevelInfo speaker : zegoSoundLevelInfos) {
|
||||
LogUtils.d("soundLevel=" + speaker.soundLevel);
|
||||
if (speaker.soundLevel > 0) {
|
||||
addToSpeakerList(speaker);
|
||||
}
|
||||
}
|
||||
IMNetEaseManager.get()
|
||||
.getChatRoomEventObservable()
|
||||
.onNext(new RoomEvent().setEvent(RoomEvent.SPEAK_STATE_CHANGE)
|
||||
.setMicPositionList(speakQueueMembersPosition));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCaptureSoundLevelUpdate(ZegoSoundLevelInfo zegoSoundLevelInfo) {
|
||||
// 自己说话的时候收到的回调
|
||||
if (speakQueueMembersPosition.size() > 0) {
|
||||
speakQueueMembersPosition.clear();
|
||||
}
|
||||
if (zegoSoundLevelInfo.soundLevel > 0) {
|
||||
addToSpeakerList(zegoSoundLevelInfo);
|
||||
mySoundLevel = zegoSoundLevelInfo;
|
||||
IMNetEaseManager.get()
|
||||
.getChatRoomEventObservable()
|
||||
.onNext(new RoomEvent().setEvent(RoomEvent.SPEAK_STATE_CHANGE)
|
||||
.setMicPositionList(speakQueueMembersPosition));
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
ZegoSoundLevelMonitor.getInstance().start();
|
||||
// 初始化媒体播放器
|
||||
zegoMediaPlayer = new ZegoMediaPlayer();
|
||||
zegoMediaPlayer.init(ZegoMediaPlayer.PlayerTypeAux, 0);
|
||||
zegoMediaPlayer.setEventWithIndexCallback(new ZegoMediaPlayerCallbackWrapper() {
|
||||
@Override
|
||||
public void onPlayEnd(int i) {
|
||||
super.onPlayEnd(i);
|
||||
IMNetEaseManager.get().getChatRoomEventObservable().onNext(
|
||||
new RoomEvent().setEvent(RoomEvent.METHOD_ON_AUDIO_MIXING_FINISHED)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加到说话者队列里
|
||||
*
|
||||
* @param zegoSoundLevelInfo
|
||||
*/
|
||||
private void addToSpeakerList(ZegoSoundLevelInfo zegoSoundLevelInfo) {
|
||||
int micPosition = getMicPosition(zegoSoundLevelInfo);
|
||||
LogUtils.d("soundLevel=" + zegoSoundLevelInfo.soundLevel + "micPosition=" + micPosition);
|
||||
// 在麦序上,但不在说话者队列里,加入到队列中
|
||||
if (micPosition != Integer.MIN_VALUE &&
|
||||
!speakQueueMembersPosition.contains(micPosition)) {
|
||||
speakQueueMembersPosition.add(micPosition);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自己的麦位,用来检查自己有没有加到说话者队列里的权限
|
||||
*
|
||||
* @param zegoSoundLevelInfo
|
||||
* @return
|
||||
*/
|
||||
public int getMicPosition(ZegoSoundLevelInfo zegoSoundLevelInfo) {
|
||||
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (roomInfo == null) return Integer.MIN_VALUE;
|
||||
// 计算麦位
|
||||
int uid = getUidFromSteamID(zegoSoundLevelInfo.streamID);
|
||||
// 如果 streamID 为零,则表示这条流是自己
|
||||
uid = uid == 0 ? (int) AuthModel.get().getCurrentUid() : uid;
|
||||
int micPosition = AvRoomDataManager.get().getMicPosition(uid);
|
||||
if (micPosition == Integer.MIN_VALUE &&
|
||||
uid == AuthModel.get().getCurrentUid()) {
|
||||
// 如果麦上没有自己,并且自己在说话,要把自己变成听众
|
||||
setRole(ROLE_AUDIENCE);
|
||||
}
|
||||
//防止黑麦,上麦的时候会重新解除禁言
|
||||
if (micPosition == Integer.MIN_VALUE &&
|
||||
uid != AuthModel.get().getCurrentUid()) {
|
||||
playStreamId(zegoSoundLevelInfo.streamID, false);
|
||||
}
|
||||
LogUtils.d("uid=" + uid + "----micPosition=" + micPosition);
|
||||
return micPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int stopAudioMixing() {
|
||||
if (zegoMediaPlayer != null) {
|
||||
zegoMediaPlayer.stop();
|
||||
isMusicPlaying = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetChannel() {
|
||||
if (zegoAudioRoom != null) {
|
||||
removeCallbacks();
|
||||
zegoAudioRoom.logoutRoom();
|
||||
zegoAudioRoom = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reEnterChannel(long channelId, long uid) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void leaveChannel() {
|
||||
if (zegoAudioRoom != null) {
|
||||
stopAudioMixing();
|
||||
removeCallbacks();
|
||||
zegoAudioRoom.logoutRoom();
|
||||
zegoAudioRoom = null;
|
||||
try {
|
||||
ZegoSoundLevelMonitor.getInstance().stop();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (UnsatisfiedLinkError ignore) {
|
||||
}
|
||||
}
|
||||
if (zegoMediaPlayer != null) {
|
||||
zegoMediaPlayer.uninit();
|
||||
}
|
||||
isMute = false;
|
||||
isRemoteMute = false;
|
||||
needRecord = false;
|
||||
isAudienceRole = false;
|
||||
}
|
||||
|
||||
// 移除所有回调
|
||||
private void removeCallbacks() {
|
||||
zegoAudioRoom.setAudioRoomDelegate(null);
|
||||
zegoAudioRoom.setAudioPublisherDelegate(null);
|
||||
zegoAudioRoom.setAudioPlayerDelegate(null);
|
||||
zegoAudioRoom.setAudioLiveEventDelegate(null);
|
||||
zegoAudioRoom.setAudioRecordDelegate(null);
|
||||
zegoAudioRoom.setAudioDeviceEventDelegate(null);
|
||||
zegoAudioRoom.setAudioAVEngineDelegate(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemoteMute(boolean mute) {
|
||||
if (zegoAudioRoom == null) {
|
||||
return;
|
||||
}
|
||||
boolean result = zegoAudioRoom.enableSpeaker(!mute);
|
||||
if (result) {
|
||||
isRemoteMute = mute;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnableLoopBack() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectOtherRoom(String roomId, long userUid) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnectOtherRoom() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void playStreamIdByUid(long uid, boolean play) {
|
||||
for (String streamId : playStreamIdSet) {
|
||||
if (uid == getUidFromSteamID(streamId)) {
|
||||
playStreamId(streamId, play);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playStreamId(String streamId, boolean play) {
|
||||
if (zegoAudioRoom == null) {
|
||||
return;
|
||||
}
|
||||
if (play) {
|
||||
zegoAudioRoom.startPlay(streamId);
|
||||
} else {
|
||||
zegoAudioRoom.stopPlay(streamId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setRole(int role) {
|
||||
if (zegoAudioRoom == null) {
|
||||
return false;
|
||||
}
|
||||
if (!isMute) {
|
||||
if (role == ROLE_BROADCASTER ) {
|
||||
zegoAudioRoom.startPublish();
|
||||
} else if (role == ROLE_AUDIENCE) {
|
||||
zegoAudioRoom.stopPublish();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMute(boolean mute) {
|
||||
if (zegoAudioRoom == null || zegoMediaPlayer == null) {
|
||||
return;
|
||||
}
|
||||
zegoAudioRoom.enableMic(!mute);
|
||||
if (mute) {
|
||||
zegoAudioRoom.stopPublish();
|
||||
isMute = true;
|
||||
// 清空缓存,表示自己没有在说话
|
||||
mySoundLevel = null;
|
||||
} else {
|
||||
zegoAudioRoom.startPublish();
|
||||
isMute = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchLoopBack(boolean enableLoopBack) {
|
||||
super.switchLoopBack(enableLoopBack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChatRoomOnlineStatus(boolean status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setASMRMode(boolean enable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustAudioMixingVolume(int volume) {
|
||||
if (zegoMediaPlayer == null) {
|
||||
return;
|
||||
}
|
||||
zegoMediaPlayer.setVolume(getZegoVolumeByLinearValue(volume));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustRecordingSignalVolume(int volume) {
|
||||
if (zegoAudioRoom == null) {
|
||||
return;
|
||||
}
|
||||
zegoAudioRoom.setCaptureVolume(getZegoVolumeByLinearValue(volume));
|
||||
}
|
||||
|
||||
/**
|
||||
* zego 提供的音量转变方法
|
||||
*
|
||||
* @param linearValue
|
||||
* @return
|
||||
*/
|
||||
private static int getZegoVolumeByLinearValue(int linearValue) {
|
||||
float fVolume = linearValue / 100f;
|
||||
float db = (float) Math.log10(fVolume) * 20;
|
||||
if (db > 0) {
|
||||
db = 0;
|
||||
} else if (db < -40) {
|
||||
db = -40;
|
||||
}
|
||||
|
||||
// 0 ~ 15 db
|
||||
if (db > -15) {
|
||||
return (int) ((db / 30 + 1) * 100);
|
||||
} else if (db > -27) {
|
||||
return (int) ((db + 35) / 40 * 100);
|
||||
} else {
|
||||
return (int) ((db + 40) / 65 * 100);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int resumeAudioMixing() {
|
||||
if (zegoMediaPlayer == null) {
|
||||
return -1;
|
||||
}
|
||||
if (zegoMediaPlayer.getCurrentDuration() > 0) {
|
||||
zegoMediaPlayer.resume();
|
||||
} else {
|
||||
LocalMusicBean current = PlayerModel.get().getCurrent();
|
||||
startAudioMixing(current.getLocalUri(), false, 1);
|
||||
}
|
||||
isMusicPlaying = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int pauseAudioMixing() {
|
||||
if (zegoMediaPlayer == null) {
|
||||
return -1;
|
||||
}
|
||||
zegoMediaPlayer.pause();
|
||||
isMusicPlaying = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int startAudioMixing(String filePath, boolean loopback, int cycle) {
|
||||
if (zegoMediaPlayer == null || TextUtils.isEmpty(filePath)) {
|
||||
return -1;
|
||||
}
|
||||
zegoMediaPlayer.stop();
|
||||
zegoMediaPlayer.start(filePath, loopback);
|
||||
isMusicPlaying = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAudioMixingCurrentPosition() {
|
||||
if (zegoMediaPlayer == null) {
|
||||
return -1;
|
||||
}
|
||||
return (int) zegoMediaPlayer.getCurrentDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAudioMixingDuration() {
|
||||
if (zegoMediaPlayer == null) {
|
||||
return -1;
|
||||
}
|
||||
return (int) zegoMediaPlayer.getDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemoteMute(long uid, boolean mute) {
|
||||
playStreamIdByUid(uid,!mute);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* streamID 的格式是 s-[uid]-[随机数]
|
||||
*
|
||||
* @param streamID
|
||||
* @return
|
||||
*/
|
||||
private int getUidFromSteamID(String streamID) {
|
||||
if (TextUtils.isEmpty(streamID)) {
|
||||
return -2;
|
||||
}
|
||||
String[] strings = streamID.split("-");
|
||||
if (strings.length <= 1) {
|
||||
return -1;
|
||||
}
|
||||
String uid = strings[1];
|
||||
return JavaUtil.str2int(uid);
|
||||
}
|
||||
}
|
@@ -1,85 +0,0 @@
|
||||
package com.yizhuan.xchat_android_core.manager.zego;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import com.zego.zegoavkit2.IZegoMediaPlayerWithIndexCallback;
|
||||
|
||||
|
||||
public class ZegoMediaPlayerCallbackWrapper implements IZegoMediaPlayerWithIndexCallback {
|
||||
|
||||
@Override
|
||||
public void onPlayStart(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayPause(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayStop(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayResume(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayError(int i, int i1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoBegin(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAudioBegin(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayEnd(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBufferBegin(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBufferEnd(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSeekComplete(int i, long l, int i1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSnapshot(Bitmap bitmap, int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadComplete(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProcessInterval(long l, int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReadEOF(int i) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -5,7 +5,6 @@ package com.yizhuan.xchat_android_core.room.bean;
|
||||
*/
|
||||
public interface RoomAudioSdkType {
|
||||
String SHENGWANG = "shengwang"; //声网
|
||||
String ZEGO = "zego"; //zego
|
||||
String TRTC = "trtc"; //trtc
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user