add[声望升级-小游戏多人连麦]
This commit is contained in:
@@ -53,6 +53,20 @@ public class SWAuManager extends BaseCacheManager {
|
||||
return manager;
|
||||
}
|
||||
|
||||
IRtcEngineEventHandler mEventHandler = new IRtcEngineEventHandler() {
|
||||
@Override
|
||||
public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
|
||||
super.onJoinChannelSuccess(channel, uid, elapsed);
|
||||
L.eSw("加入房间成功 channel"+channel+" uid"+uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserJoined(int uid, int elapsed) {
|
||||
super.onUserJoined(uid, elapsed);
|
||||
L.eSw("用户加入房间成功"+uid);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 初始化声网SDK
|
||||
*/
|
||||
@@ -76,11 +90,52 @@ public class SWAuManager extends BaseCacheManager {
|
||||
//mRtcEngine.startPreview();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化声网SDK-语音房
|
||||
*/
|
||||
public void initRtcEngineAudio(Activity mContext) {
|
||||
this.mContext = mContext;
|
||||
try {
|
||||
// 创建 RtcEngineConfig 对象,并进行配置
|
||||
RtcEngineConfig config = new RtcEngineConfig();
|
||||
config.mContext = mContext;
|
||||
config.mAppId = SWAuManager.shengwang_appId;
|
||||
config.mEventHandler = mEventHandler;
|
||||
// 创建并初始化 RtcEngine
|
||||
mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config);
|
||||
mRtcEngine.enableAudio();
|
||||
mRtcEngine.enableLocalAudio(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Check the error.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建语音房
|
||||
* @param token
|
||||
* @param channelName
|
||||
* @param uid
|
||||
*/
|
||||
public void joinAudioRoom(String channelName,String token,int uid){
|
||||
L.eSw("加入房间"+channelName+" uid"+uid);
|
||||
// 创建 ChannelMediaOptions 对象,并进行配置
|
||||
ChannelMediaOptions options = new ChannelMediaOptions();
|
||||
// 根据场景将用户角色设置为 AUDIENCE (观众)
|
||||
options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE;
|
||||
// 直播场景下,设置频道场景为 BROADCASTING (直播场景)
|
||||
options.audienceLatencyLevel = Constants.CHANNEL_PROFILE_LIVE_BROADCASTING; // 觀眾走極速直播
|
||||
options.autoSubscribeVideo = false;
|
||||
options.autoSubscribeAudio = true;
|
||||
mRtcEngine.joinChannel(token, channelName, uid, options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新主播视图
|
||||
*
|
||||
* @param frameLayout
|
||||
*/
|
||||
public void updateMyChannelView(FrameLayout frameLayout,int uid) {
|
||||
public void updateMyChannelView(FrameLayout frameLayout, int uid) {
|
||||
mRtcEngine.setupLocalVideo(null);
|
||||
SurfaceView surfaceView = new SurfaceView(mContext);
|
||||
surfaceView.setZOrderMediaOverlay(true);
|
||||
@@ -114,7 +169,6 @@ public class SWAuManager extends BaseCacheManager {
|
||||
mRtcEngine.joinChannel(token, channelName, uid, options);
|
||||
}
|
||||
|
||||
|
||||
public void joinExRoomEx(int strUid, String token, String channelName) {
|
||||
// 创建 ChannelMediaOptions 对象,并进行配置
|
||||
ChannelMediaOptions options = new ChannelMediaOptions();
|
||||
@@ -136,7 +190,7 @@ public class SWAuManager extends BaseCacheManager {
|
||||
mContext.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
L.eSw("onJoinChannelSuccess:" + channel + " uid " +uid+ " elapsed: " + elapsed);
|
||||
L.eSw("onJoinChannelSuccess:" + channel + " uid " + uid + " elapsed: " + elapsed);
|
||||
SurfaceView surfaceView = new SurfaceView(mContext);
|
||||
surfaceView.setZOrderMediaOverlay(true);
|
||||
pkContainer1.addView(surfaceView);
|
||||
@@ -156,32 +210,38 @@ public class SWAuManager extends BaseCacheManager {
|
||||
|
||||
/**
|
||||
* 与主播连麦
|
||||
*
|
||||
* @param isUp true 上麦 false 下麦
|
||||
*/
|
||||
public void setMicAn(boolean isUp) {
|
||||
L.eSw("setMicAn-isUp:"+isUp);
|
||||
ChannelMediaOptions options = new ChannelMediaOptions();
|
||||
if(isUp){
|
||||
L.eSw("setMicAn-isUp:" + isUp);
|
||||
ChannelMediaOptions options = new ChannelMediaOptions();
|
||||
if (isUp) {
|
||||
options.publishCameraTrack = false; //控制是否发视频
|
||||
options.publishMicrophoneTrack = true; //控制是否发音频
|
||||
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; //设置身份为主播
|
||||
}else{
|
||||
} else {
|
||||
options.publishCameraTrack = false; //控制是否发视频
|
||||
options.publishMicrophoneTrack = false; //控制是否发音频
|
||||
options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; //设置身份为观众
|
||||
options.audienceLatencyLevel=Constants.AUDIENCE_LATENCY_LEVEL_LOW_LATENCY ;//设置为极速直播观众
|
||||
options.audienceLatencyLevel = Constants.AUDIENCE_LATENCY_LEVEL_LOW_LATENCY;//设置为极速直播观众
|
||||
}
|
||||
mRtcEngine.updateChannelMediaOptions(options);
|
||||
}
|
||||
|
||||
public void setMicAudio(int toUid,boolean isEn) {
|
||||
L.eSw("setMicAudio:toUid" +toUid+"isEn "+ isEn);
|
||||
mRtcEngine.muteRemoteAudioStream(toUid,isEn);
|
||||
}
|
||||
/**
|
||||
* PK-加入对方主播直播间
|
||||
*
|
||||
* @param strUid
|
||||
* @param token
|
||||
* @param toUid
|
||||
* @param channelName
|
||||
*/
|
||||
public void joinChannelDrEx(FrameLayout frameLayout,String strUid, String token, String toUid, String channelName) {
|
||||
public void joinChannelDrEx(FrameLayout frameLayout, String strUid, String token, String toUid, String channelName) {
|
||||
int tempUid;
|
||||
if (StringUtil.isEmpty(strUid)) {
|
||||
tempUid = 0;
|
||||
@@ -213,7 +273,7 @@ public class SWAuManager extends BaseCacheManager {
|
||||
SurfaceView surfaceView = new SurfaceView(mContext);
|
||||
surfaceView.setZOrderMediaOverlay(true);
|
||||
frameLayout.addView(surfaceView);
|
||||
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN,Integer.parseInt(toUid));
|
||||
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, Integer.parseInt(toUid));
|
||||
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
|
||||
}
|
||||
});
|
||||
@@ -234,10 +294,11 @@ public class SWAuManager extends BaseCacheManager {
|
||||
|
||||
/**
|
||||
* 退出对方直播间
|
||||
* @param uid 自己的ID
|
||||
*
|
||||
* @param uid 自己的ID
|
||||
* @param liveUid 对方直播间号
|
||||
*/
|
||||
public void exitChannelToUid(int uid, String liveUid){
|
||||
public void exitChannelToUid(int uid, String liveUid) {
|
||||
RtcConnection rtcConnection = new RtcConnection();
|
||||
rtcConnection.channelId = getChannelName(liveUid); //對方主播的頻道
|
||||
rtcConnection.localUid = uid;//自己的ID
|
||||
@@ -247,14 +308,14 @@ public class SWAuManager extends BaseCacheManager {
|
||||
/**
|
||||
* 退出所有的直播间
|
||||
*/
|
||||
public void exitChannelAll(){
|
||||
public void exitChannelAll() {
|
||||
mRtcEngine.leaveChannel();
|
||||
}
|
||||
|
||||
public static String getChannelName(String liveUid) {
|
||||
if(liveUid.contains("g")){
|
||||
if (liveUid.contains("g")) {
|
||||
return liveUid;
|
||||
}else{
|
||||
} else {
|
||||
return CommonAppConfig.SWChannelPrefix + liveUid;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user