feat:初步完成声网个播PK功能
This commit is contained in:
@@ -75,7 +75,8 @@ public class XChatConstants {
|
||||
/**
|
||||
* 聲網 key
|
||||
*/
|
||||
public static final String AGORA_KEY_DEBUG = "7ae1a8dabe7a44a9a67c829faa409e70";
|
||||
public static final String AGORA_KEY_DEBUG = "f8713b6ec98c4c01adaf34cb4fa091b1";
|
||||
// public static final String AGORA_KEY_DEBUG = "7ae1a8dabe7a44a9a67c829faa409e70";
|
||||
|
||||
/**
|
||||
* 阿裏雲日誌空間名字
|
||||
|
@@ -82,6 +82,7 @@ public class AudioEngineManager {
|
||||
|
||||
//设置静音
|
||||
public void setRemoteMute(boolean mute) {
|
||||
LogUtils.d("setRemoteMute() mute:" + mute);
|
||||
if (this.iAudioEngine == null) return;
|
||||
this.iAudioEngine.setRemoteMute(mute);
|
||||
}
|
||||
@@ -106,6 +107,7 @@ public class AudioEngineManager {
|
||||
* @param role CLIENT_ROLE_AUDIENCE: 听众 ,ROLE_BROADCASTER: 主播
|
||||
*/
|
||||
public boolean setRole(int role) {
|
||||
LogUtils.d("setRole() role:" + role);
|
||||
return this.iAudioEngine != null && this.iAudioEngine.setRole(role);
|
||||
}
|
||||
|
||||
@@ -123,6 +125,7 @@ public class AudioEngineManager {
|
||||
* @param mute true:静音,false:不静音
|
||||
*/
|
||||
public void setMute(boolean mute) {
|
||||
LogUtils.d("setMute() mute:" + mute);
|
||||
if (this.iAudioEngine == null) return;
|
||||
this.iAudioEngine.setMute(mute);
|
||||
}
|
||||
@@ -161,12 +164,14 @@ public class AudioEngineManager {
|
||||
}
|
||||
|
||||
public void connectOtherRoom(String roomId, long userUid) {
|
||||
LogUtils.d("connectOtherRoom() roomId:" + roomId + " userUid:" + userUid);
|
||||
if (iAudioEngine != null) {
|
||||
iAudioEngine.connectOtherRoom(roomId, userUid);
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnectOtherRoom() {
|
||||
LogUtils.d("disconnectOtherRoom()");
|
||||
if (iAudioEngine != null) {
|
||||
iAudioEngine.disconnectOtherRoom();
|
||||
}
|
||||
@@ -228,6 +233,7 @@ public class AudioEngineManager {
|
||||
|
||||
|
||||
public void setRemoteMute(long uid, boolean mute) {
|
||||
LogUtils.d("setRemoteMute() uid:" + uid + " mute:" + mute);
|
||||
if (this.iAudioEngine == null) return;
|
||||
this.iAudioEngine.setRemoteMute(uid, mute);
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@ import android.os.Message;
|
||||
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.yizhuan.xchat_android_core.R;
|
||||
import com.yizhuan.xchat_android_core.im.custom.bean.RoomPkBean;
|
||||
import com.yizhuan.xchat_android_core.manager.AudioEngineManager;
|
||||
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
||||
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||||
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
||||
@@ -133,9 +135,22 @@ public class EngineEventHandler extends IRtcEngineEventHandler {
|
||||
//角色切换 麦克风切换
|
||||
if (newRole == Constants.CLIENT_ROLE_BROADCASTER) {
|
||||
RtcEngineManager.get().setMute(RtcEngineManager.get().isMute);
|
||||
if (AvRoomDataManager.get().isRoomOwner() &&
|
||||
AvRoomDataManager.get().isSingleRoom() &&
|
||||
AvRoomDataManager.get().isOpenAnotherPKMode()) {
|
||||
RoomPkBean pkBean = AvRoomDataManager.get().roomPkLiveData.getValue();
|
||||
if (pkBean != null) {
|
||||
AudioEngineManager.get().connectOtherRoom(String.valueOf(pkBean.getARoomId()), pkBean.getAUid());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChannelMediaRelayStateChanged(int state, int code) {
|
||||
super.onChannelMediaRelayStateChanged(state, code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAudioMixingFinished() {//伴奏播放已结束回调
|
||||
super.onAudioMixingFinished();
|
||||
@@ -156,7 +171,8 @@ public class EngineEventHandler extends IRtcEngineEventHandler {
|
||||
Logger.t(TAG).d("onRemoteAudioStats uid%d", remoteAudioStats.uid);
|
||||
long uid = (long) remoteAudioStats.uid;
|
||||
// 如果麦上没有这个人,不接收这个人的声音
|
||||
RtcEngineManager.get().setRemoteMute(uid, !AvRoomDataManager.get().checkIsOnMicByAccount(uid + ""));
|
||||
|
||||
if (!(AvRoomDataManager.get().isSingleRoom() && AvRoomDataManager.get().isOpenAnotherPKMode())) {
|
||||
RtcEngineManager.get().setRemoteMute(uid, !AvRoomDataManager.get().checkIsOnMicByAccount(uid + ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -72,7 +72,8 @@ public class RtcEngineHandler extends Handler {
|
||||
// 如果麦上没有自己,并且自己在说话,要把自己变成听众
|
||||
AudioEngineManager.get().setRole(Constants.CLIENT_ROLE_AUDIENCE);
|
||||
} else if (micPosition == Integer.MIN_VALUE &&
|
||||
uid != AuthModel.get().getCurrentUid()) {
|
||||
uid != AuthModel.get().getCurrentUid() &&
|
||||
!(AvRoomDataManager.get().isSingleRoom() && AvRoomDataManager.get().isOpenAnotherPKMode())) {
|
||||
// 如果麦上没有这个人,要把他静音
|
||||
AudioEngineManager.get().setRemoteMute(uid, true);
|
||||
}
|
||||
|
@@ -13,9 +13,12 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.yizhuan.xchat_android_constants.XChatConstants;
|
||||
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.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_library.common.application.Env;
|
||||
import com.yizhuan.xchat_android_library.common.file.FileHelper;
|
||||
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
||||
@@ -25,6 +28,8 @@ import java.util.Locale;
|
||||
|
||||
import io.agora.rtc2.Constants;
|
||||
import io.agora.rtc2.RtcEngine;
|
||||
import io.agora.rtc2.video.ChannelMediaInfo;
|
||||
import io.agora.rtc2.video.ChannelMediaRelayConfiguration;
|
||||
|
||||
|
||||
/**
|
||||
@@ -150,11 +155,27 @@ public class RtcEngineManager extends BaseEngine {
|
||||
|
||||
@Override
|
||||
public void connectOtherRoom(String roomId, long userUid) {
|
||||
RoomInfo curRoomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (curRoomInfo == null) {
|
||||
return;
|
||||
}
|
||||
ChannelMediaInfo srcChannelInfo = new ChannelMediaInfo(null, null, 0);
|
||||
ChannelMediaRelayConfiguration mediaRelayConfiguration = new ChannelMediaRelayConfiguration();
|
||||
mediaRelayConfiguration.setSrcChannelInfo(srcChannelInfo);
|
||||
|
||||
ChannelMediaInfo destChannelInfo = new ChannelMediaInfo(roomId, null, 0);
|
||||
mediaRelayConfiguration.setDestChannelInfo(roomId, destChannelInfo);
|
||||
|
||||
if (mRtcEngine != null) {
|
||||
mRtcEngine.startOrUpdateChannelMediaRelay(mediaRelayConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnectOtherRoom() {
|
||||
|
||||
if (mRtcEngine != null) {
|
||||
mRtcEngine.stopChannelMediaRelay();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user