add[声望升级-多人PK]

This commit is contained in:
Martin
2024-04-22 18:28:01 +08:00
parent 4147e3c5f5
commit 8228c45a4d
5 changed files with 467 additions and 726 deletions

View File

@@ -17,6 +17,9 @@ import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.faceunity.utils.FURenderer;
import java.util.ArrayList;
import java.util.List;
import io.agora.beautyapi.faceunity.BeautyPreset;
import io.agora.beautyapi.faceunity.CameraConfig;
import io.agora.beautyapi.faceunity.CaptureMode;
@@ -48,11 +51,10 @@ public class SWManager extends BaseCacheManager {
private int uid;
private VideoEncoderConfiguration cfg;
private FrameLayout anchorContainer; //主播视图
private FrameLayout pkContainer1; //pk主播视图1
private FrameLayout pkContainer2; //pk主播视图2
private FrameLayout pkContainer3; //pk主播视图3
private FrameLayout pkContainer; //pk主播视图1
private FrameLayout linkUserContainer;//连麦用户视图
private onRtcEngineListener onRtcEngineListener;
private List<String> drPkUserInfo = new ArrayList<>();
public void setOnRtcEngineListener(SWManager.onRtcEngineListener onRtcEngineListener) {
this.onRtcEngineListener = onRtcEngineListener;
@@ -193,16 +195,6 @@ public class SWManager extends BaseCacheManager {
}
}
/**
* 设置美颜
*/
public void setBeautPreset(){
if(mRtcEngine!=null){
}
}
/**
* 创建直播间
*/
@@ -228,6 +220,7 @@ public class SWManager extends BaseCacheManager {
mRtcEngine.setupLocalVideo(videoCanvas);
}
/**
* PK-加入对方主播直播间
* @param strUid
@@ -266,7 +259,86 @@ public class SWManager extends BaseCacheManager {
public void run() {
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
pkContainer1.addView(surfaceView);
pkContainer.addView(surfaceView);
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid));
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
}
});
}
@Override
public void onLeaveChannel(RtcStats stats) {
super.onLeaveChannel(stats);
}
@Override
public void onError(int err) {
super.onError(err);
L.eSw("onError:" + err);
}
});
}
/**
* 更新主播视图
* @param frameLayout
* @param channelName 對方直播間通道
* @param toUid 對方主播uid
*/
public void updateDrChannelView(FrameLayout frameLayout,String channelName,String toUid) {
mRtcEngine.setupLocalVideo(null);
RtcConnection rtcConnection = new RtcConnection();
rtcConnection.channelId = channelName; //對方主播的頻道
rtcConnection.localUid = Integer.parseInt(CommonAppConfig.getInstance().getUid());//自己的ID
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
frameLayout.addView(surfaceView);
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid));
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
}
/**
* PK-加入对方主播直播间
* @param strUid
* @param token
* @param toUid
* @param channelName
*/
public void joinChannelDrEx(FrameLayout frameLayout,String strUid, String token, String toUid, String channelName) {
int tempUid;
if (StringUtil.isEmpty(strUid)) {
tempUid = 0;
} else {
tempUid = Integer.parseInt(strUid);
}
// 创建 ChannelMediaOptions 对象,并进行配置
ChannelMediaOptions options = new ChannelMediaOptions();
// 根据场景将用户角色设置为 AUDIENCE (观众)
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
options.autoSubscribeVideo = true;
options.autoSubscribeAudio = true;
options.publishMicrophoneTrack = false;
options.publishCameraTrack = false;
RtcConnection rtcConnection = new RtcConnection();
rtcConnection.channelId = channelName; //對方主播的頻道
rtcConnection.localUid = tempUid;//自己的ID
L.eSw("strUid:" + tempUid + "_token:" + token + "_channelName:" + channelName);
mRtcEngine.joinChannelEx(token, rtcConnection, options, new IRtcEngineEventHandler() {
@Override
public void onJoinChannelSuccess(String channel, int scUid, int elapsed) {
super.onJoinChannelSuccess(channel, scUid, elapsed);
L.eSw("onJoinChannelSuccess:" + channel + " uid " + scUid + " elapsed: " + elapsed);
mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
frameLayout.addView(surfaceView);
VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid));
mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection);
}
@@ -307,15 +379,6 @@ public class SWManager extends BaseCacheManager {
}
}
//设置对方主播视图
private void setupRemoteVideo(int uid) {
SurfaceView surfaceView = new SurfaceView(mContext);
surfaceView.setZOrderMediaOverlay(true);
pkContainer1.addView(surfaceView);
// 将 SurfaceView 对象传入声网实时互动 SDK设置远端视图
mRtcEngine.setupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT, uid));
}
public void setAnchorContainer(FrameLayout anchorContainer) {
this.anchorContainer = anchorContainer;
}
@@ -397,16 +460,8 @@ public class SWManager extends BaseCacheManager {
void onOpenSuccess(String channel, int uid);
}
public void setPkContainer1(FrameLayout pkContainer1) {
this.pkContainer1 = pkContainer1;
}
public void setPkContainer2(FrameLayout pkContainer2) {
this.pkContainer2 = pkContainer2;
}
public void setPkContainer3(FrameLayout pkContainer3) {
this.pkContainer3 = pkContainer3;
public void setPkContainer(FrameLayout pkContainer) {
this.pkContainer = pkContainer;
}
public void setLinkUserContainer(FrameLayout linkUserContainer) {