From 5922f4c08b2c82f7133450912bbf014fb921077c Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Wed, 10 Apr 2024 18:31:00 +0800 Subject: [PATCH 01/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/proguard-rules.pro | 2 + app/src/main/AndroidManifest.xml | 5 + common/build.gradle | 3 +- .../com/yunbao/common/CommonAppConfig.java | 1 - .../yunbao/common/manager/SWAuManager.java | 147 ++ .../com/yunbao/common/manager/SWManager.java | 207 +++ live/src/main/AndroidManifest.xml | 4 + .../yunbao/live/activity/NewLiveActivity.java | 139 ++ .../live/views/LiveNewReadyRyViewHolder.java | 8 +- .../live/views/LivePlayRyViewHolder.java | 13 + .../live/views/LivePlaySwViewHolder.java | 1374 +++++++++++++++++ .../live/views/LivePushRyViewHolder.java | 47 +- .../src/main/res/layout/acticity_new_live.xml | 37 + .../main/res/layout/view_live_play_ksy.xml | 6 + .../yunbao/main/activity/LoginActivity.java | 5 +- 15 files changed, 1975 insertions(+), 23 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/manager/SWAuManager.java create mode 100644 common/src/main/java/com/yunbao/common/manager/SWManager.java create mode 100644 live/src/main/java/com/yunbao/live/activity/NewLiveActivity.java create mode 100644 live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java create mode 100644 live/src/main/res/layout/acticity_new_live.xml diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 6f4c447c6..1a522d0c3 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -292,3 +292,5 @@ rx.internal.util.atomic.LinkedQueueNode* consumerNode; -keep class com.shayu.lib_google.**{*;} -keep class com.shayu.lib_huawei.**{*;} + +-keep class io.agora.**{*;} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ded4c2c0f..8d8a3325c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -89,6 +89,11 @@ + + + + + diff --git a/common/build.gradle b/common/build.gradle index d59049c32..b69c7b668 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -225,6 +225,7 @@ dependencies { api 'com.github.FlyJingFish:GradientTextView:1.2.4' //轮播 一屏显示多个 api 'com.github.xiaohaibin:XBanner:androidx_v1.2.6' - + //声网SDK + api 'io.agora.rtc:agora-special-full:4.1.1.28' } diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index 6b1a7119d..2f447a77e 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -77,7 +77,6 @@ public class CommonAppConfig { public static int alert_time = 1; public static int alert_end_time = 1; - private CommonAppConfig() { } diff --git a/common/src/main/java/com/yunbao/common/manager/SWAuManager.java b/common/src/main/java/com/yunbao/common/manager/SWAuManager.java new file mode 100644 index 000000000..7a3b9741e --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/SWAuManager.java @@ -0,0 +1,147 @@ +package com.yunbao.common.manager; + +import android.app.Activity; +import android.content.Context; +import android.view.SurfaceView; +import android.widget.FrameLayout; + +import com.yunbao.common.CommonAppContext; +import com.yunbao.common.manager.base.BaseCacheManager; +import com.yunbao.common.utils.StringUtil; + +import io.agora.rtc2.ChannelMediaOptions; +import io.agora.rtc2.Constants; +import io.agora.rtc2.IRtcEngineEventHandler; +import io.agora.rtc2.RtcEngine; +import io.agora.rtc2.RtcEngineConfig; +import io.agora.rtc2.video.VideoCanvas; + +/** + * 声网主播管理类 + */ +public class SWAuManager extends BaseCacheManager { + + // 填写项目的 App ID,可在声网控制台中生成 + public static final String shengwang_appId = "4cf0376582d742ac8a96778b25b1079e"; + // 填写频道名 + public static final String shengwang_channelName = "12"; + // 填写声网控制台中生成的临时 Token + public static final String shengwang_token = "007eJxSYJi477Xju22xV7ov7GfzzOnbtCU0IuK9+YuwWf2uLPGnl8xRYDBJTjMwNjcztTBKMTcxSky2SLQ0Mze3SDIyTTI0MLdMPWQrltYQyMjw/4kCCyMDBIL4TAyGRiwMlpaWloAAAAD//w/TIFY="; + private Activity mContext; + public static SWAuManager manager; + private RtcEngine mRtcEngine; + private FrameLayout audienceContainer; //主播视图 + private FrameLayout pkContainer1; //pk主播视图1 + private FrameLayout pkContainer2; //pk主播视图2 + private FrameLayout pkContainer3; //pk主播视图3 + private FrameLayout linkUserContainer;//连麦用户视图 + + public SWAuManager(Context context) { + super(context); + } + + /** + * 获取单列 + * + * @return + */ + public static SWAuManager get() { + if (null == manager) { + manager = new SWAuManager(CommonAppContext.sInstance.getBaseContext()); + } + return manager; + } + + /** + * 初始化声网SDK + */ + public void initRtcEngine(Activity mContext) { + this.mContext = mContext; + try { + // 创建 RtcEngineConfig 对象,并进行配置 + RtcEngineConfig config = new RtcEngineConfig(); + config.mContext = mContext; + config.mAppId = SWAuManager.shengwang_appId; + config.mEventHandler = mRtcEventHandler; + // 创建并初始化 RtcEngine + mRtcEngine = RtcEngine.create(config); + } catch (Exception e) { + throw new RuntimeException("Check the error."); + } + mRtcEngine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING); // 直播模式,引擎級別 + // 启用视频模块 + mRtcEngine.enableVideo(); + // 开启本地预览 + //mRtcEngine.startPreview(); + } + + /** + * guanzhong + * 加入房间 + */ + public void joinRoom(String strUid, String token, String channelName) { + int uid; + if (StringUtil.isEmpty(strUid)) { + uid = 0; + } else { + uid = Integer.parseInt(strUid); + } + // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 + SurfaceView surfaceView = new SurfaceView(mContext); + audienceContainer.addView(surfaceView); + + // 创建 ChannelMediaOptions 对象,并进行配置 + ChannelMediaOptions options = new ChannelMediaOptions(); + // 根据场景将用户角色设置为 AUDIENCE (观众) + options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; + // 直播场景下,设置频道场景为 BROADCASTING (直播场景) + options.audienceLatencyLevel = Constants.AUDIENCE_LATENCY_LEVEL_LOW_LATENCY; // 觀眾走極速直播 + + // 使用临时 Token 加入频道,自行指定用户 ID 并确保其在频道内的唯一性 + mRtcEngine.joinChannel(token, channelName, uid, options); + } + + //远程监听 + private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { + @Override + // 监听频道内的远端用户,获取用户的 uid 信息 + public void onUserJoined(int uid, int elapsed) { + mContext.runOnUiThread(new Runnable() { + @Override + public void run() { + // 获取 uid 后,设置远端视频视图 + setupRemoteVideo(uid); + } + }); + } + }; + + //设置对方主播视图 + public void setupRemoteVideo(int uid) { + SurfaceView surfaceView = new SurfaceView(mContext); + surfaceView.setZOrderMediaOverlay(true); + audienceContainer.addView(surfaceView); + // 将 SurfaceView 对象传入声网实时互动 SDK,设置远端视图 + mRtcEngine.setupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); + } + + public void setAudienceContainer(FrameLayout audienceContainer) { + this.audienceContainer = audienceContainer; + } + + 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 setLinkUserContainer(FrameLayout linkUserContainer) { + this.linkUserContainer = linkUserContainer; + } +} diff --git a/common/src/main/java/com/yunbao/common/manager/SWManager.java b/common/src/main/java/com/yunbao/common/manager/SWManager.java new file mode 100644 index 000000000..a97d85b9b --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/SWManager.java @@ -0,0 +1,207 @@ +package com.yunbao.common.manager; + +import android.app.Activity; +import android.content.Context; +import android.view.SurfaceView; +import android.widget.FrameLayout; + +import com.yunbao.common.CommonAppContext; +import com.yunbao.common.manager.base.BaseCacheManager; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; + +import cn.rongcloud.rtc.base.RCRTCParamsType; +import io.agora.rtc2.ChannelMediaOptions; +import io.agora.rtc2.Constants; +import io.agora.rtc2.IRtcEngineEventHandler; +import io.agora.rtc2.RtcEngine; +import io.agora.rtc2.RtcEngineConfig; +import io.agora.rtc2.video.VideoCanvas; +import io.agora.rtc2.video.VideoEncoderConfiguration; + +/** + * 声网主播管理类 + */ +public class SWManager extends BaseCacheManager { + + // 填写项目的 App ID,可在声网控制台中生成 + public static final String shengwang_appId = "4cf0376582d742ac8a96778b25b1079e"; + // 填写频道名 + public static final String shengwang_channelName = "12"; + // 填写声网控制台中生成的临时 Token + public static final String shengwang_token = "007eJxTYOD6Iv3buTHm6666BKY1Cr7mUZU3tY0eHH5qbF4jv5nNukqBwSQ5zcDY3MzUwijF3MQoMdki0dLM3Nwiycg0ydDA3DL1xX/RtIZARgb+3ExWRgYIBPGZGAyNGBgAhDMb8Q=="; + private Activity mContext; + public static SWManager manager; + private RtcEngine mRtcEngine; + private int uid; + VideoEncoderConfiguration cfg; + private FrameLayout anchorContainer; //主播视图 + private FrameLayout pkContainer1; //pk主播视图1 + private FrameLayout pkContainer2; //pk主播视图2 + private FrameLayout pkContainer3; //pk主播视图3 + private FrameLayout linkUserContainer;//连麦用户视图 + private onRtcEngineListener onRtcEngineListener; + + public void setOnRtcEngineListener(SWManager.onRtcEngineListener onRtcEngineListener) { + this.onRtcEngineListener = onRtcEngineListener; + } + + public SWManager(Context context) { + super(context); + } + + /** + * 获取单列 + * + * @return + */ + public static SWManager get() { + if (null == manager) { + manager = new SWManager(CommonAppContext.sInstance.getBaseContext()); + } + return manager; + } + + /** + * 初始化声网SDK + */ + public void initRtcEngine(Activity mContext, String strUid) { + this.mContext = mContext; + if (StringUtil.isEmpty(strUid)) { + uid = 0; + } else { + uid = Integer.parseInt(strUid); + } + try { + // 创建 RtcEngineConfig 对象,并进行配置 + RtcEngineConfig config = new RtcEngineConfig(); + config.mContext = mContext; + config.mAppId = SWManager.shengwang_appId; + config.mEventHandler = mRtcEventHandler; + // 创建并初始化 RtcEngine + mRtcEngine = RtcEngine.create(config); + } catch (Exception e) { + throw new RuntimeException("Check the error."); + } + mRtcEngine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING); + // 启用视频模块 + mRtcEngine.enableVideo(); + // 开启本地预览 + mRtcEngine.startPreview(); + + cfg = new VideoEncoderConfiguration(); + //设置默认分辨率 + switch (IMLoginManager.get(mContext).getSelectClarity()) { + case 0: + cfg.dimensions = VideoEncoderConfiguration.VD_840x480; + break; + case 1: + cfg.dimensions = VideoEncoderConfiguration.VD_1280x720; + break; + case 2: + cfg.dimensions = VideoEncoderConfiguration.VD_1920x1080; + break; + } + cfg.frameRate = 24; + cfg.bitrate = 0; + cfg.mirrorMode = VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_ENABLED; //镜像 + mRtcEngine.setVideoEncoderConfiguration(cfg); + + // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 + SurfaceView surfaceView = new SurfaceView(mContext); + anchorContainer.addView(surfaceView); + // 设置视图 + mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); + } + + public void setDimensions(int selectClarity) { + if (cfg != null && mRtcEngine != null) { + switch (selectClarity) { + case 0: + cfg.dimensions = VideoEncoderConfiguration.VD_840x480; + break; + case 1: + cfg.dimensions = VideoEncoderConfiguration.VD_1280x720; + break; + case 2: + cfg.dimensions = VideoEncoderConfiguration.VD_1920x1080; + break; + } + mRtcEngine.setVideoEncoderConfiguration(cfg); + } + } + + + /** + * 创建房间 + */ + public void createRoom(String token, String channelName) { + ChannelMediaOptions options = new ChannelMediaOptions(); + // 设置角色 BROADCASTER (主播) 或 AUDIENCE (观众) + options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; + // 加入频道 + mRtcEngine.joinChannel(token, channelName, uid, options); + } + + //远程监听 + private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { + @Override + // 监听频道内的远端用户,获取用户的 uid 信息 + public void onUserJoined(int uid, int elapsed) { + mContext.runOnUiThread(new Runnable() { + @Override + public void run() { + // 获取 uid 后,设置远端视频视图 + setupRemoteVideo(uid); + } + }); + } + + @Override + public void onJoinChannelSuccess(String channel, int uid, int elapsed) { + super.onJoinChannelSuccess(channel, uid, elapsed); + if (onRtcEngineListener != null) { + onRtcEngineListener.onOpenSuccess(channel, uid); + } + } + + @Override + public void onError(int err) { + super.onError(err); + ToastUtil.show("onError:" + err); + } + }; + + //设置对方主播视图 + 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; + } + + public interface onRtcEngineListener { + 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 setLinkUserContainer(FrameLayout linkUserContainer) { + this.linkUserContainer = linkUserContainer; + } +} diff --git a/live/src/main/AndroidManifest.xml b/live/src/main/AndroidManifest.xml index 1af89a691..6c664cb33 100644 --- a/live/src/main/AndroidManifest.xml +++ b/live/src/main/AndroidManifest.xml @@ -124,6 +124,10 @@ + + \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/activity/NewLiveActivity.java b/live/src/main/java/com/yunbao/live/activity/NewLiveActivity.java new file mode 100644 index 000000000..6dfb2bbf5 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/activity/NewLiveActivity.java @@ -0,0 +1,139 @@ +package com.yunbao.live.activity; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; + +import android.Manifest; +import android.content.pm.PackageManager; +import android.view.SurfaceView; +import android.widget.FrameLayout; + +import android.os.Bundle; + +import com.yunbao.common.manager.SWManager; +import com.yunbao.live.R; + +import io.agora.rtc2.ChannelMediaOptions; +import io.agora.rtc2.Constants; +import io.agora.rtc2.IRtcEngineEventHandler; +import io.agora.rtc2.RtcEngine; +import io.agora.rtc2.RtcEngineConfig; +import io.agora.rtc2.video.VideoCanvas; + + +public class NewLiveActivity extends AppCompatActivity { + private RtcEngine mRtcEngine; + + private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { + @Override + // 监听频道内的远端用户,获取用户的 uid 信息 + public void onUserJoined(int uid, int elapsed) { + runOnUiThread(new Runnable() { + @Override + public void run() { + // 获取 uid 后,设置远端视频视图 + setupRemoteVideo(uid); + } + }); + } + }; + + private void initializeAndJoinChannel() { + try { + // 创建 RtcEngineConfig 对象,并进行配置 + RtcEngineConfig config = new RtcEngineConfig(); + config.mContext = getBaseContext(); + config.mAppId = SWManager.shengwang_appId; + config.mEventHandler = mRtcEventHandler; + // 创建并初始化 RtcEngine + mRtcEngine = RtcEngine.create(config); + } catch (Exception e) { + throw new RuntimeException("Check the error."); + } + // 启用视频模块 + mRtcEngine.enableVideo(); + // 开启本地预览 + mRtcEngine.startPreview(); + + // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 + FrameLayout container = findViewById(R.id.local_video_view_container); + SurfaceView surfaceView = new SurfaceView(getBaseContext()); + container.addView(surfaceView); + // 将 SurfaceView 对象传入声网实时互动 SDK,设置本地视图 + mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT, 0)); + + // 创建 ChannelMediaOptions 对象,并进行配置 + ChannelMediaOptions options = new ChannelMediaOptions(); + // 根据场景将用户角色设置为 BROADCASTER (主播) 或 AUDIENCE (观众) + options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; + // 直播场景下,设置频道场景为 BROADCASTING (直播场景) + options.channelProfile = Constants.CHANNEL_PROFILE_LIVE_BROADCASTING; + + // 使用临时 Token 加入频道,自行指定用户 ID 并确保其在频道内的唯一性 + mRtcEngine.joinChannel(SWManager.shengwang_token, SWManager.shengwang_channelName, 0, options); + } + + private void setupRemoteVideo(int uid) { + FrameLayout container = findViewById(R.id.remote_video_view_container); + SurfaceView surfaceView = new SurfaceView(getBaseContext()); + surfaceView.setZOrderMediaOverlay(true); + container.addView(surfaceView); + // 将 SurfaceView 对象传入声网实时互动 SDK,设置远端视图 + mRtcEngine.setupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT, uid)); + } + + private static final int PERMISSION_REQ_ID = 22; + + // 获取体验实时音视频互动所需的录音、摄像头等权限 + private String[] getRequiredPermissions() { + // 判断 targetSDKVersion 31 及以上时所需的权限 + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { + return new String[]{ + Manifest.permission.RECORD_AUDIO, // 录音权限 + Manifest.permission.CAMERA, // 摄像头权限 + Manifest.permission.READ_PHONE_STATE, // 读取电话状态权限 + Manifest.permission.BLUETOOTH_CONNECT // 蓝牙连接权限 + }; + } else { + return new String[]{ + Manifest.permission.RECORD_AUDIO, + Manifest.permission.CAMERA + }; + } + } + + private boolean checkPermissions() { + for (String permission : getRequiredPermissions()) { + int permissionCheck = ContextCompat.checkSelfPermission(this, permission); + if (permissionCheck != PackageManager.PERMISSION_GRANTED) { + return false; + } + } + return true; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.acticity_new_live); + // 如果已经授权,则初始化 RtcEngine 并加入频道 + initializeAndJoinChannel(); + if (checkPermissions()) { + initializeAndJoinChannel(); + } else { + ActivityCompat.requestPermissions(this, getRequiredPermissions(), PERMISSION_REQ_ID); + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + // 停止本地视频预览 + mRtcEngine.stopPreview(); + + // 离开频道 + mRtcEngine.leaveChannel(); + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java index c40b07bf1..5863c3b91 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java @@ -44,6 +44,7 @@ import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.interfaces.ImageResultCallback; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.manager.SWManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.L; @@ -327,7 +328,10 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl if (liveOpenCustomPopup != null) { liveOpenCustomPopup.setSelectClarity(selectClarity); } - //設置開播分辨率 + SWManager.get().setDimensions(selectClarity); + + + /*//設置開播分辨率 RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; int minRate = 200; int maxRate = 900; @@ -355,7 +359,7 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_15) .setVideoResolution(rcrtcVideoResolution) .build(); - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); + RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config);*/ Log.e("切换分辨率", "时间戳" + System.currentTimeMillis()); //重新发布一下流 Bus.get().post(new LivePushRyEvent()); diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 126ec891c..5c4b48ab3 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -3,6 +3,7 @@ package com.yunbao.live.views; import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; import android.Manifest; +import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.graphics.Color; @@ -36,6 +37,7 @@ import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.manager.SWAuManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; @@ -97,6 +99,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private RelativeLayout mPkContainer; public StyledPlayerView mVideoView; + private FrameLayout playFrameLayout; + private View mLoading, mLoading2; private ImageView mCover; private boolean mPaused;//是否切后台了 @@ -122,6 +126,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { //0未申请1申请中2连麦中 RCRTCRoom rcrtcRoom; String purl, srcUrl; + SWAuManager swAuManager; public int getLandscape() { return landscape; @@ -146,6 +151,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { EventBus.getDefault().register(this); Bus.getOn(this); mRoot = (ViewGroup) findViewById(R.id.root); + playFrameLayout = (FrameLayout) findViewById(R.id.playView); mSmallContainer = (ViewGroup) findViewById(R.id.small_container); mLeftContainer = (ViewGroup) findViewById(R.id.left_container); mRightContainer = (ViewGroup) findViewById(R.id.right_container); @@ -167,6 +173,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mPlayer = new LiveExoPlayerManager(mContext); mPlayer.setMainView(mVideoView); mPlayer.setListener(new ExoPlayerListener()); + + swAuManager = SWAuManager.get(); + swAuManager.setAudienceContainer(playFrameLayout); + swAuManager.initRtcEngine((Activity) mContext); + swAuManager.setupRemoteVideo(11); + swAuManager.joinRoom("9999", SWAuManager.shengwang_token, SWAuManager.shengwang_channelName); + debugView = new TextView(mContext); debugView.setBackgroundColor(Color.WHITE); diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java new file mode 100644 index 000000000..f421d920f --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -0,0 +1,1374 @@ +package com.yunbao.live.views; + +import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; + +import android.Manifest; +import android.app.Dialog; +import android.content.Context; +import android.graphics.Color; +import android.media.AudioManager; +import android.os.Build; +import android.os.Handler; +import android.os.Looper; +import android.text.TextUtils; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.google.android.exoplayer2.PlaybackException; +import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.ui.StyledPlayerView; +import com.google.android.exoplayer2.video.VideoSize; +import com.lxj.xpopup.XPopup; +import com.lxj.xpopup.core.BasePopupView; +import com.lxj.xpopup.interfaces.XPopupCallback; +import com.lzf.easyfloat.EasyFloat; +import com.lzy.okserver.OkDownload; +import com.yunbao.common.bean.EnterRoomNewModel; +import com.yunbao.common.dialog.LiveFontSizeSettingDialog; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.MicStatusManager; +import com.yunbao.common.utils.ScreenDimenUtil; +import com.yunbao.common.utils.SpUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.views.LiveClarityCustomPopup; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveActivity; +import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.utils.LiveExoPlayerManager; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +import cn.rongcloud.rtc.api.RCRTCEngine; +import cn.rongcloud.rtc.api.RCRTCRemoteUser; +import cn.rongcloud.rtc.api.RCRTCRoom; +import cn.rongcloud.rtc.api.RCRTCRoomConfig; +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; +import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleDataCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCVideoInputFrameListener; +import cn.rongcloud.rtc.api.stream.RCRTCInputStream; +import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; +import cn.rongcloud.rtc.api.stream.RCRTCOutputStream; +import cn.rongcloud.rtc.api.stream.RCRTCVideoInputStream; +import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; +import cn.rongcloud.rtc.api.stream.RCRTCVideoView; +import cn.rongcloud.rtc.base.RCRTCLiveRole; +import cn.rongcloud.rtc.base.RCRTCMediaType; +import cn.rongcloud.rtc.base.RCRTCParamsType; +import cn.rongcloud.rtc.base.RCRTCRemoteVideoFrame; +import cn.rongcloud.rtc.base.RCRTCRoomType; +import cn.rongcloud.rtc.base.RCRTCStreamType; +import cn.rongcloud.rtc.base.RTCErrorCode; +import cn.rongcloud.rtc.core.RendererCommon; + +public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { + + private static final String TAG = "LivePlayViewHolder"; + private ViewGroup mRoot; + private ViewGroup mSmallContainer; + private ViewGroup mLeftContainer; + private ViewGroup mRightContainer; + private RelativeLayout mPkContainer; + public StyledPlayerView mVideoView; + + private View mLoading, mLoading2; + private ImageView mCover; + private boolean mPaused;//是否切后台了 + private boolean mStarted;//是否开始了播放 + private boolean mEnd;//是否结束了播放 + public static ImageView leave; + + private boolean mPausedPlay;//是否被动暂停了播放 + public int landscape; //1h 2s + public Context contexts; + public FrameLayout ry_view; + + private static final int VIDEO_VERTICAL = 2; + private static final int VIDEO_HORIZONTAL = 1; + int videoLandscape = -1; // 视频方向,2=竖屏,1=横屏 + + static int vHeight;//视频高 + private TextView debugView; + private LiveExoPlayerManager mPlayer; + private boolean isPk = false; + private boolean userJoinLinkMic = false;//用户是否已加入房间 + + //0未申请1申请中2连麦中 + RCRTCRoom rcrtcRoom; + String purl, srcUrl; + + public int getLandscape() { + return landscape; + } + + public LivePlaySwViewHolder(Context context, ViewGroup parentView, int landscapes) { + super(context, parentView); + contexts = context; + landscape = landscapes; + Log.i("收收收", landscape + ""); + } + + + @Override + protected int getLayoutId() { + return R.layout.view_live_play_ksy; + } + + @Override + public void init() { + Log.i(TAG, "init: 初始化播放器ViewHolder"); + EventBus.getDefault().register(this); + Bus.getOn(this); + mRoot = (ViewGroup) findViewById(R.id.root); + mSmallContainer = (ViewGroup) findViewById(R.id.small_container); + mLeftContainer = (ViewGroup) findViewById(R.id.left_container); + mRightContainer = (ViewGroup) findViewById(R.id.right_container); + mPkContainer = (RelativeLayout) findViewById(R.id.pk_container); + mVideoView = (StyledPlayerView) findViewById(R.id.video_view); + ry_view = (FrameLayout) findViewById(R.id.ry_view); + leave = (ImageView) findViewById(R.id.leave); + mLoading = findViewById(R.id.loading); + mLoading2 = findViewById(R.id.loading2); + mCover = (ImageView) findViewById(R.id.cover); + ScreenDimenUtil util = ScreenDimenUtil.getInstance(); + int mScreenWdith = util.getScreenWdith(); + vHeight = mScreenWdith * 720 / 960; + + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mPkContainer.getLayoutParams(); + params.height = vHeight; + mPkContainer.requestLayout(); + + mPlayer = new LiveExoPlayerManager(mContext); + mPlayer.setMainView(mVideoView); + mPlayer.setListener(new ExoPlayerListener()); + debugView = new TextView(mContext); + debugView.setBackgroundColor(Color.WHITE); + + } + + @Override + public void hideCover() { +// if (mCover != null) { +// if (mCover.getVisibility()==View.VISIBLE){ +//// new Handler().postDelayed(new Runnable() { +//// @Override +//// public void run() { +//// +//// } +//// },200); +// mCover.setVisibility(View.GONE); +// mLoading2.setVisibility(View.GONE); +// } +// +// +// } + } + + @Override + public void setCover(String coverUrl) { +// if (mCover != null) { +// mCover.setVisibility(View.VISIBLE); +// mLoading2.setVisibility(View.VISIBLE); +// ImgLoader.displayBlurLive(mContext, coverUrl, mCover, 400, 600); +// +// } + }// + + @Override + public synchronized void setLiveBeanLandscape(int landscape) { +// landscape=1; + Log.i(TAG, "setLiveBeanLandscape: " + landscape + " isPk: " + isPk); + this.landscape = landscape; + this.videoLandscape = landscape; + if (mPlayer != null) { + mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); + } + + if (landscape == 2) { + Log.i(TAG, "还原9:16"); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = RelativeLayout.LayoutParams.MATCH_PARENT; + params.topMargin = 0; + mVideoView.setLayoutParams(params); + mVideoView.requestLayout(); + + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = RelativeLayout.LayoutParams.MATCH_PARENT; + params1.topMargin = 0; + ry_view.setLayoutParams(params1); + ry_view.requestLayout(); + RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params2.height = RelativeLayout.LayoutParams.MATCH_PARENT; + params2.topMargin = 0; + mCover.setLayoutParams(params2); + mCover.requestLayout(); + + } else { + Log.i(TAG, "还原16:9"); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.setLayoutParams(params); + mVideoView.requestLayout(); + + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = vHeight; + params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params1.addRule(RelativeLayout.ALIGN_TOP); + ry_view.setLayoutParams(params1); + ry_view.requestLayout(); + RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params2.height = DpUtil.dp2px(270); + params2.topMargin = DpUtil.dp2px(120); + mCover.setLayoutParams(params2); + mCover.requestLayout(); + } + } + + @Override + public void setLiveEnterRoomNewModel(EnterRoomNewModel data) { + super.setLiveEnterRoomNewModel(data); + isPk = data.getEnterRoomInfo().getIsconnection().equals("1"); + if (isPk) { + setLiveBeanLandscape(1); + } + } + + /** + * 暂停播放 + */ + @Override + public void pausePlay() { + + } + + /** + * 暂停播放后恢复 + */ + @Override + public void resumePlay() { + if (!mPlayer.isPlaying()) { + new Handler(Looper.getMainLooper()) + .postDelayed(() -> { + mPlayer.replay(); + // ToastUtil.show("强制播放" + val); + }, 100); + } + } + + /** + * 开始播放 + * + * @param url 流地址 + */ + @Override + public void play(String url, int playModel) { + srcUrl = url; + PLAY_MODEL = playModel; + waitNextUrl = null; + Log.i(TAG, "play" + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape" + videoLandscape); + if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { + mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); + if (landscape == VIDEO_VERTICAL && !isPk) { + url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); + } else if (landscape == VIDEO_HORIZONTAL || isPk) { + url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); + } + } else if (!url.contains(videoFps[0] + ".flv")) { + mPlayer.setViewResizeMode(false); + } + Log.e("purl121", url); + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + if (mPlayer.isPlaying()) { + mPlayer.stop(); + mPlayer.clearUrl(); + } + mPlayer.startUrl(url); + purl = url; + onPrepared(); + } + + @Override + public void switchStream(String url, int playModel) { + srcUrl = url; + PLAY_MODEL = playModel; + Log.i(TAG, "switchStream: " + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape = " + videoLandscape + " ispk = " + isPk + " bean = " + roomModel.getEnterRoomInfo().getIsconnection()); + if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { + mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); + if (landscape == VIDEO_VERTICAL && !isPk) { + url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); + } else if (landscape == VIDEO_HORIZONTAL || isPk) { + url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); + } + } else if (!url.contains(videoFps[0] + ".flv")) { + mPlayer.setViewResizeMode(false); + } + Log.e("purl121", url); + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + mPlayer.switchUrl(url); + purl = url; + } + + boolean tmpPk = false; + String waitNextUrl = null; + + @Override + public void switchStreamPk(boolean isPk) { + super.switchStreamPk(isPk); + Log.i(TAG, "switchStreamPk: isPk1" + isPk + " tmp = " + !tmpPk + " isPk2 = " + this.isPk); + if (this.isPk && tmpPk) return; + if (isPk && !tmpPk || this.isPk) { + mPlayer.setViewResizeMode(false); + String url; + if (PLAY_MODEL != -1) { + url = srcUrl.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); + } else { + url = srcUrl.replace(".flv", videoRatioHorizontal[1] + videoFps[0] + ".flv"); + } + if (!tmpPk) { + waitNextUrl = url; + } + mPlayer.switchUrl(srcUrl); + tmpPk = true; + } else if (!isPk) { + tmpPk = false; + if (landscape == VIDEO_VERTICAL && PLAY_MODEL != -1) { + waitNextUrl = srcUrl.replace(".flv", videoRatioVertical[PLAY_MODEL] + videoFps[0] + ".flv"); + } else if (landscape == VIDEO_HORIZONTAL && PLAY_MODEL != -1) { + waitNextUrl = srcUrl.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); + } else { + waitNextUrl = null; + } + mPlayer.switchUrl(srcUrl); + } + } + + @Override + public void clearFrame() { + super.clearFrame(); + mPlayer.clearFrame(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = ViewGroup.LayoutParams.WRAP_CONTENT; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.setLayoutParams(params); + mVideoView.requestLayout(); + + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = ViewGroup.LayoutParams.WRAP_CONTENT; + params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params1.addRule(RelativeLayout.ALIGN_TOP); + ry_view.setLayoutParams(params1); + ry_view.requestLayout(); + RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params2.height = DpUtil.dp2px(270); + params2.topMargin = DpUtil.dp2px(120); + mCover.setLayoutParams(params2); + mCover.requestLayout(); + } + + @Override + public void release() { + mEnd = true; + mStarted = false; + if (mPlayer != null) { + mPlayer.stop(); + mPlayer.release(); + } + Bus.getOff(this); + EventBus.getDefault().unregister(this); + L.e(TAG, "release------->"); + } + + @Override + public void stopPlay() { + Log.i(TAG, "stopPlay: "); + if (mCover != null) { + mCover.setAlpha(1f); + if (mCover.getVisibility() != View.VISIBLE) { + mCover.setVisibility(View.VISIBLE); + } + } + if (mPlayer != null) { + mPlayer.stop(); + } + stopPlay2(); + } + + @Override + public void stopPlay2() { + + } + + @Override + public void setViewUP(int i) { + if (mVideoView == null) return; + Log.e("PK状态", "" + i); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; + params.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = vHeight; + params1.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top); + params1.addRule(RelativeLayout.ALIGN_TOP); + ry_view.requestLayout(); + isPk = true; + if (mPlayer.getUrl().contains("848_24.flv") || mPlayer.getUrl().contains("1280_24.flv")) { + tmpPk = false; + switchStreamPk(true); + } + } + + /** + * 播放开始 + */ + public void onPrepared() { + if (mEnd) { + release(); + return; + } + int height; + if (videoLandscape == VIDEO_VERTICAL) { + height = ViewGroup.LayoutParams.MATCH_PARENT; + } else { + height = ViewGroup.LayoutParams.WRAP_CONTENT; + } + mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); + if (landscape == 2) { + Log.i(TAG, "onPrepared:还原9:16 land=" + videoLandscape); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = height; + params.topMargin = 0; + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.setLayoutParams(params); + mVideoView.requestLayout(); + + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = height; + params1.topMargin = 0; + ry_view.setLayoutParams(params1); + ry_view.requestLayout(); + RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params2.height = height; + params2.topMargin = 0; + mCover.setLayoutParams(params2); + mCover.requestLayout(); + } else { + Log.i(TAG, "onPrepared:还原16:9"); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = height; + params.topMargin = 0; + if (videoLandscape == VIDEO_HORIZONTAL) { + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + } + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.setLayoutParams(params); + mVideoView.requestLayout(); + + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = height; + params1.topMargin = 0; + params1.addRule(RelativeLayout.ALIGN_TOP); + if (videoLandscape == VIDEO_HORIZONTAL) { + params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + } + ry_view.setLayoutParams(params1); + ry_view.requestLayout(); + RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params2.height = height; + params2.topMargin = DpUtil.dp2px(120); + mCover.setLayoutParams(params2); + mCover.requestLayout(); + } + } + + @Override + public void setPkview() { + Log.i("收到socket--->", "变成16:9"); + String url = srcUrl; + isPk = true; + switchStreamPk(true); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + } + + @Override + public synchronized void setPkEndview() { + + Log.i("收收收", landscape + ""); + isPk = false; + tmpPk = false; + switchStreamPk(false); + if (landscape == 2) { + Log.i("收到socket--->", "还原9:16"); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = RelativeLayout.LayoutParams.MATCH_PARENT; + params.topMargin = 0; + mVideoView.requestLayout(); + + } else { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + } +// if (detailsView != null) { +// mVideoView.removeView(detailsView); +// detailsView = null; +// } + } + + public void removeDetailView() { +// if (detailsView != null) { +// mVideoView.removeView(detailsView); +// detailsView = null; +// } + } + + @Override + public ViewGroup getSmallContainer() { + return mSmallContainer; + } + + + @Override + public ViewGroup getRightContainer() { + return mRightContainer; + } + + @Override + public ViewGroup getPkContainer() { + return mPkContainer; + } + + @Override + public void changeToLeft() { + if (mVideoView != null) { + + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; +// params.height = mContext.getResources().getDimensionPixelOffset(R.dimen.live_view); + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + + } + if (mLoading != null && mLeftContainer != null) { + ViewParent viewParent = mLoading.getParent(); + if (viewParent != null) { + ((ViewGroup) viewParent).removeView(mLoading); + } + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); + params.gravity = Gravity.CENTER; + mLoading.setLayoutParams(params); + mLeftContainer.addView(mLoading); + } + } + + @Override + public void changeToBig() { + if (mVideoView != null) { + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + mVideoView.setLayoutParams(params); + + } + if (mLoading != null && mRoot != null) { + ViewParent viewParent = mLoading.getParent(); + if (viewParent != null) { + ((ViewGroup) viewParent).removeView(mLoading); + } + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); + params.addRule(RelativeLayout.CENTER_IN_PARENT); + mLoading.setLayoutParams(params); + mRoot.addView(mLoading); + } + } + + @Override + public void onResume() { + if (!mPausedPlay && mPaused && mVideoView != null) { +// mVideoView.runInForeground(); +// mVideoView.start(); + } + mPaused = false; +// if (mPlayer.isPlaying() == 1) { +// mPlayer.resumeVideo(); +// mPlayer.resumeAudio(); +// } + } + + @Override + public void onPause() { +// if (!mPausedPlay && mVideoView != null) { +// mVideoView.runInBackground(false); +// } +// mPaused = true; +// mPlayer.pauseVideo(); +// mPlayer.pauseAudio(); + } + + @Override + public void onDestroy() { + release(); + } + + //全屏 + @Override + public void fullScreen() { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = RelativeLayout.LayoutParams.MATCH_PARENT; + params.topMargin = 0; + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + } + + //小屏 + @Override + public void smallScreen() { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + // mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation0); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + } + + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onUpdata(String str) { + if ("UsertoRY".equals(str)) { + DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + UsertoRY(); + dialog = null; + } + }); + + } else if ("inviteMic".equals(str)) { + String content = "邀請您進行語音連麥"; + String confirm = "接受"; + String cancel = "拒絕"; + if (!WordUtil.isNewZh()) { + content = "You are invited to join the voice connection"; + confirm = "accept"; + cancel = "cancel"; + } + DialogUitl.Builder builder = new DialogUitl.Builder(mContext) + .setContent(content) + .setTitle(mLiveBean.getUserNiceName()) + .setConfirmString(confirm) + .setCancelString(cancel) + .setView(R.layout.dialog_live_mic_invite) + .setClickCallback(new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + String[] permissions; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + permissions = new String[]{ + Manifest.permission.READ_MEDIA_IMAGES, + Manifest.permission.RECORD_AUDIO + }; + } else { + permissions = new String[]{ + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.RECORD_AUDIO + }; + } + LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { + @Override + public void run() { + UsertoRY(); + + } + }); + } + }); + builder.build().show(); + + } else if ("endMic".equals(str)) { + if (rcrtcRoom != null) { + // 开始切换为观众身份 + RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { + + /** + * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 + * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 + */ + @Override + public void onKicked() { + + } + + @Override + public void onSuccess() { + Log.e("ry", "下麦成功"); + // 该用户切换为观众成功,可以以观众身份进行音视频 + //退出rtc播放 + leaveRoom(); + } + + /** + * 当切换失败且不影响当前角色继续音视频时回调 + * @param errorCode 失败错误码 + */ + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "下麦失败" + errorCode); + leaveRoom(); + } + + private void leaveRoom() { + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + @Override + public void onSuccess() { + userJoinLinkMic = false; + Log.e("ry", "退出多人房间成功"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + if (WordUtil.isNewZh()) { + ToastUtil.show("已成功退出語音連麥"); + } else { + ToastUtil.show("You have successfully exited the voice connection"); + } + if (mPlayer.getNowPlayer() != null) { + mPlayer.play(); + Log.e("ry", mPlayer.isPlaying() + "purl" + purl); + if (!mPlayer.isPlaying()) { + mPlayer.switchUrl(purl); + } + ry_view.removeAllViews(); + ry_view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; + onPrepared(); + rcrtcRoom = null; + MicStatusManager.getInstance().clear(); + + resumePlay(); + } + + if (onMicCallback != null) { + onMicCallback.onMikUpdate(); + } + } + }); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", errorCode + "退出多人房间成功"); + userJoinLinkMic = false; + } + }); + + } + }); + } + } else if ("Debug".equals(str)) { + if (EasyFloat.isShow("Debug")) { + EasyFloat.dismiss("Debug"); + return; + } + EasyFloat.with(mContext) + .setDragEnable(true) + .setTag("Debug") + .setLayout(debugView) + .show(); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onOpenDrawer(LiveAudienceEvent event) { + if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO) { + int ban = 0;//全模式都可以选择 + switch (roomModel.getClarityType() - 1) { + case PLAY_MODEL_720://仅允许720(高清),ban掉1080(超高清)模式 + ban = LiveClarityCustomPopup.BAN_1080; + break; + case -1://没有该字段 + case PLAY_MODEL_480://仅允许480(流畅),ban掉1080(超高清)和720(高清)模式 + ban = LiveClarityCustomPopup.BAN_720; + break; + + } + LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, + IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR), + ban, + true); + new XPopup.Builder(mContext) + .setPopupCallback(new XPopupCallback() { + @Override + public void onCreated(BasePopupView popupView) { + + } + + @Override + public void beforeShow(BasePopupView popupView) { + + } + + @Override + public void onShow(BasePopupView popupView) { + + } + + @Override + public void onDismiss(BasePopupView popupView) { + int selectClarity = liveClarityCustomPopup.getSelectClarity(); + if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR)) + return; + if (selectClarity == PLAY_MODEL_ANCHOR) { + switchStream(srcUrl, PLAY_MODEL_DEF); + setAudiencePlayModel(selectClarity); + } else { + switchStream(srcUrl, selectClarity); + } + IMLoginManager.get(mContext).put(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, selectClarity); + showToast(); + } + + private void showToast() { + if (WordUtil.isNewZh()) { + DialogUitl.showToast(mContext, "設置成功\n" + + "正在為你轉換中", 3000); + } else { + DialogUitl.showToast(mContext, "successful\n" + + "It's being converted for you", 3000); + } + } + + @Override + public void beforeDismiss(BasePopupView popupView) { + + } + + @Override + public boolean onBackPressed(BasePopupView popupView) { + return false; + } + + @Override + public void onKeyBoardStateChanged(BasePopupView popupView, int height) { + + } + + @Override + public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { + + } + + @Override + public void onClickOutside(BasePopupView popupView) { + + } + }) + .asCustom(liveClarityCustomPopup) + .show(); + } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.FONT_SIZE) { + int fount = 0; + try { + fount = Integer.parseInt(SpUtil.getStringValue("pd_live_room_fount_size")); + } catch (Exception ignored) { + + } + new LiveFontSizeSettingDialog(mContext, fount).setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(Integer bean, int position) { + EventBus.getDefault().post(new LiveAudienceEvent() + .setNums(bean) + .setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE)); + } + }).showDialog(); + } + } + + /** + * 把观众转换成主播 + */ + public List userinputStreamList = new ArrayList<>(); + + + public void UsertoRY() { + userinputStreamList.clear(); + Log.e("ry", "主播同意了UsertoRY"); + if (userJoinLinkMic) {//已经在房间内,不再joinRoom直接去连麦 + subscribeMic(rcrtcRoom); + return; + } + RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() + // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO + .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) + .setLiveRole(RCRTCLiveRole.AUDIENCE) + .build(); + RCRTCEngine.getInstance().joinRoom(LiveActivity.mLiveUid, roomConfig, new IRCRTCResultDataCallback() { + + + @Override + public void onSuccess(RCRTCRoom data) { + userJoinLinkMic = true; + rcrtcRoom = data; + subscribeMic(data); + + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", LiveActivity.mLiveUid + errorCode + ""); + if (errorCode.getValue() == 50007) {//userJoinLinkMic可能失效,直接leaveRoom + userJoinLinkMic = false; + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + UsertoRY(); + } + }); + } else { + ToastUtil.show("房间失败" + errorCode); + } + + } + }); + + + } + + private void subscribeMic(RCRTCRoom data) { + runOnUiThread(new Runnable() { + @Override + public void run() { + RCRTCEngine.getInstance().enableSpeaker(true); + //遍历远端用户发布的资源列表 + Log.i(TAG, "软件资源数量:" + data.getLiveStreams().size()); + for (RCRTCInputStream stream : data.getLiveStreams()) { + Log.i(TAG, "资源流 type: " + stream.getMediaType()); + if (stream.getMediaType() == RCRTCMediaType.VIDEO) { + //暂停播放 + mPlayer.stop(); + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT); + ry_view.addView(remoteView); + Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + data.getLiveStreams().size()); + } + userinputStreamList.add(stream); + } + rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList, new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", userinputStreamList.size() + LiveActivity.mLiveUid + "订阅失败" + errorCode.toString()); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + + @Override + public void onSuccess() { + Log.e("ry", "订阅资源成功"); +// new Handler().postDelayed(new Runnable() { +// @Override +// public void run() { + toMic(); +// } +// }, 3000); + + } + }); + } + }); + } + + /** + * 主房间事件监听 + * 详细说明请参考文档:https://www.rongcloud.cn/docs/api/android/rtclib_v4/cn/rongcloud/rtc/api/callback/IRCRTCRoomEventsListener.html + */ + public IRCRTCRoomEventsListener roomEventsListener = new IRCRTCRoomEventsListener() { + @Override + public void onRemoteUserPublishResource(RCRTCRemoteUser rcrtcRemoteUser, List list) { + Log.e("ry", "远端来了" + list.size()); + //TODO 按需在此订阅远端用户发布的资源 + rcrtcRoom.getLocalUser().subscribeStreams(list, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "远端成功" + list.size()); + + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", "远端失败" + list.size()); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + }); + } + + @Override + public void onRemoteUserMuteAudio(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { + + } + + @Override + public void onRemoteUserMuteVideo(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { + + } + + @Override + public void onRemoteUserUnpublishResource(RCRTCRemoteUser remoteUser, List streams) { + + } + + @Override + public void onUserJoined(RCRTCRemoteUser remoteUser) { + + } + + @Override + public void onUserLeft(RCRTCRemoteUser remoteUser) { + + } + + @Override + public void onUserOffline(RCRTCRemoteUser remoteUser) { + + } + + @Override + public void onPublishLiveStreams(List streams) { + + } + + @Override + public void onUnpublishLiveStreams(List streams) { + + } + }; + + + public List userinputStreamList1 = new ArrayList<>(); + public List userinputStreamList2 = new ArrayList<>(); + + public void toMic() { + RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC, RCRTCParamsType.AudioScenario.MUSIC_CLASSROOM); + userinputStreamList1.clear(); + userinputStreamList2.clear(); + RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; + int minRate = 200; + int maxRate = 900; + switch (IMLoginManager.get(mContext).getSelectClarity()) { + case 0: + rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; + minRate = landscape == 1 ? 900 : 200; + maxRate = landscape == 1 ? 700 : 900; + break; + case 1: + rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; + minRate = landscape == 1 ? 900 : 250; + maxRate = landscape == 1 ? 700 : 2200; + break; + case 2: + rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; + minRate = landscape == 1 ? 900 : 400; + maxRate = landscape == 1 ? 700 : 4000; + break; + } + // 示例代码使用480x640分辨率演示 + RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig + .Builder.create() + //设置分辨率 + .setVideoResolution(rcrtcVideoResolution) + //设置帧率 + .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_24) + //设置最小码率,480P下推荐200 + .setMinRate(minRate) + //设置最大码率,480P下推荐900 + .setMaxRate(maxRate) + .build(); + RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); +// 创建视图渲染视图 +// RCRTCVideoView videoView = new RCRTCVideoView(contexts); +// RCRTCEngine.getInstance().getDefaultVideoStream().setVideoView(videoView); +//TODO 示例代码使用获取本地默认视频流、音频流演示 + ArrayList streams = new ArrayList<>(); +// streams.add(RCRTCEngine.getInstance().getDefaultVideoStream()); + streams.add(RCRTCEngine.getInstance().getDefaultAudioStream()); + if (landscape == 1) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + setLiveBeanLandscape(1); + } + }); + + } +// 开启摄像头 +// RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(null); +// 开始切换为主播身份 + RCRTCEngine.getInstance().getRoom().getLocalUser().switchToBroadcaster(streams, new IRCRTCSwitchRoleDataCallback() { + /** + * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 + * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 + */ + @Override + public void onKicked() { + Log.e("ry", "切换onKicked"); + + } + + @Override + public void onSuccess(RCRTCLiveInfo data) { + rcrtcRoom.registerRoomListener(roomEventsListener); + //该用户切换为主播成功,可以以主播身份进行音视频 + Log.e("ry", "切换成功"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + if (onMicCallback != null) { + onMicCallback.onMikUpdate(); + } + //遍历远端用户列表 + for (int i = 0; i < rcrtcRoom.getRemoteUsers().size(); i++) { + Log.e("ry", rcrtcRoom.getRemoteUsers().get(i).getUserId() + "收到rcrtcOtherRoom" + rcrtcRoom.getRemoteUsers().size()); + //遍历远端用户发布的资源列表 + for (RCRTCInputStream stream : rcrtcRoom.getRemoteUsers().get(i).getStreams()) { + Log.e("ry", i + "收到" + stream.getMediaType() + "实打实打算" + rcrtcRoom.getRemoteUsers().get(i).getUserId()); + if (stream.getMediaType() == RCRTCMediaType.VIDEO) { + if (userinputStreamList1.size() == 0) { + + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setStreamType(RCRTCStreamType.NORMAL); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + ((RCRTCVideoInputStream) stream).setVideoFrameListener(new IRCRTCVideoInputFrameListener() { + @Override + public void onFrame(RCRTCRemoteVideoFrame videoFrame) { + String debugText = " 2、安卓主播开播, 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" + + "rotation:" + videoFrame.getRotation() + "\n" + + "timestampNs:" + videoFrame.getTimestampNs() + "\n" + + "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + + "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n"; + //Log.d("ry", "onFrame: " + debugText); + new Handler(Looper.getMainLooper()).post(() -> { + debugView.setText(debugText); + + }); + } + }); + //todo 本demo只演示添加1个远端用户的视图 + ry_view.removeAllViews(); + remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL); + ry_view.addView(remoteView); + } + userinputStreamList1.add(stream); + } + userinputStreamList2.add(stream); + } + } + //开始订阅资源 + rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList2, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "订阅资源成功"); + MicStatusManager.getInstance().setMicData(MicStatusManager.MIC_TYPE_OPEN, LiveActivity.mLiveUid); + AudioManager audioManager = (AudioManager) contexts.getSystemService(Context.AUDIO_SERVICE); + RCRTCEngine.getInstance().enableSpeaker(true); + audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); + audioManager.setSpeakerphoneOn(true); + + HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm") + .params("roomid", LiveActivity.mLiveUid) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.e("ry", code + "热热热"); + } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", "订阅资源失败: " + rtcErrorCode.getReason()); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + }); + } + }); + + + } + + /** + * 当切换失败且不影响当前角色继续音视频时回调 + * @param errorCode 失败错误码 + */ + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", errorCode + "切换失败"); + + } + }); + } + + @Override + public void setLoadViewListener(LoadingListener listener) { + super.setLoadViewListener(listener); + } + + private void showLoadingDialog() { + if (PLAY_MODEL == PLAY_MODEL_480) return; + + new DialogUitl.Builder(mContext) + .setTitle("網絡提示") + .setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。") + .setView(R.layout.dialog_simple_tip) + .setClickCallback(new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + dialog.dismiss(); + } + }).build().show(); + PLAY_MODEL = PLAY_MODEL_480; + String url = srcUrl; + if (videoLandscape == VIDEO_VERTICAL) { + url = url.replace(".flv", videoRatioVertical[PLAY_MODEL_480] + videoFps[0] + ".flv"); + } else if (videoLandscape == VIDEO_HORIZONTAL) { + url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); + } + mPlayer.switchUrl(url); + } + + private class ExoPlayerListener implements Player.Listener { + String TAG = "播放流"; + + @Override + public void onPlayerError(PlaybackException error) { + Player.Listener.super.onPlayerError(error); + debugView.setText("播放出错code=" + error.errorCode + " msg=" + error.getErrorCodeName()); + } + + @Override + public void onVideoSizeChanged(VideoSize videoSize) { + Player.Listener.super.onVideoSizeChanged(videoSize); + Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height); + //ToastUtil.show("分辨率: 宽 = " + videoSize.width + " 高 = " + videoSize.height); + if (videoSize.height > videoSize.width) { + videoLandscape = VIDEO_VERTICAL; + } else { + videoLandscape = VIDEO_HORIZONTAL; + } + } + + @Override + public void onPlaybackStateChanged(int playbackState) { + Player.Listener.super.onPlaybackStateChanged(playbackState); + if (playbackState == Player.STATE_BUFFERING) { + //showLoadingDialog(); + mLoading.setVisibility(View.VISIBLE); + OkDownload.getInstance().pauseAll(); + Log.i(TAG, "onPlaybackStateChanged: 缓存中"); + } else { + mLoading.setVisibility(View.INVISIBLE); + Log.i(TAG, "onPlaybackStateChanged: 播放中"); + } + } + + @Override + public void onIsPlayingChanged(boolean isPlaying) { + Player.Listener.super.onIsPlayingChanged(isPlaying); + if (isPlaying) { + hideCover(); + mLoading.setVisibility(View.INVISIBLE); + Log.i(TAG, "onIsPlayingChanged: 开始播放 | waitNextUrl = " + waitNextUrl); + OkDownload.getInstance().startAll(); + if (loadingListener != null) { + loadingListener.onPlayer(); + } + if (waitNextUrl != null) { + mPlayer.switchUrl(waitNextUrl); + waitNextUrl = null; + } + } + } + } + + private int mPkTimeCount = 0; + + + public interface PlayViewLayoutInterface { + void playViewLayout(int width, int height); + } + + private PlayViewLayoutInterface layoutInterface; + + public void setLayoutInterface(PlayViewLayoutInterface layoutInterface) { + mVideoView.post(new Runnable() { + @Override + public void run() { + int width = mVideoView.getMeasuredWidth(); + int height = mVideoView.getMeasuredHeight(); + if (layoutInterface != null) { + layoutInterface.playViewLayout(width, height); + } + } + }); + } + + +} diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 9b50cfc7f..0e7d75410 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -9,8 +9,8 @@ import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.LIVE_PK_I import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.inputStreamList; import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.inputStreamList1; import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.mPkUid; -import static cn.rongcloud.rtc.base.RCRTCLiveRole.BROADCASTER; +import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.res.Resources; @@ -46,6 +46,7 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.RandomPkManager; +import com.yunbao.common.manager.SWManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; @@ -70,26 +71,19 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; import java.util.List; -import cn.rongcloud.rtc.api.RCRTCConfig; import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.RCRTCMixConfig; import cn.rongcloud.rtc.api.RCRTCRemoteUser; import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.RCRTCRoomConfig; -import cn.rongcloud.rtc.api.callback.IRCRTCEngineEventListener; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; import cn.rongcloud.rtc.api.stream.RCRTCInputStream; import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; -import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; -import cn.rongcloud.rtc.api.stream.RCRTCVideoView; import cn.rongcloud.rtc.base.RCRTCParamsType; -import cn.rongcloud.rtc.base.RCRTCRoomType; -import cn.rongcloud.rtc.base.RCRTCVideoEventCode; import cn.rongcloud.rtc.base.RTCErrorCode; import cn.rongcloud.rtc.core.CameraVideoCapturer; -import cn.rongcloud.rtc.core.RendererCommon; +import io.agora.rtc2.RtcEngine; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; @@ -101,13 +95,12 @@ import io.rong.message.TextMessage; */ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITXLivePushListener { - + private RtcEngine mRtcEngine; private int mMeiBaiVal;//基础美颜 美白 private int mMoPiVal;//基础美颜 磨皮 private int mHongRunVal;//基础美颜 红润 private String mBgmPath;//背景音乐路径 private Bitmap mFilterBmp; - private TXDeviceManager mTXDeviceManager; private TRTCCloudDef.TRTCParams mTRTCParams; private Handler mMainHandler; @@ -117,7 +110,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public LinearLayout dr_pk_view; public static RCRTCRoom rtcRoom; public static RCRTCLiveInfo rcrtcLiveInfo; - private ViewGroup liveActivityContainer; public FrameLayout timeTitle; public TextView textTime; @@ -126,6 +118,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX private LinearLayout goto_room_view; private boolean isPk = false; private boolean isNeedOpenCamera = false; + private SWManager swManager; //修改上面主播的头像 @Subscribe(threadMode = ThreadMode.MAIN) @@ -139,7 +132,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX goto_room_view.setVisibility(View.VISIBLE); } else { goto_room_view.setVisibility(View.GONE); - } } } @@ -414,7 +406,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh()?"抱歉!出錯了!":"i \\'m sorry! An error occurred"); + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); } }); @@ -470,7 +462,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } }; - @Override public void init() { super.init(); @@ -615,8 +606,9 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX }); } }); + initRtcEngine(); - // 构建 RoomConfig,指定房间类型和主播身份: + /* // 构建 RoomConfig,指定房间类型和主播身份: RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) @@ -772,9 +764,24 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } - }); + });*/ } + /** + * 初始化声网SDK + */ + private void initRtcEngine() { + swManager = SWManager.get(); + swManager.setAnchorContainer(mPreView); + swManager.initRtcEngine((Activity) mContext, "11"); + swManager.setOnRtcEngineListener(new SWManager.onRtcEngineListener() { + @Override + public void onOpenSuccess(String channel, int uid) { + //开播成功 + + } + }); + } @Override public void changeToLeft() { @@ -847,6 +854,10 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX */ @Override public void startPush(String pushUrl) { + //开播成功,创建频道 + if (swManager != null) { + swManager.createRoom(SWManager.shengwang_token, SWManager.shengwang_channelName); + } if (rcrtcLiveInfo != null) { rcrtcLiveInfo.addPublishStreamUrl(pushUrl, new IRCRTCResultDataCallback() { @Override @@ -946,7 +957,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void onResume() { mPaused = false; Log.i("摄像头", "onResume: " + isNeedOpenCamera); - if(isNeedOpenCamera){ + if (isNeedOpenCamera) { RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(new IRCRTCResultDataCallback() { @Override public void onSuccess(Boolean data) { diff --git a/live/src/main/res/layout/acticity_new_live.xml b/live/src/main/res/layout/acticity_new_live.xml new file mode 100644 index 000000000..886d43dcd --- /dev/null +++ b/live/src/main/res/layout/acticity_new_live.xml @@ -0,0 +1,37 @@ + + + + + + + + + + diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index 91b5d0346..b602c6757 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -12,8 +12,14 @@ android:layout_width="match_parent" app:surface_type="texture_view" app:use_controller="false" + android:visibility="gone" android:layout_height="match_parent" /> + + Date: Fri, 12 Apr 2024 18:29:26 +0800 Subject: [PATCH 02/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/CommonAppConfig.java | 11 ++ .../com/yunbao/common/bean/SwTokenModel.java | 23 +++ .../com/yunbao/common/http/PDLiveApi.java | 3 + .../common/http/live/LiveNetManager.java | 26 +++- .../yunbao/common/manager/SWAuManager.java | 66 +++++++-- .../com/yunbao/common/manager/SWManager.java | 108 +++++++++++++- .../main/java/com/yunbao/common/utils/L.java | 8 + live/src/main/AndroidManifest.xml | 4 - .../live/activity/LiveRyAnchorActivity.java | 39 ++++- .../yunbao/live/activity/NewLiveActivity.java | 139 ------------------ .../presenter/LiveRyLinkMicPkPresenter.java | 62 ++++++-- .../yunbao/live/socket/SocketRyClient.java | 2 +- .../live/views/AbsRyLivePushViewHolder.java | 6 +- .../live/views/LiveNewReadyRyViewHolder.java | 2 - .../live/views/LivePlayRyViewHolder.java | 22 ++- .../live/views/LivePushRyViewHolder.java | 28 +++- .../live/views/PortraitLiveManager.java | 1 + .../src/main/res/layout/acticity_new_live.xml | 37 ----- .../main/res/layout/view_live_play_ksy.xml | 37 +++-- .../src/main/res/layout/view_live_push_ry.xml | 8 +- .../yunbao/main/activity/LoginActivity.java | 1 - .../yunbao/main/activity/MainActivity.java | 34 ++++- 22 files changed, 413 insertions(+), 254 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/bean/SwTokenModel.java delete mode 100644 live/src/main/java/com/yunbao/live/activity/NewLiveActivity.java delete mode 100644 live/src/main/res/layout/acticity_new_live.xml diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index 2f447a77e..3ec41c897 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -76,6 +76,17 @@ public class CommonAppConfig { public static boolean isGetNewWrap = false;//是否获取到新的包裹礼物 public static int alert_time = 1; public static int alert_end_time = 1; + public static String SWToken = ""; //声网Token + public static final String SWChannelPrefix = "g"; + + + /** + * 获取通道 + * @return + */ + public static String getChannelName() { + return SWChannelPrefix+ getInstance().getUid(); + } private CommonAppConfig() { diff --git a/common/src/main/java/com/yunbao/common/bean/SwTokenModel.java b/common/src/main/java/com/yunbao/common/bean/SwTokenModel.java new file mode 100644 index 000000000..2f50ed67c --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/SwTokenModel.java @@ -0,0 +1,23 @@ +package com.yunbao.common.bean; + +/** + * 声网token + */ +public class SwTokenModel extends BaseModel { + private String token; + + public SwTokenModel() { + } + + public SwTokenModel(String token) { + this.token = token; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } +} diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index ab4c92838..a2b978554 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -70,6 +70,7 @@ import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.SudGameUserModel; import com.yunbao.common.bean.SudRoomListModel; import com.yunbao.common.bean.SudgameCodeModel; +import com.yunbao.common.bean.SwTokenModel; import com.yunbao.common.bean.UserAreaBean; import com.yunbao.common.bean.UserAvatarSelectBean; import com.yunbao.common.bean.VipModel; @@ -1192,4 +1193,6 @@ public interface PDLiveApi { Observable> checkUpgrades(@Query("liveuid") String liveUid); @GET("/api/public/?service=Guard.getRewards") Observable> guardGetRewards(@Query("guard_level") String guardLevel,@Query("liveuid") String liveUid); + @GET("/api/public/?service=Tx.getShengwangToken") + Observable> getSwToken(); } diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index 974ab71af..16d7c046c 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -66,6 +66,7 @@ import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.SudGameUserModel; import com.yunbao.common.bean.SudRoomListModel; import com.yunbao.common.bean.SudgameCodeModel; +import com.yunbao.common.bean.SwTokenModel; import com.yunbao.common.bean.UserAreaBean; import com.yunbao.common.bean.UserAvatarSelectBean; import com.yunbao.common.bean.VipModel; @@ -3133,7 +3134,6 @@ public class LiveNetManager { } } }).isDisposed(); - } public void guardGetRewards(String guardLevel, String liveUid, HttpCallback callback) { @@ -3160,6 +3160,30 @@ public class LiveNetManager { } + public void getSwToken( HttpCallback callback) { + API.get().pdLiveApi(mContext) + .getSwToken() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel listResponseModel) throws Exception { + if (callback != null) { + callback.onSuccess(listResponseModel.getData().getInfo()); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + throwable.printStackTrace(); + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + + } + /** * 直播间取消网络请求 */ diff --git a/common/src/main/java/com/yunbao/common/manager/SWAuManager.java b/common/src/main/java/com/yunbao/common/manager/SWAuManager.java index 7a3b9741e..e69707e99 100644 --- a/common/src/main/java/com/yunbao/common/manager/SWAuManager.java +++ b/common/src/main/java/com/yunbao/common/manager/SWAuManager.java @@ -5,15 +5,18 @@ import android.content.Context; import android.view.SurfaceView; import android.widget.FrameLayout; +import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.manager.base.BaseCacheManager; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.StringUtil; import io.agora.rtc2.ChannelMediaOptions; import io.agora.rtc2.Constants; import io.agora.rtc2.IRtcEngineEventHandler; -import io.agora.rtc2.RtcEngine; +import io.agora.rtc2.RtcConnection; import io.agora.rtc2.RtcEngineConfig; +import io.agora.rtc2.RtcEngineEx; import io.agora.rtc2.video.VideoCanvas; /** @@ -24,12 +27,9 @@ public class SWAuManager extends BaseCacheManager { // 填写项目的 App ID,可在声网控制台中生成 public static final String shengwang_appId = "4cf0376582d742ac8a96778b25b1079e"; // 填写频道名 - public static final String shengwang_channelName = "12"; - // 填写声网控制台中生成的临时 Token - public static final String shengwang_token = "007eJxSYJi477Xju22xV7ov7GfzzOnbtCU0IuK9+YuwWf2uLPGnl8xRYDBJTjMwNjcztTBKMTcxSky2SLQ0Mze3SDIyTTI0MLdMPWQrltYQyMjw/4kCCyMDBIL4TAyGRiwMlpaWloAAAAD//w/TIFY="; private Activity mContext; public static SWAuManager manager; - private RtcEngine mRtcEngine; + private RtcEngineEx mRtcEngine; private FrameLayout audienceContainer; //主播视图 private FrameLayout pkContainer1; //pk主播视图1 private FrameLayout pkContainer2; //pk主播视图2 @@ -64,7 +64,7 @@ public class SWAuManager extends BaseCacheManager { config.mAppId = SWAuManager.shengwang_appId; config.mEventHandler = mRtcEventHandler; // 创建并初始化 RtcEngine - mRtcEngine = RtcEngine.create(config); + mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); } catch (Exception e) { throw new RuntimeException("Check the error."); } @@ -76,7 +76,6 @@ public class SWAuManager extends BaseCacheManager { } /** - * guanzhong * 加入房间 */ public void joinRoom(String strUid, String token, String channelName) { @@ -96,11 +95,60 @@ public class SWAuManager extends BaseCacheManager { options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; // 直播场景下,设置频道场景为 BROADCASTING (直播场景) options.audienceLatencyLevel = Constants.AUDIENCE_LATENCY_LEVEL_LOW_LATENCY; // 觀眾走極速直播 - // 使用临时 Token 加入频道,自行指定用户 ID 并确保其在频道内的唯一性 mRtcEngine.joinChannel(token, channelName, uid, options); } + + public void joinExRoomEx(String strUid, String token, String channelName) { + int uid; + if (StringUtil.isEmpty(strUid)) { + uid = 0; + } else { + uid = Integer.parseInt(strUid); + } + + // 创建 ChannelMediaOptions 对象,并进行配置 + ChannelMediaOptions options = new ChannelMediaOptions(); + // 根据场景将用户角色设置为 AUDIENCE (观众) + options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; + // 直播场景下,设置频道场景为 BROADCASTING (直播场景) + options.audienceLatencyLevel = Constants.AUDIENCE_LATENCY_LEVEL_LOW_LATENCY; // 觀眾走極速直播 + options.autoSubscribeVideo = true; + options.autoSubscribeAudio = true; + + RtcConnection rtcConnection = new RtcConnection(); + rtcConnection.channelId = "g99411"; //對方主播的頻道 + rtcConnection.localUid = 99412;//自己的ID + + mRtcEngine.joinChannelEx(token, rtcConnection, options, new IRtcEngineEventHandler() { + @Override + public void onJoinChannelSuccess(String channel, int uid, int elapsed) { + super.onJoinChannelSuccess(channel, uid, elapsed); + L.eSw("onJoinChannelSuccess:" + channel + " uid " +uid+ " elapsed: " + elapsed); + + SurfaceView surfaceView = new SurfaceView(mContext); + surfaceView.setZOrderMediaOverlay(true); + pkContainer1.addView(surfaceView); + + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, 99411); + + mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); + + } + + @Override + public void onError(int err) { + super.onError(err); + L.eSw("onError:" + err); + } + }); + } + + public static String getChannelName(String liveUid) { + return CommonAppConfig.SWChannelPrefix + liveUid; + } + //远程监听 private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { @Override @@ -110,7 +158,7 @@ public class SWAuManager extends BaseCacheManager { @Override public void run() { // 获取 uid 后,设置远端视频视图 - setupRemoteVideo(uid); + //setupRemoteVideo(uid); } }); } diff --git a/common/src/main/java/com/yunbao/common/manager/SWManager.java b/common/src/main/java/com/yunbao/common/manager/SWManager.java index a97d85b9b..5dfeaf474 100644 --- a/common/src/main/java/com/yunbao/common/manager/SWManager.java +++ b/common/src/main/java/com/yunbao/common/manager/SWManager.java @@ -5,17 +5,23 @@ import android.content.Context; import android.view.SurfaceView; import android.widget.FrameLayout; +import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; +import com.yunbao.common.bean.SwTokenModel; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.base.BaseCacheManager; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; -import cn.rongcloud.rtc.base.RCRTCParamsType; import io.agora.rtc2.ChannelMediaOptions; import io.agora.rtc2.Constants; import io.agora.rtc2.IRtcEngineEventHandler; +import io.agora.rtc2.RtcConnection; import io.agora.rtc2.RtcEngine; import io.agora.rtc2.RtcEngineConfig; +import io.agora.rtc2.RtcEngineEx; import io.agora.rtc2.video.VideoCanvas; import io.agora.rtc2.video.VideoEncoderConfiguration; @@ -27,12 +33,9 @@ public class SWManager extends BaseCacheManager { // 填写项目的 App ID,可在声网控制台中生成 public static final String shengwang_appId = "4cf0376582d742ac8a96778b25b1079e"; // 填写频道名 - public static final String shengwang_channelName = "12"; - // 填写声网控制台中生成的临时 Token - public static final String shengwang_token = "007eJxTYOD6Iv3buTHm6666BKY1Cr7mUZU3tY0eHH5qbF4jv5nNukqBwSQ5zcDY3MzUwijF3MQoMdki0dLM3Nwiycg0ydDA3DL1xX/RtIZARgb+3ExWRgYIBPGZGAyNGBgAhDMb8Q=="; private Activity mContext; public static SWManager manager; - private RtcEngine mRtcEngine; + private RtcEngineEx mRtcEngine; private int uid; VideoEncoderConfiguration cfg; private FrameLayout anchorContainer; //主播视图 @@ -79,7 +82,7 @@ public class SWManager extends BaseCacheManager { config.mAppId = SWManager.shengwang_appId; config.mEventHandler = mRtcEventHandler; // 创建并初始化 RtcEngine - mRtcEngine = RtcEngine.create(config); + mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); } catch (Exception e) { throw new RuntimeException("Check the error."); } @@ -131,7 +134,6 @@ public class SWManager extends BaseCacheManager { } } - /** * 创建房间 */ @@ -143,6 +145,68 @@ public class SWManager extends BaseCacheManager { mRtcEngine.joinChannel(token, channelName, uid, options); } + public void updateMyVideoView(FrameLayout frameLayout, String channelName) { + mRtcEngine.setupRemoteVideoEx(null, null); + + RtcConnection rtcConnection = new RtcConnection(); + rtcConnection.channelId = channelName; //自己频道名称 + rtcConnection.localUid = uid;//自己的ID + + SurfaceView surfaceView = new SurfaceView(mContext); + surfaceView.setZOrderMediaOverlay(true); + frameLayout.addView(surfaceView); + + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid); + mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); + } + + + public void joinExRoomEx(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); + pkContainer1.addView(surfaceView); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid)); + mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); + } + }); + } + + @Override + public void onError(int err) { + super.onError(err); + L.eSw("onError:" + err); + } + }); + } + //远程监听 private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { @Override @@ -152,7 +216,7 @@ public class SWManager extends BaseCacheManager { @Override public void run() { // 获取 uid 后,设置远端视频视图 - setupRemoteVideo(uid); + //setupRemoteVideo(uid); } }); } @@ -170,8 +234,36 @@ public class SWManager extends BaseCacheManager { super.onError(err); ToastUtil.show("onError:" + err); } + + @Override + public void onTokenPrivilegeWillExpire(String token) { + super.onTokenPrivilegeWillExpire(token); + refreshToken(); + } + + @Override + public void onRequestToken() { + super.onRequestToken(); + refreshToken(); + } }; + private void refreshToken() { + LiveNetManager.get(mContext).getSwToken(new HttpCallback() { + @Override + public void onSuccess(SwTokenModel data) { + if (mRtcEngine != null) { + mRtcEngine.renewToken(data.getToken()); + } + } + + @Override + public void onError(String error) { + + } + }); + } + //设置对方主播视图 private void setupRemoteVideo(int uid) { SurfaceView surfaceView = new SurfaceView(mContext); diff --git a/common/src/main/java/com/yunbao/common/utils/L.java b/common/src/main/java/com/yunbao/common/utils/L.java index 990473aed..7d4a2dc93 100644 --- a/common/src/main/java/com/yunbao/common/utils/L.java +++ b/common/src/main/java/com/yunbao/common/utils/L.java @@ -12,10 +12,18 @@ public class L { private final static String TAG = "log--->"; + private final static String TAG_SW = "log--->TAG_SW"; + public static void e(String s) { e(TAG, s); } + public static void eSw(String s) { + if (sDeBug) { + Log.e(TAG_SW, s); + } + } + public static void e(String tag, String s) { if (sDeBug) { Log.e(tag, s); diff --git a/live/src/main/AndroidManifest.xml b/live/src/main/AndroidManifest.xml index 6c664cb33..1af89a691 100644 --- a/live/src/main/AndroidManifest.xml +++ b/live/src/main/AndroidManifest.xml @@ -124,10 +124,6 @@ - - \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index d1ed67746..7b1526ba1 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -3,6 +3,7 @@ package com.yunbao.live.activity; import static com.blankj.utilcode.util.SnackbarUtils.dismiss; import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_DISABLE; import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_ENABLE; +import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK_RANDOM; import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_dr_pk_nub; @@ -101,6 +102,7 @@ import com.yunbao.live.interfaces.LiveFunctionClickListener; import com.yunbao.live.interfaces.LivePushListener; import com.yunbao.live.music.LiveMusicDialogFragment; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; +import com.yunbao.live.presenter.LiveLinkMicPkPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; import com.yunbao.live.socket.SocketRyChatUtil; @@ -1235,8 +1237,40 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (obj != null) { if (obj.getString("ispk").equals("0")) { + // TODO: 2024/4/11 发送IM消息 + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 1) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", pkUid) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); - IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain("g" + pkUid, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("tx", "发送成功"); + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "发送失败" + errorCode.getMessage()); + + } + }); + + /*IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { @Override public void onSuccess() { // ToastUtil.show("邀请 " + pkUid + " 发送成功"); @@ -1264,7 +1298,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl ToastUtil.show("invite " + pkUid + " failed:" + rtcErrorCode); } } - }); + });*/ + } else { ToastUtil.show("主播正在PK,稍後再試"); diff --git a/live/src/main/java/com/yunbao/live/activity/NewLiveActivity.java b/live/src/main/java/com/yunbao/live/activity/NewLiveActivity.java deleted file mode 100644 index 6dfb2bbf5..000000000 --- a/live/src/main/java/com/yunbao/live/activity/NewLiveActivity.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.yunbao.live.activity; - -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; - -import android.Manifest; -import android.content.pm.PackageManager; -import android.view.SurfaceView; -import android.widget.FrameLayout; - -import android.os.Bundle; - -import com.yunbao.common.manager.SWManager; -import com.yunbao.live.R; - -import io.agora.rtc2.ChannelMediaOptions; -import io.agora.rtc2.Constants; -import io.agora.rtc2.IRtcEngineEventHandler; -import io.agora.rtc2.RtcEngine; -import io.agora.rtc2.RtcEngineConfig; -import io.agora.rtc2.video.VideoCanvas; - - -public class NewLiveActivity extends AppCompatActivity { - private RtcEngine mRtcEngine; - - private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { - @Override - // 监听频道内的远端用户,获取用户的 uid 信息 - public void onUserJoined(int uid, int elapsed) { - runOnUiThread(new Runnable() { - @Override - public void run() { - // 获取 uid 后,设置远端视频视图 - setupRemoteVideo(uid); - } - }); - } - }; - - private void initializeAndJoinChannel() { - try { - // 创建 RtcEngineConfig 对象,并进行配置 - RtcEngineConfig config = new RtcEngineConfig(); - config.mContext = getBaseContext(); - config.mAppId = SWManager.shengwang_appId; - config.mEventHandler = mRtcEventHandler; - // 创建并初始化 RtcEngine - mRtcEngine = RtcEngine.create(config); - } catch (Exception e) { - throw new RuntimeException("Check the error."); - } - // 启用视频模块 - mRtcEngine.enableVideo(); - // 开启本地预览 - mRtcEngine.startPreview(); - - // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 - FrameLayout container = findViewById(R.id.local_video_view_container); - SurfaceView surfaceView = new SurfaceView(getBaseContext()); - container.addView(surfaceView); - // 将 SurfaceView 对象传入声网实时互动 SDK,设置本地视图 - mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT, 0)); - - // 创建 ChannelMediaOptions 对象,并进行配置 - ChannelMediaOptions options = new ChannelMediaOptions(); - // 根据场景将用户角色设置为 BROADCASTER (主播) 或 AUDIENCE (观众) - options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; - // 直播场景下,设置频道场景为 BROADCASTING (直播场景) - options.channelProfile = Constants.CHANNEL_PROFILE_LIVE_BROADCASTING; - - // 使用临时 Token 加入频道,自行指定用户 ID 并确保其在频道内的唯一性 - mRtcEngine.joinChannel(SWManager.shengwang_token, SWManager.shengwang_channelName, 0, options); - } - - private void setupRemoteVideo(int uid) { - FrameLayout container = findViewById(R.id.remote_video_view_container); - SurfaceView surfaceView = new SurfaceView(getBaseContext()); - surfaceView.setZOrderMediaOverlay(true); - container.addView(surfaceView); - // 将 SurfaceView 对象传入声网实时互动 SDK,设置远端视图 - mRtcEngine.setupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT, uid)); - } - - private static final int PERMISSION_REQ_ID = 22; - - // 获取体验实时音视频互动所需的录音、摄像头等权限 - private String[] getRequiredPermissions() { - // 判断 targetSDKVersion 31 及以上时所需的权限 - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { - return new String[]{ - Manifest.permission.RECORD_AUDIO, // 录音权限 - Manifest.permission.CAMERA, // 摄像头权限 - Manifest.permission.READ_PHONE_STATE, // 读取电话状态权限 - Manifest.permission.BLUETOOTH_CONNECT // 蓝牙连接权限 - }; - } else { - return new String[]{ - Manifest.permission.RECORD_AUDIO, - Manifest.permission.CAMERA - }; - } - } - - private boolean checkPermissions() { - for (String permission : getRequiredPermissions()) { - int permissionCheck = ContextCompat.checkSelfPermission(this, permission); - if (permissionCheck != PackageManager.PERMISSION_GRANTED) { - return false; - } - } - return true; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.acticity_new_live); - // 如果已经授权,则初始化 RtcEngine 并加入频道 - initializeAndJoinChannel(); - if (checkPermissions()) { - initializeAndJoinChannel(); - } else { - ActivityCompat.requestPermissions(this, getRequiredPermissions(), PERMISSION_REQ_ID); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - - // 停止本地视频预览 - mRtcEngine.stopPreview(); - - // 离开频道 - mRtcEngine.leaveChannel(); - } -} diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 60325da49..44abb11f6 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -52,6 +52,7 @@ import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.ScreenDimenUtil; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; @@ -683,9 +684,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void onLinkMicToPk(UserBean u) { EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar())); Log.e("eve", u.getId() + ""); + L.eSw("主播接受了主播的PK邀請"); /** * 加入副房间 - * * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 * * @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_` @@ -693,7 +694,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * @group 房间管理 */ RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); - RCRTCEngine.getInstance().joinOtherRoom(u.getId(), new IRCRTCResultDataCallback() { + /*RCRTCEngine.getInstance().joinOtherRoom(u.getId(), new IRCRTCResultDataCallback() { @Override public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); @@ -779,17 +780,18 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void onFailed(RTCErrorCode rtcErrorCode) { Log.i("ry", "11111加入其他房间失败 :" + rtcErrorCode.getReason()); } - }); + });*/ LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); LiveRyAnchorActivity.isDRPK = 1; ScreenDimenUtil util = ScreenDimenUtil.getInstance(); int mScreenWdith = util.getScreenWdith(); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); + /*LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); params.weight = 1; params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); livePushRyViewHolder.camera.setLayoutParams(params); livePushRyViewHolder.mPreView1.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); + livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);*/ + livePushRyViewHolder.setAnPkRtc(u);//设置对方主播视图 final SocketSendBean msg1 = new SocketSendBean() .param("_method_", SOCKET_LINK_MIC_PK) @@ -801,7 +803,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { .param("pkname", u.getUserNiceName()); msg1.create(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + /*Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain("g" + CommonAppConfig.getInstance().getUid(), conversationType, messageContent); @@ -821,7 +823,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { Log.e("tx", "发送失败" + errorCode.getMessage()); } - }); + });*/ } @@ -837,7 +839,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); LiveRyAnchorActivity.isDRPK = 1; - JSONObject msg1 = new JSONObject(); + /*JSONObject msg1 = new JSONObject(); msg1.put("uid", CommonAppConfig.getInstance().getUid()); msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb()); @@ -847,9 +849,47 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (bean != null && bean.isRandomPk()) { msg1.put("random_pk", bean.isRandomPk() ? 1 : 0); msg1.put("is_ladders", bean.getRankPkImgUrl()); - } + }*/ + + + /*---------------------------------------------------------------- */ + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 2) //回复PK申请 2 + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); System.out.println("PK回执 = " + msg1.toString()); - IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() { + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain("g" + bean.getId(), conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("tx", "发送成功"); + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "发送失败" + errorCode.getMessage()); + + } + }); + + // TODO: 2024/4/12 视图渲染 + livePushRyViewHolder.setAnPkRtc(bean); + + + /*IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() { @Override public void onSuccess() { RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback() { @@ -956,7 +996,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void onFailed(RTCErrorCode errorCode) { ToastUtil.show("接受失败"); } - }); + });*/ } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index 549c32778..780f934e2 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -1374,7 +1374,7 @@ public class SocketRyClient { private void processAnchorLinkMicPk(JSONObject map) { int action = map.getIntValue("action"); Log.i("Socket", "action = " + action + " json = " + map.toString()); - + L.eSw("处理主播与主播PK逻辑action = " + action + " json = " + map.toString()); switch (action) { case 1://收到对方主播PK回调 UserBean u = new UserBean(); diff --git a/live/src/main/java/com/yunbao/live/views/AbsRyLivePushViewHolder.java b/live/src/main/java/com/yunbao/live/views/AbsRyLivePushViewHolder.java index 2b1c7e4f2..ca097bcf6 100644 --- a/live/src/main/java/com/yunbao/live/views/AbsRyLivePushViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/AbsRyLivePushViewHolder.java @@ -11,6 +11,8 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import androidx.fragment.app.Fragment; + import com.yunbao.common.CommonAppConfig; import com.yunbao.common.utils.L; import com.yunbao.common.views.AbsViewHolder; @@ -30,7 +32,7 @@ public class AbsRyLivePushViewHolder extends AbsViewHolder implements ILivePushV protected ViewGroup mBigContainer; protected ViewGroup mSmallContainer; protected ViewGroup mLeftContainer; - protected ViewGroup mRightContainer; + protected FrameLayout mRightContainer; protected ViewGroup mPkContainer; public FrameLayout mPreView, mPreView1, cameraPreview3, dr1_preview, dr2_preview, dr3_preview, dr4_preview; public ImageView leave; @@ -59,7 +61,7 @@ public class AbsRyLivePushViewHolder extends AbsViewHolder implements ILivePushV mBigContainer = (ViewGroup) findViewById(R.id.big_container); mSmallContainer = (ViewGroup) findViewById(R.id.small_container); mLeftContainer = (ViewGroup) findViewById(R.id.left_container); - mRightContainer = (ViewGroup) findViewById(R.id.right_container); + mRightContainer = (FrameLayout) findViewById(R.id.right_container); mPkContainer = (ViewGroup) findViewById(R.id.pk_container); mCameraFront = true; String mBeautySdkType = CommonAppConfig.getInstance().getBeautySdkType(); diff --git a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java index 5863c3b91..dcca21861 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java @@ -308,7 +308,6 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl } private void setSelectClarity(int selectClarity) { - this.selectClarity = selectClarity; IMLoginManager.get(mContext).setSelectClarity(selectClarity); switch (selectClarity) { @@ -330,7 +329,6 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl } SWManager.get().setDimensions(selectClarity); - /*//設置開播分辨率 RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; int minRate = 200; diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 5c4b48ab3..204f15b59 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -31,6 +31,7 @@ import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; import com.lzy.okserver.OkDownload; +import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.dialog.LiveFontSizeSettingDialog; import com.yunbao.common.http.HttpCallback; @@ -100,6 +101,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public StyledPlayerView mVideoView; private FrameLayout playFrameLayout; + private FrameLayout playFrameLayout1; private View mLoading, mLoading2; private ImageView mCover; @@ -127,6 +129,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { RCRTCRoom rcrtcRoom; String purl, srcUrl; SWAuManager swAuManager; + String liveUid; public int getLandscape() { return landscape; @@ -137,9 +140,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { contexts = context; landscape = landscapes; Log.i("收收收", landscape + ""); + L.eSw("liveUid:" + liveUid); } - @Override protected int getLayoutId() { return R.layout.view_live_play_ksy; @@ -152,6 +155,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Bus.getOn(this); mRoot = (ViewGroup) findViewById(R.id.root); playFrameLayout = (FrameLayout) findViewById(R.id.playView); + playFrameLayout1 = (FrameLayout) findViewById(R.id.playView1); mSmallContainer = (ViewGroup) findViewById(R.id.small_container); mLeftContainer = (ViewGroup) findViewById(R.id.left_container); mRightContainer = (ViewGroup) findViewById(R.id.right_container); @@ -174,15 +178,21 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mPlayer.setMainView(mVideoView); mPlayer.setListener(new ExoPlayerListener()); + debugView = new TextView(mContext); + debugView.setBackgroundColor(Color.WHITE); + } + + public void initSwEngine(String liveUid) { + this.liveUid = liveUid; swAuManager = SWAuManager.get(); swAuManager.setAudienceContainer(playFrameLayout); swAuManager.initRtcEngine((Activity) mContext); - swAuManager.setupRemoteVideo(11); - swAuManager.joinRoom("9999", SWAuManager.shengwang_token, SWAuManager.shengwang_channelName); - - debugView = new TextView(mContext); - debugView.setBackgroundColor(Color.WHITE); + swAuManager.setupRemoteVideo(Integer.parseInt(liveUid)); + swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); + //测试-模拟PK场景,加入第二个主播视图 + swAuManager.setPkContainer1(playFrameLayout1); + swAuManager.joinExRoomEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); } @Override diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 0e7d75410..aeb0a5f8c 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -46,6 +46,7 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.RandomPkManager; +import com.yunbao.common.manager.SWAuManager; import com.yunbao.common.manager.SWManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; @@ -503,7 +504,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } }); - HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK") .params("uid", CommonAppConfig.getInstance().getUid()) .params("addtime", "1") @@ -772,23 +772,36 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX */ private void initRtcEngine() { swManager = SWManager.get(); - swManager.setAnchorContainer(mPreView); - swManager.initRtcEngine((Activity) mContext, "11"); + swManager.setAnchorContainer((FrameLayout) mLeftContainer); + swManager.initRtcEngine((Activity) mContext, CommonAppConfig.getInstance().getUid()); swManager.setOnRtcEngineListener(new SWManager.onRtcEngineListener() { @Override public void onOpenSuccess(String channel, int uid) { //开播成功 - + L.eSw("开播成功"); } }); } + public void setAnPkRtc(UserBean u) { + if (swManager != null && u != null) { + L.eSw("设置对方主播的视图setAnPkRtc" + u); + + //将自己的渲染视图设置到 leftContainer + //swManager.updateMyVideoView((FrameLayout) mLeftContainer,SWAuManager.getChannelName(CommonAppConfig.getInstance().getUid())); + + //设置对方主播的渲染视图 设置到 rightContainer + swManager.setPkContainer1(mRightContainer); + swManager.joinExRoomEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,u.getId(), SWAuManager.getChannelName(u.getId())); + } + } + @Override public void changeToLeft() { if (mPreView != null) { - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mPreView.getLayoutParams(); + LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mPreView.getLayoutParams(); params.width = mPreView.getWidth() / 2; - params.height = DpUtil.dp2px(250); + params.height = DpUtil.dp2px(mPreView.getHeight()); params.topMargin = DpUtil.dp2px(130); camera.setLayoutParams(params); } @@ -844,7 +857,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX ToastUtil.show(mContext.getString(R.string.live_open_flash)); return; } - } /** @@ -856,7 +868,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void startPush(String pushUrl) { //开播成功,创建频道 if (swManager != null) { - swManager.createRoom(SWManager.shengwang_token, SWManager.shengwang_channelName); + swManager.createRoom(CommonAppConfig.SWToken, CommonAppConfig.getChannelName()); } if (rcrtcLiveInfo != null) { rcrtcLiveInfo.addPublishStreamUrl(pushUrl, new IRCRTCResultDataCallback() { diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 801bab514..9554d80c4 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -365,6 +365,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe liveHandler.removeCallbacks(loadTimeoutRunnableGone); if (mLivePlayViewHolder == null) { mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); + mLivePlayViewHolder.initSwEngine(mLiveBean.getUid()); mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager()); mLiveAudienceViewHolder = new LiveAudienceViewHolder(mContext, mContainer); mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, mLiveAudienceViewHolder.getContentView()); diff --git a/live/src/main/res/layout/acticity_new_live.xml b/live/src/main/res/layout/acticity_new_live.xml deleted file mode 100644 index 886d43dcd..000000000 --- a/live/src/main/res/layout/acticity_new_live.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index b602c6757..4eea26aeb 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -2,23 +2,39 @@ + android:layout_height="match_parent" + android:animateLayoutChanges="true"> + app:surface_type="texture_view" + app:use_controller="false" /> - + android:layout_height="300dp" + android:layout_centerVertical="true" + android:orientation="horizontal"> + + + + + + + + - - - @@ -195,7 +195,6 @@ android:textSize="13sp" android:visibility="gone" /> - - () { + @Override + public void onSuccess(SwTokenModel data) { + CommonAppConfig.SWToken = data.getToken(); + } + + @Override + public void onError(String error) { + + } + }); } /** @@ -798,18 +817,17 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene private void showStartDialog() { - if (isReady == true) { - MainStartDialogFragment dialogFragment = new MainStartDialogFragment(); - dialogFragment.setMainStartChooseCallback(true, this); - dialogFragment.show(getSupportFragmentManager(), "MainStartDialogFragment"); - } else { - ToastUtil.show("正在初始化,請稍等...."); - } + if (isReady == true) { + MainStartDialogFragment dialogFragment = new MainStartDialogFragment(); + dialogFragment.setMainStartChooseCallback(true, this); + dialogFragment.show(getSupportFragmentManager(), "MainStartDialogFragment"); + } else { + ToastUtil.show("正在初始化,請稍等...."); + } } - /** * 检查版本更新 */ From 0db8eefbe6ac3e35a591016f95ce7f7b5b89a8e0 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 13 Apr 2024 18:19:14 +0800 Subject: [PATCH 03/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/common/bean/UserBean.java | 60 +++++ .../com/yunbao/common/manager/SWManager.java | 91 +++++-- .../live/activity/LiveRyAnchorActivity.java | 2 +- .../presenter/LiveRyLinkMicPkPresenter.java | 14 +- .../yunbao/live/socket/SocketRyClient.java | 253 +++++------------- .../live/views/LivePushRyViewHolder.java | 47 ++-- .../src/main/res/layout/view_live_push_ry.xml | 8 +- 7 files changed, 218 insertions(+), 257 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/bean/UserBean.java b/common/src/main/java/com/yunbao/common/bean/UserBean.java index aa44fc257..6290b76f2 100644 --- a/common/src/main/java/com/yunbao/common/bean/UserBean.java +++ b/common/src/main/java/com/yunbao/common/bean/UserBean.java @@ -898,6 +898,66 @@ public class UserBean implements Parcelable { this.bubble = bubble; } } + + @Override + public String toString() { + return "UserBean{" + + "id='" + id + '\'' + + ", userNiceName='" + userNiceName + '\'' + + ", avatar='" + avatar + '\'' + + ", avatarThumb='" + avatarThumb + '\'' + + ", sex=" + sex + + ", signature='" + signature + '\'' + + ", coin='" + coin + '\'' + + ", gold='" + gold + '\'' + + ", votes='" + votes + '\'' + + ", consumption='" + consumption + '\'' + + ", votestotal='" + votestotal + '\'' + + ", province='" + province + '\'' + + ", city='" + city + '\'' + + ", location='" + location + '\'' + + ", birthday='" + birthday + '\'' + + ", level=" + level + + ", levelAnchor=" + levelAnchor + + ", lives=" + lives + + ", follows=" + follows + + ", fans=" + fans + + ", vip=" + vip + + ", liang=" + liang + + ", car=" + car + + ", medal_level=" + medal_level + + ", medal_name='" + medal_name + '\'' + + ", Dress=" + Dress + + ", noble_id='" + noble_id + '\'' + + ", yuanbao='" + yuanbao + '\'' + + ", noble_name='" + noble_name + '\'' + + ", islive='" + islive + '\'' + + ", medal_no_display_src='" + medal_no_display_src + '\'' + + ", hot_num='" + hot_num + '\'' + + ", goodnum='" + goodnum + '\'' + + ", fans_pic='" + fans_pic + '\'' + + ", gifticon='" + gifticon + '\'' + + ", department_name='" + department_name + '\'' + + ", token_rong='" + token_rong + '\'' + + ", noble_end_time='" + noble_end_time + '\'' + + ", slide='" + slide + '\'' + + ", users_type='" + users_type + '\'' + + ", is_bind='" + is_bind + '\'' + + ", mobile='" + mobile + '\'' + + ", front_task='" + front_task + '\'' + + ", is_admin='" + is_admin + '\'' + + ", praise=" + praise + + ", isHide=" + isHide + + ", randomPk=" + randomPk + + ", mRankPkImgUrl='" + mRankPkImgUrl + '\'' + + ", user_info_complete=" + user_info_complete + + ", fansLevel=" + fansLevel + + ", typeMic=" + typeMic + + ", isMicList=" + isMicList + + ", isRequest=" + isRequest + + ", fansEnterRoomUrl='" + fansEnterRoomUrl + '\'' + + '}'; + } } diff --git a/common/src/main/java/com/yunbao/common/manager/SWManager.java b/common/src/main/java/com/yunbao/common/manager/SWManager.java index 5dfeaf474..2d17287ea 100644 --- a/common/src/main/java/com/yunbao/common/manager/SWManager.java +++ b/common/src/main/java/com/yunbao/common/manager/SWManager.java @@ -19,7 +19,6 @@ import io.agora.rtc2.ChannelMediaOptions; import io.agora.rtc2.Constants; import io.agora.rtc2.IRtcEngineEventHandler; import io.agora.rtc2.RtcConnection; -import io.agora.rtc2.RtcEngine; import io.agora.rtc2.RtcEngineConfig; import io.agora.rtc2.RtcEngineEx; import io.agora.rtc2.video.VideoCanvas; @@ -55,7 +54,6 @@ public class SWManager extends BaseCacheManager { /** * 获取单列 - * * @return */ public static SWManager get() { @@ -117,6 +115,10 @@ public class SWManager extends BaseCacheManager { mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); } + /** + * 设置清晰度 + * @param selectClarity + */ public void setDimensions(int selectClarity) { if (cfg != null && mRtcEngine != null) { switch (selectClarity) { @@ -135,9 +137,9 @@ public class SWManager extends BaseCacheManager { } /** - * 创建房间 + * 创建直播间 */ - public void createRoom(String token, String channelName) { + public void createChannel(String token, String channelName) { ChannelMediaOptions options = new ChannelMediaOptions(); // 设置角色 BROADCASTER (主播) 或 AUDIENCE (观众) options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; @@ -145,23 +147,28 @@ public class SWManager extends BaseCacheManager { mRtcEngine.joinChannel(token, channelName, uid, options); } - public void updateMyVideoView(FrameLayout frameLayout, String channelName) { - mRtcEngine.setupRemoteVideoEx(null, null); - - RtcConnection rtcConnection = new RtcConnection(); - rtcConnection.channelId = channelName; //自己频道名称 - rtcConnection.localUid = uid;//自己的ID - + /** + * 更新主播视图 + * @param frameLayout + */ + public void updateMyChannelView(FrameLayout frameLayout) { + mRtcEngine.setupLocalVideo(null); SurfaceView surfaceView = new SurfaceView(mContext); surfaceView.setZOrderMediaOverlay(true); frameLayout.addView(surfaceView); VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid); - mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); + mRtcEngine.setupLocalVideo(videoCanvas); } - - public void joinExRoomEx(String strUid, String token,String toUid, String channelName) { + /** + * PK-加入对方主播直播间 + * @param strUid + * @param token + * @param toUid + * @param channelName + */ + public void joinChannelEx(String strUid, String token, String toUid, String channelName) { int tempUid; if (StringUtil.isEmpty(strUid)) { tempUid = 0; @@ -199,6 +206,11 @@ public class SWManager extends BaseCacheManager { }); } + @Override + public void onLeaveChannel(RtcStats stats) { + super.onLeaveChannel(stats); + } + @Override public void onError(int err) { super.onError(err); @@ -207,6 +219,30 @@ public class SWManager extends BaseCacheManager { }); } + /** + * 退出对方直播间 + * @param uid 自己的ID + * @param liveUid 对方直播间号 + */ + public void exitChannelToUid(int uid, String liveUid){ + RtcConnection rtcConnection = new RtcConnection(); + rtcConnection.channelId = getChannelName(liveUid); //對方主播的頻道 + rtcConnection.localUid = uid;//自己的ID + mRtcEngine.leaveChannelEx(rtcConnection); + } + + //设置对方主播视图 + 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; + } //远程监听 private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { @Override @@ -224,6 +260,7 @@ public class SWManager extends BaseCacheManager { @Override public void onJoinChannelSuccess(String channel, int uid, int elapsed) { super.onJoinChannelSuccess(channel, uid, elapsed); + L.eSw("onJoinChannelSuccess 加入频道:channel"+channel+" uid:"+uid+" elapsed:"+elapsed); if (onRtcEngineListener != null) { onRtcEngineListener.onOpenSuccess(channel, uid); } @@ -232,20 +269,29 @@ public class SWManager extends BaseCacheManager { @Override public void onError(int err) { super.onError(err); + L.eSw("onError 错误码:"+err); ToastUtil.show("onError:" + err); } @Override public void onTokenPrivilegeWillExpire(String token) { super.onTokenPrivilegeWillExpire(token); + L.eSw("onTokenPrivilegeWillExpire_Token 即将失效"); refreshToken(); } @Override public void onRequestToken() { super.onRequestToken(); + L.eSw("onRequestToken_Token失效"); refreshToken(); } + + @Override + public void onLeaveChannel(RtcStats stats) { + super.onLeaveChannel(stats); + L.eSw("onLeaveChannel退出頻道"); + } }; private void refreshToken() { @@ -255,6 +301,7 @@ public class SWManager extends BaseCacheManager { if (mRtcEngine != null) { mRtcEngine.renewToken(data.getToken()); } + L.eSw("refreshToken_重新获取Token成功"); } @Override @@ -264,19 +311,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; - } - public interface onRtcEngineListener { void onOpenSuccess(String channel, int uid); } @@ -296,4 +330,7 @@ public class SWManager extends BaseCacheManager { public void setLinkUserContainer(FrameLayout linkUserContainer) { this.linkUserContainer = linkUserContainer; } + public static String getChannelName(String liveUid) { + return CommonAppConfig.SWChannelPrefix + liveUid; + } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 7b1526ba1..6154ec5ad 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -1476,7 +1476,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl @Override public void onLinkMicToPk(String uid, String pkhead, String pkname) { - + L.eSw("onLinkMicToPkonLinkMicToPkonLinkMicToPk"); } @Override diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 44abb11f6..2fd16e034 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -887,7 +887,17 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { // TODO: 2024/4/12 视图渲染 livePushRyViewHolder.setAnPkRtc(bean); - + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); + LiveRyAnchorActivity.isDRPK = 1; + LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); + SocketRyLinkMicPkUtil.linkMicPkAccept(mSocketRyClient, mApplyUid, mApplyUrl, mApplyNmae); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid)); + onLinkMicPkStart(mApplyUid, 2); + } + }); /*IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() { @Override @@ -2294,6 +2304,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mPkUid = pkUid; mApplyUid = null; mApplyStream = null; + if (mLiveLinkMicPkViewHolder == null) { mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); mLiveLinkMicPkViewHolder.addToParent(); @@ -2301,7 +2312,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).getmLivePlayViewHolder().setPkview(); } - } mLiveLinkMicPkViewHolder.startAnim(); EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(pkUid)); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index 780f934e2..75b078f2e 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -204,10 +204,7 @@ public class SocketRyClient { EventBus.getDefault().post("UsertoRY"); } else if (actions == 5) { JSONObject mic_data = map.getJSONObject("ct"); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_MIC_LIST) - .setObject(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(), LinkMicUserBean.class)) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_MIC_LIST).setObject(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(), LinkMicUserBean.class))); MicedUserManager.get().upDataMicUserList(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(), LinkMicUserBean.class)); } else if (actions == 6) { if (WordUtil.isNewZh()) { @@ -216,9 +213,7 @@ public class SocketRyClient { ToastUtil.show("The host has disabled the voice connection function"); } EventBus.getDefault().post("endMic"); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CLOSE) - .setObject(map.toJavaObject(LinkMicUserBean.class))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CLOSE).setObject(map.toJavaObject(LinkMicUserBean.class))); } else if (actions == 8) { if (WordUtil.isNewZh()) { ToastUtil.show("您已被移出多人語音連麥"); @@ -227,24 +222,16 @@ public class SocketRyClient { } EventBus.getDefault().post("endMic"); } else if (actions == 3) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC) - .setObject(map.toJavaObject(LinkMicUserBean.class)) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC).setObject(map.toJavaObject(LinkMicUserBean.class))); MicUserManager.get().upDataMicUser(map); } else if (actions == 7) {//取消连麦 - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CANCEL) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CANCEL)); MicUserManager.get().removeMiscUser(map); } break; case Constants.UP_USER_LIST: mListener.onUpUserList(map.getJSONObject("ct")); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_AUDIENCE_LIST) - .setObject(JSON.parseArray(map.getJSONObject("ct").getString("userlist"), LiveUserGiftBean.class)) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_AUDIENCE_LIST).setObject(JSON.parseArray(map.getJSONObject("ct").getString("userlist"), LiveUserGiftBean.class))); break; case Constants.CARD: // LiveLinkMicPresenter.setHD(map.getString("ct")); @@ -263,9 +250,7 @@ public class SocketRyClient { } else { if (!WordUtil.isNewZh() && map.getString("ct").contains("退出比賽") && map.getString("ct").contains("獲得勝利")) { String ctTmp = map.getString("ct"); - ctTmp = ctTmp.replace("由於", "Due to") - .replace("退出比賽", "withdrawing from the competition") - .replace("獲得勝利", "won"); + ctTmp = ctTmp.replace("由於", "Due to").replace("退出比賽", "withdrawing from the competition").replace("獲得勝利", "won"); map.put("ct", ctTmp); } systemChatMessage2(map.getString("ct")); @@ -333,16 +318,10 @@ public class SocketRyClient { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); } // LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, map.getIntValue("drpk_time")); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE) - .setPkScores(map.getJSONArray("userlist")) - .setUid(mLiveUid) - .setTime(map.getIntValue("drpk_time"))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE).setPkScores(map.getJSONArray("userlist")).setUid(mLiveUid).setTime(map.getIntValue("drpk_time"))); if (livePushRyViewHolder == null) { // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); } @@ -352,14 +331,11 @@ public class SocketRyClient { if (LiveRyAnchorActivity.mLiveAnchorViewHolder != null) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); params.topMargin = 0; - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LEAVE_DR_ROOM)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LEAVE_DR_ROOM)); isDRPK = 0; } else { // LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview(); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW)); } //創建了多人房間 @@ -367,16 +343,12 @@ public class SocketRyClient { /* if (LiveAudienceActivity.getmLivePlayViewHolder() != null) { LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); }*/ - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); isDRPK = 1; } else if (action3 == 10) { if (!map.getString("uid").equals(CommonAppConfig.getInstance().getUid())) { // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); } } @@ -413,39 +385,19 @@ public class SocketRyClient { } else { boxTypeName = WordUtil.isNewZh() ? "PD盲盒" : "PD blind box"; } - AllServerNotifyEvent allServerNotifyEvent - = new AllServerNotifyEvent() - .setBlindBoxId(map.getString("blind_box_id")) - .setBoxType(boxType) - .setBoxTypeName(boxTypeName) - .setDressName(WordUtil.isNewZh() ? map.getString("dress_name") : TextUtils.isEmpty(map.getString("dress_nameen")) ? map.getString("dress_name") : map.getString("dress_nameen")) - .setGiftNotification(map.getString("gift_notification")) - .setGiftName(WordUtil.isNewZh() ? mCt.getString("giftname") : mCt.getString("giftnameen")) - .setUserNiceName(map.getString("uname")) - .setGiftIcon(map.getString("gifticon")) - .setAnchorName(map.getString("ancherName")) - .setDisplaySrc(map.getString("display_src")); + AllServerNotifyEvent allServerNotifyEvent = new AllServerNotifyEvent().setBlindBoxId(map.getString("blind_box_id")).setBoxType(boxType).setBoxTypeName(boxTypeName).setDressName(WordUtil.isNewZh() ? map.getString("dress_name") : TextUtils.isEmpty(map.getString("dress_nameen")) ? map.getString("dress_name") : map.getString("dress_nameen")).setGiftNotification(map.getString("gift_notification")).setGiftName(WordUtil.isNewZh() ? mCt.getString("giftname") : mCt.getString("giftnameen")).setUserNiceName(map.getString("uname")).setGiftIcon(map.getString("gifticon")).setAnchorName(map.getString("ancherName")).setDisplaySrc(map.getString("display_src")); Log.e("AllServerNotifyEvent", allServerNotifyEvent.toString()); Log.e("AllServerNotifyEvent", map.toJSONString()); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX) - .setAllServerNotifyEvent(allServerNotifyEvent)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX).setAllServerNotifyEvent(allServerNotifyEvent)); } else if (action2 == 89) {//红包 JSONObject mCt = map.getJSONObject("ct"); - AllServerNotifyEvent allServerNotifyEvent - = new AllServerNotifyEvent() - .setUserNiceName(mCt.getString("user_nicename")) - .setGiftName(WordUtil.isNewZh() ? map.getString("giftname") : map.getString("giftname_en")) - .setGiftIcon(mCt.getString("gifticon")) - .setRedPacket(true); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX) - .setAllServerNotifyEvent(allServerNotifyEvent)); + AllServerNotifyEvent allServerNotifyEvent = new AllServerNotifyEvent().setUserNiceName(mCt.getString("user_nicename")).setGiftName(WordUtil.isNewZh() ? map.getString("giftname") : map.getString("giftname_en")).setGiftIcon(mCt.getString("gifticon")).setRedPacket(true); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX).setAllServerNotifyEvent(allServerNotifyEvent)); } else if (action2 == 90) { NewAllServerNotifyGuardEvent notifyGuardEvent = GsonUtils.fromJson(map.toString(), NewAllServerNotifyGuardEvent.class); Bus.get().post(notifyGuardEvent); buyGuardInSameRoom(map); - }else if (action2==91){ + } else if (action2 == 91) { AllServerNotifyFFGGGDJANEvent notifyFFGGGDJANEvent = GsonUtils.fromJson(map.toString(), AllServerNotifyFFGGGDJANEvent.class); Bus.get().post(notifyFFGGGDJANEvent); } @@ -473,12 +425,7 @@ public class SocketRyClient { mListener.onAnchorInvalid(); } //主播强制下播 - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_END) - .setVotes(map.getString("votes")) - .setLength(map.getString("length")) - .setNums(map.getIntValue("nums")) - .setUname(map.getString("uname"))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_END).setVotes(map.getString("votes")).setLength(map.getString("length")).setNums(map.getIntValue("nums")).setUname(map.getString("uname"))); break; case Constants.SOCKET_CHANGE_LIVE://主播切换计时收费类型 mListener.onChangeTimeCharge(map.getIntValue("type_val")); @@ -619,9 +566,7 @@ public class SocketRyClient { List msg = model.getMsg(); if (msg.size() > 0) { // EventBus.getDefault().post(msg.get(0)); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.TRUMPET_NOTIFY) - .setMsgModel(msg.get(0))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.TRUMPET_NOTIFY).setMsgModel(msg.get(0))); } break; case Constants.RECOMMEND_CARD_NOTIFY://推荐卡消息通知 @@ -629,9 +574,7 @@ public class SocketRyClient { List recommendCardNotifyMsg = recommendCardNotifyModel.getMsg(); if (recommendCardNotifyMsg.size() > 0) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.RECOMMEND_CARD_NOTIFY) - .setMsgModel(recommendCardNotifyMsg.get(0))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.RECOMMEND_CARD_NOTIFY).setMsgModel(recommendCardNotifyMsg.get(0))); } break; case Constants.STAR_CHALLENGE_UPDATE://星级助力 @@ -648,29 +591,21 @@ public class SocketRyClient { case Constants.AI_AUTOMATIC_SPEECH_LIVE: //{"name_color":"#f19ec2","ai_name":"助手小小P","content":"@1 ","user_name":"1","icon":"https://downs.yaoulive.com/xzs_tab.png","system_bubble":"https://downs.yaoulive.com/xzs_qipao.9.png"} AiAutomaticSpeechModel aiAutomaticSpeechModel = GsonUtils.fromJson(map.getString("ct"), AiAutomaticSpeechModel.class); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.AI_AUTOMATIC_SPEECH) - .setAiAutomaticSpeechModel(aiAutomaticSpeechModel)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.AI_AUTOMATIC_SPEECH).setAiAutomaticSpeechModel(aiAutomaticSpeechModel)); break; case Constants.STAR_CHALLENGE_UPGRADE_NOTIFY: SocketModel starChallengeUpgradeNotify = GsonUtils.fromJson(socketMsg, SocketModel.class); List starChallengeUpgradeNotifyMsg = starChallengeUpgradeNotify.getMsg(); if (starChallengeUpgradeNotifyMsg.size() > 0) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.STAR_CHALLENGE_UPGRADE_NOTIFY) - .setMsgModel(starChallengeUpgradeNotifyMsg.get(0))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.STAR_CHALLENGE_UPGRADE_NOTIFY).setMsgModel(starChallengeUpgradeNotifyMsg.get(0))); } break; case Constants.LuckyAngel: - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LUCKY_ANGEL) - .setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LUCKY_ANGEL).setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); break; case Constants.Lucky100Check: - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LUCKY_100_CHECK) - .setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LUCKY_100_CHECK).setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); break; case Constants.PK_RANK_UPDATE: Log.i("PK排位", map.toString()); @@ -680,117 +615,68 @@ public class SocketRyClient { pkRankBean.setName(item.getString("new_rank_name")); pkRankBean.setImg(item.getString("new_rank_img")); pkRankBean.setNewRankNameEn(item.getString("new_rank_name_en")); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_UPDATE) - .setObject(pkRankBean)); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_UPDATE).setObject(pkRankBean)); break; case Constants.CUSTOM_FULL_SERVICE_NOTIFY: Log.e("全服通知", map.toString()); CustomFullServiceNotifyEvent customFullServiceNotifyEvent = GsonUtils.fromJson(map.toString(), CustomFullServiceNotifyEvent.class); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.CUSTOM_FULL_SERVICE_NOTIFY) - .setCustomFullServiceNotifyEvent(customFullServiceNotifyEvent)); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.CUSTOM_FULL_SERVICE_NOTIFY).setCustomFullServiceNotifyEvent(customFullServiceNotifyEvent)); break; case Constants.XYD_COMPLETE: // xydComplete(map); XydCompleteModel xydCompleteModel = GsonUtils.fromJson(map.toString(), XydCompleteModel.class); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.XYD_COMPLETE) - .setXydCompleteModel(xydCompleteModel) - .setLiveReceiveGiftBean(JSON.parseObject(map.toString(), LiveReceiveGiftBean.class))); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.XYD_COMPLETE).setXydCompleteModel(xydCompleteModel).setLiveReceiveGiftBean(JSON.parseObject(map.toString(), LiveReceiveGiftBean.class))); break; case "GuardSpecialEffect": LiveReceiveGiftBean giftBean = JSON.parseObject(map.toString(), LiveReceiveGiftBean.class); giftBean.setMedal_name(map.getString("medal_name")); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GuardSpecialEffect) - .setLiveReceiveGiftBean(giftBean)); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GuardSpecialEffect).setLiveReceiveGiftBean(giftBean)); break; case Constants.WISH_LIST_PROGRESS: StringBuffer conString = new StringBuffer(); conString.append(WordUtil.isNewZh() ? map.getString("msg") : map.getString("msg_en")); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.WISH_LIST_PROGRESS) - .setWishListProgress(new WishModel() - .setWishlistProgress(map.getString("wishlist_progress")) - .setWishlistIcon(map.getString("wishlist_icon")) - .setWishlistName(map.getString("wishlist_name")) - .setWishlistNum(map.getString("wishlist_num")) - .setGiftType(map.getInteger("giftId")) - .setLuid(conString.toString())).setUname(map.getString("userName")).setLiveType(Integer.parseInt(map.getString("level")))); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.WISH_LIST_PROGRESS).setWishListProgress(new WishModel().setWishlistProgress(map.getString("wishlist_progress")).setWishlistIcon(map.getString("wishlist_icon")).setWishlistName(map.getString("wishlist_name")).setWishlistNum(map.getString("wishlist_num")).setGiftType(map.getInteger("giftId")).setLuid(conString.toString())).setUname(map.getString("userName")).setLiveType(Integer.parseInt(map.getString("level")))); break; case Constants.LIVE_VOTE_CREATE: - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.VOTE_CREATE) - .setObject(map) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.VOTE_CREATE).setObject(map)); break; case Constants.LIVE_VOTE_END: - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.VOTE_END) - .setObject(map) - ); - EventBus.getDefault().post(new LiveAnchorEvent() - .setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_END) - .setObject(map) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.VOTE_END).setObject(map)); + EventBus.getDefault().post(new LiveAnchorEvent().setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_END).setObject(map)); break; case Constants.LIVE_VOTE_UPDATE: //通知给观众 - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.VOTE_UPDATE) - .setObject(map) - ); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.VOTE_UPDATE).setObject(map)); //通知给主播 - EventBus.getDefault().post(new LiveAnchorEvent() - .setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_UPDATE) - .setObject(map) - ); + EventBus.getDefault().post(new LiveAnchorEvent().setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_UPDATE).setObject(map)); break; case Constants.LIVE_PK_END: - mListener.onEndPk(map.getLong("uid"), - map.getLong("pkuid"), - map.getLong("uid_score"), - map.getLong("pkuid_score"), - JSONObject.parseObject(map.getJSONObject("ct").getJSONObject("pk_top_users").toJSONString(), LivePKUserListBean.class) - ); + mListener.onEndPk(map.getLong("uid"), map.getLong("pkuid"), map.getLong("uid_score"), map.getLong("pkuid_score"), JSONObject.parseObject(map.getJSONObject("ct").getJSONObject("pk_top_users").toJSONString(), LivePKUserListBean.class)); break; case Constants.RED_PACKET: RedPacketModel redPacketModel = GsonUtils.fromJson(map.toString(), RedPacketModel.class); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET) - .setRedPacketModel(redPacketModel)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET).setRedPacketModel(redPacketModel)); break; case Constants.RED_PACKET_SUPER_JACKPOT: RedPacketInfoModel redPacketInfoModel = GsonUtils.fromJson(map.toString(), RedPacketInfoModel.class); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET_SUPER_JACKPOT) - .setRedPacketInfoModel(redPacketInfoModel)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET_SUPER_JACKPOT).setRedPacketInfoModel(redPacketInfoModel)); break; case "GiftWallIlluminate": Log.e("GiftWallIlluminate", map.toString()); - Bus.get().post(new GiftWallIlluminateEvent() - .setNewNumber(map.getInteger("new_number")) - .setMaxNumber(map.getInteger("max_number"))); + Bus.get().post(new GiftWallIlluminateEvent().setNewNumber(map.getInteger("new_number")).setMaxNumber(map.getInteger("max_number"))); break; case SOCKET_LIVE_MSG_TO_USER: sendToUserMsg(map); break; case "SudGameCreateRoom": - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SUD_GAME_CREATE_ROOM) - .setAvatar(WordUtil.isNewZh() ? map.getString("sud_game_name") : map.getString("sud_game_name_en")) - .setCreateSudRoomModel(GsonUtils.fromJson(map.toString(), SudGameDateModel.class))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SUD_GAME_CREATE_ROOM).setAvatar(WordUtil.isNewZh() ? map.getString("sud_game_name") : map.getString("sud_game_name_en")).setCreateSudRoomModel(GsonUtils.fromJson(map.toString(), SudGameDateModel.class))); break; case "sendQuickGift": SendQuickGiftModel sendQuickGiftModel = GsonUtils.fromJson(map.toString(), SendQuickGiftModel.class); StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append(sendQuickGiftModel.getUserNicename()) - .append(WordUtil.isNewZh() ? " 送出了 " : " sent ") - .append(sendQuickGiftModel.getQuickGiftNumber()) - .append(WordUtil.isNewZh() ? " 個小PD " : " small pandas "); + stringBuffer.append(sendQuickGiftModel.getUserNicename()).append(WordUtil.isNewZh() ? " 送出了 " : " sent ").append(sendQuickGiftModel.getQuickGiftNumber()).append(WordUtil.isNewZh() ? " 個小PD " : " small pandas "); systemChatMessage2(stringBuffer.toString()); Bus.get().post(new QuickGiftingEvent().setHotNum(sendQuickGiftModel.getHotNum())); break; @@ -805,9 +691,7 @@ public class SocketRyClient { pkRankBean.setRedVal(item.getString("uid_win_continuity")); pkRankBean.setPkTopImgUrl(item.getString("pktt_img")); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_START) - .setObject(pkRankBean)); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_START).setObject(pkRankBean)); break; case "guardMaturityDateRemind": GuardMaturityDateRemindModel maturityDateRemindModel = GsonUtils.fromJson(map.toString(), GuardMaturityDateRemindModel.class); @@ -1059,8 +943,7 @@ public class SocketRyClient { FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); u.setFansLevel(obj.getIntValue("medal_level")); u.setFansEnterRoomUrl(obj.getString("medal_backgroup_thumb")); - if (fansMedalBean != null) - chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); mListener.onEnterRoom(new LiveEnterRoomBean(u, chatBean)); } } @@ -1092,8 +975,7 @@ public class SocketRyClient { //增加粉丝徽章信息 chatBean.setMedalNmae(map.getString("medal_name")); FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); - if (fansMedalBean != null) - chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); //聊天列表显示 玩家名 送 1 个 礼物名 if (CommonAppContext.lang.equals("chinese")) { @@ -1118,8 +1000,7 @@ public class SocketRyClient { mListener.onSendGift(receiveGiftBean, null); } //同一个直播间时才刷新pk - if (mLiveUid.equals(map.getString("pkuid1")) || - mLiveUid.equals(map.getString("pkuid2"))) { + if (mLiveUid.equals(map.getString("pkuid1")) || mLiveUid.equals(map.getString("pkuid2"))) { mListener.onSendGiftPk(map.getLongValue("pktotal2"), map.getLongValue("pktotal1"), livePKUserListBean); } } @@ -1215,8 +1096,7 @@ public class SocketRyClient { //增加粉丝徽章信息 chatBean.setMedalNmae(map.getString("medal_name")); FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); - if (fansMedalBean != null) - chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); receiveGiftBean.setLiveChatBean(chatBean); @@ -1244,11 +1124,7 @@ public class SocketRyClient { } if (map.getIntValue("drpk_status") == 1) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE) - .setPkScores(map.getJSONArray("userlist")) - .setUid(mLiveUid) - .setTime(0)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE).setPkScores(map.getJSONArray("userlist")).setUid(mLiveUid).setTime(0)); // LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, 0); } @@ -1387,6 +1263,11 @@ public class SocketRyClient { RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); mListener.onLinkMicToPk(map.getString("uid"), map.getString("pkhead"), map.getString("pkname")); mListener.onLinkMicPkStart(map.getString("uid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); + if (livePushRyViewHolder != null) { + UserBean userBean = new UserBean(); + userBean.setId(map.getString("uid")); + livePushRyViewHolder.setAnPkRtc(userBean); + } break; case 3://对方主播拒绝PK的回调 RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); @@ -1399,30 +1280,18 @@ public class SocketRyClient { break; case 5://PK时候断开连麦的回调 // if (rtcRoom != null) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.DISCONNEXT_PK_TIME)); - RCRTCEngine.getInstance().leaveOtherRoom(map.getString("pkuid"), true, new IRCRTCResultCallback() { + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.DISCONNEXT_PK_TIME)); + //断开连麦 + HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout").execute(new HttpCallback() { @Override - public void onSuccess() { - Log.e("ry", map.getString("pkuid") + "退出多人成功a as"); - - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", map.getString("pkuid") + "退asa出多人失败" + rtcErrorCode); + public void onSuccess(int code, String msg, String[] info) { } }); - //断开连麦 - HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - } - }); // } + if (livePushRyViewHolder != null) { + livePushRyViewHolder.onLinkMicAnchorClose(); + } mListener.onLinkMicPkClose(1); if (RandomPkManager.getInstance().isRandomModel()) { RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_DEFAULT); @@ -1436,8 +1305,10 @@ public class SocketRyClient { break; case 9://pk结束的回调 mListener.onLinkMicPkEnd(map.getString("win_uid")); - EventBus.getDefault().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END)); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END)); + if (livePushRyViewHolder != null) { + livePushRyViewHolder.onLinkMicAnchorClose(); + } break; case 10://系统发起PK回调 JSONObject msg1 = new JSONObject(); diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index aeb0a5f8c..70a60f04c 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -120,6 +120,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX private boolean isPk = false; private boolean isNeedOpenCamera = false; private SWManager swManager; + private String pkUid1; //修改上面主播的头像 @Subscribe(threadMode = ThreadMode.MAIN) @@ -515,31 +516,13 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX if (code == 0) { JSONObject datas = JSONObject.parseObject(info[0]); String pkUid = datas.getString("pkuid"); + //退出副房间 - RCRTCEngine.getInstance().leaveOtherRoom(pkUid, true, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "退出房间成功" + pkUid); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - mPreView1.removeAllViews(); - mPreView1.setVisibility(View.GONE); - inputStreamList.clear(); - inputStreamList1.clear(); - changeToBig(); - //清理PK上面对方的头像 - EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); - closeButtonGone(); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", pkUid + "退出房间s失败" + rtcErrorCode); - } - }); - + // TODO: 2024/4/13 退出对方主播直播间 + SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),pkUid1); + SWManager.get().updateMyChannelView((FrameLayout) mBigContainer); + EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); + closeButtonGone(); SocketSendBean seed_msg = new SocketSendBean() .param("_method_", Constants.SOCKET_LINK_MIC_PK) @@ -772,7 +755,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX */ private void initRtcEngine() { swManager = SWManager.get(); - swManager.setAnchorContainer((FrameLayout) mLeftContainer); + swManager.setAnchorContainer((FrameLayout) mBigContainer); swManager.initRtcEngine((Activity) mContext, CommonAppConfig.getInstance().getUid()); swManager.setOnRtcEngineListener(new SWManager.onRtcEngineListener() { @Override @@ -788,14 +771,21 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX L.eSw("设置对方主播的视图setAnPkRtc" + u); //将自己的渲染视图设置到 leftContainer - //swManager.updateMyVideoView((FrameLayout) mLeftContainer,SWAuManager.getChannelName(CommonAppConfig.getInstance().getUid())); + swManager.updateMyChannelView((FrameLayout) mLeftContainer); + + //清除 mBigContainer 中的渲染 + mBigContainer.removeAllViews(); //设置对方主播的渲染视图 设置到 rightContainer swManager.setPkContainer1(mRightContainer); - swManager.joinExRoomEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,u.getId(), SWAuManager.getChannelName(u.getId())); + swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,u.getId(), SWAuManager.getChannelName(u.getId())); } } + public void onLinkMicAnchorClose(){ + swManager.updateMyChannelView((FrameLayout) mBigContainer); + } + @Override public void changeToLeft() { if (mPreView != null) { @@ -868,7 +858,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void startPush(String pushUrl) { //开播成功,创建频道 if (swManager != null) { - swManager.createRoom(CommonAppConfig.SWToken, CommonAppConfig.getChannelName()); + swManager.createChannel(CommonAppConfig.SWToken, CommonAppConfig.getChannelName()); } if (rcrtcLiveInfo != null) { rcrtcLiveInfo.addPublishStreamUrl(pushUrl, new IRCRTCResultDataCallback() { @@ -1066,7 +1056,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX .param("ct", ct); seed_msg.create(); - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") .params("GroupId", "g" + pkUid) .params("jsonstr", seed_msg.mResult.toString()) diff --git a/live/src/main/res/layout/view_live_push_ry.xml b/live/src/main/res/layout/view_live_push_ry.xml index ec20bbeee..4bf171e2b 100644 --- a/live/src/main/res/layout/view_live_push_ry.xml +++ b/live/src/main/res/layout/view_live_push_ry.xml @@ -94,10 +94,7 @@ - - - + android:layout_height="match_parent"/> From 583740e866610a9189d6fe7e56f3cd4195cb383f Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Thu, 18 Apr 2024 09:47:38 +0800 Subject: [PATCH 04/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E6=8E=A5=E5=85=A5=E7=BE=8E=E9=A2=9C]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FaceUnity/build.gradle | 16 +- .../com/yunbao/faceunity/FaceManager.java | 17 + .../yunbao/faceunity/utils/FURenderer.java | 4 +- .../faceunity/utils/FaceUnityConfig.java | 2 +- Share/build.gradle | 2 +- app/build.gradle | 4 +- .../java/com/shayu/phonelive/AppContext.java | 1 + build.gradle | 8 +- common/build.gradle | 3 +- config.gradle | 4 +- gradle.properties | 6 +- lib_faceunity/.gitignore | 4 + lib_faceunity/build.gradle | 79 + lib_faceunity/consumer-rules.pro | 0 lib_faceunity/proguard-rules.pro | 21 + lib_faceunity/src/main/AndroidManifest.xml | 5 + .../beautyapi/faceunity/FaceUnityBeautyAPI.kt | 179 +++ .../faceunity/FaceUnityBeautyAPIImpl.kt | 818 ++++++++++ .../faceunity/agora}/SWAuManager.java | 3 +- .../beautyapi/faceunity/agora}/SWManager.java | 88 +- .../faceunity/utils/FuDeviceUtils.java | 607 ++++++++ .../beautyapi/faceunity/utils/LogUtils.kt | 57 + .../beautyapi/faceunity/utils/StatsHelper.kt | 80 + .../faceunity/utils/egl/EGLContextHelper.java | 210 +++ .../faceunity/utils/egl/GLCopyHelper.java | 84 + .../faceunity/utils/egl/GLFrameBuffer.java | 204 +++ .../utils/egl/GLTextureBufferQueue.kt | 180 +++ .../faceunity/utils/egl/GLUtils.java | 279 ++++ .../utils/egl/TextureProcessHelper.kt | 214 +++ live/build.gradle | 2 +- .../live/activity/LiveRyAnchorActivity.java | 9 +- .../LiveFaceUnityDialogNewFragment.java | 87 ++ .../presenter/LiveRyLinkMicPkPresenter.java | 228 +-- .../yunbao/live/socket/SocketRyClient.java | 2 + .../live/views/LiveNewReadyRyViewHolder.java | 54 +- .../live/views/LivePlayRyViewHolder.java | 89 +- .../live/views/LivePlaySwViewHolder.java | 1374 ----------------- .../live/views/LivePushRyViewHolder.java | 194 +-- main/build.gradle | 2 +- pluginsForAnchor/build.gradle | 2 +- settings.gradle | 1 + 41 files changed, 3303 insertions(+), 1920 deletions(-) create mode 100644 lib_faceunity/.gitignore create mode 100644 lib_faceunity/build.gradle create mode 100644 lib_faceunity/consumer-rules.pro create mode 100644 lib_faceunity/proguard-rules.pro create mode 100644 lib_faceunity/src/main/AndroidManifest.xml create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/FaceUnityBeautyAPI.kt create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/FaceUnityBeautyAPIImpl.kt rename {common/src/main/java/com/yunbao/common/manager => lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora}/SWAuManager.java (99%) rename {common/src/main/java/com/yunbao/common/manager => lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora}/SWManager.java (77%) create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/FuDeviceUtils.java create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/LogUtils.kt create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/StatsHelper.kt create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/EGLContextHelper.java create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLCopyHelper.java create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLTextureBufferQueue.kt create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLUtils.java create mode 100644 lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/TextureProcessHelper.kt create mode 100644 live/src/main/java/com/yunbao/live/dialog/LiveFaceUnityDialogNewFragment.java delete mode 100644 live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java diff --git a/FaceUnity/build.gradle b/FaceUnity/build.gradle index 4d0686f41..e69ef51ea 100644 --- a/FaceUnity/build.gradle +++ b/FaceUnity/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'img-optimizer' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-parcelize' android { @@ -58,15 +58,15 @@ repositories { } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation rootProject.ext.dependencies["appcompat-androidx"] - implementation rootProject.ext.dependencies["recyclerview-androidx"] - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + api fileTree(dir: 'libs', include: ['*.jar']) + api rootProject.ext.dependencies["appcompat-androidx"] + api rootProject.ext.dependencies["recyclerview-androidx"] + api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" //common - implementation project(path: ':common') + api project(path: ':common') - implementation 'com.faceunity:core:8.3.1' - implementation 'com.faceunity:model:8.3.1' + api 'com.faceunity:core:8.7.0' + api 'com.faceunity:model:8.7.0' //implementation 'com.faceunity:nama:8.3.1' //底层库-标准版 diff --git a/FaceUnity/src/main/java/com/yunbao/faceunity/FaceManager.java b/FaceUnity/src/main/java/com/yunbao/faceunity/FaceManager.java index 9cbef67ef..0c3c09d6e 100644 --- a/FaceUnity/src/main/java/com/yunbao/faceunity/FaceManager.java +++ b/FaceUnity/src/main/java/com/yunbao/faceunity/FaceManager.java @@ -96,11 +96,17 @@ public class FaceManager implements SensorEventListener { faceUnityView.setIFaceUnityInter(new FaceUnityView.IFaceUnityInter() { @Override public void onPause() { + if(onMirrorChanged!=null){ + onMirrorChanged.onChange(false); + } pauseFace = true; } @Override public void onStart() { + if(onMirrorChanged!=null){ + onMirrorChanged.onChange(true); + } pauseFace = false; } }); @@ -295,7 +301,18 @@ public class FaceManager implements SensorEventListener { } + OnMirrorChanged onMirrorChanged; + + public void setOnMirrorChanged(OnMirrorChanged onMirrorChanged) { + this.onMirrorChanged = onMirrorChanged; + } + public interface FaceStatusChanged { void onFaceChanged(int num); } + + + public interface OnMirrorChanged{ + void onChange(boolean falg); + } } diff --git a/FaceUnity/src/main/java/com/yunbao/faceunity/utils/FURenderer.java b/FaceUnity/src/main/java/com/yunbao/faceunity/utils/FURenderer.java index 19ff7db23..12fd910f8 100644 --- a/FaceUnity/src/main/java/com/yunbao/faceunity/utils/FURenderer.java +++ b/FaceUnity/src/main/java/com/yunbao/faceunity/utils/FURenderer.java @@ -52,10 +52,10 @@ public class FURenderer extends IFURenderer { /* 特效FURenderKit*/ - private FURenderKit mFURenderKit; + public FURenderKit mFURenderKit; /* AI道具*/ - public static String BUNDLE_AI_FACE = "model" + File.separator + "ai_face_processor_lite.bundle"; + public static String BUNDLE_AI_FACE = "model" + File.separator + "ai_face_processor.bundle"; public static String BUNDLE_AI_HUMAN = "model" + File.separator + "ai_human_processor.bundle"; /* GL 线程 ID */ diff --git a/FaceUnity/src/main/java/com/yunbao/faceunity/utils/FaceUnityConfig.java b/FaceUnity/src/main/java/com/yunbao/faceunity/utils/FaceUnityConfig.java index 7ca84f925..b6a2d51de 100644 --- a/FaceUnity/src/main/java/com/yunbao/faceunity/utils/FaceUnityConfig.java +++ b/FaceUnity/src/main/java/com/yunbao/faceunity/utils/FaceUnityConfig.java @@ -15,7 +15,7 @@ public class FaceUnityConfig { /************************** 算法Model ******************************/ // 人脸识别 - public static String BUNDLE_AI_FACE = "model" + File.separator + "ai_face_processor_lite.bundle"; + public static String BUNDLE_AI_FACE = "model" + File.separator + "ai_face_processor.bundle"; // 手势 public static String BUNDLE_AI_HAND = "model" + File.separator + "ai_hand_processor.bundle"; diff --git a/Share/build.gradle b/Share/build.gradle index 039fa8b89..e3acfbeca 100644 --- a/Share/build.gradle +++ b/Share/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'img-optimizer' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-parcelize' android { diff --git a/app/build.gradle b/app/build.gradle index 4a5890d4b..ca93012ac 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -131,7 +131,7 @@ android { variant.mergeAssetsProvider.configure { doLast { delete(fileTree(dir: outputDir, includes: ['model/ai_bgseg_green.bundle', - 'model/ai_face_processor.bundle', + //'model/ai_face_processor.bundle', //'model/ai_face_processor_lite.bundle', 'model/ai_hairseg.bundle', 'model/ai_hand_processor.bundle', @@ -158,7 +158,7 @@ android { ])) println "isPluginModel = " + rootProject.ext.manifestPlaceholders.isPluginModel if (rootProject.ext.manifestPlaceholders.isPluginModel) { - delete(fileTree(dir: outputDir, includes: ['model/ai_face_processor_lite.bundle', + delete(fileTree(dir: outputDir, includes: ['model/ai_face_processor.bundle', 'graphics/face_beautification.bundle'])) } else { println "不删除bundle" diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index d9ccd9be5..737efced5 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -274,6 +274,7 @@ public class AppContext extends CommonAppContext { }); configSPApp(); + //初始化美颜SDK // FaceManager.initFaceUnity(this); } diff --git a/build.gradle b/build.gradle index 7212cbfef..fbf0b6204 100644 --- a/build.gradle +++ b/build.gradle @@ -52,4 +52,10 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir } - +ext { + IS_PUBLISH_LOCAL=true + LIB_VERSION="1.0.6" +// AGORA_RTC_SDK="io.agora.rtc:agora-special-full:4.1.1.28" +// AGORA_RTC_SDK= "${rootProject.rootDir.absolutePath}/sdk" + AGORA_RTC_SDK="io.agora.rtc:full-sdk:4.2.6" +} diff --git a/common/build.gradle b/common/build.gradle index b69c7b668..def1c55da 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.library' apply plugin: 'img-optimizer' +apply plugin: 'kotlin-android' android { @@ -226,6 +227,6 @@ dependencies { //轮播 一屏显示多个 api 'com.github.xiaohaibin:XBanner:androidx_v1.2.6' //声网SDK - api 'io.agora.rtc:agora-special-full:4.1.1.28' + //api 'io.agora.rtc:agora-special-full:4.2.6.245' } diff --git a/config.gradle b/config.gradle index 72fe88cbe..bead9f425 100644 --- a/config.gradle +++ b/config.gradle @@ -9,9 +9,9 @@ ext { ] manifestPlaceholders = [ //正式、 - serverHost : "https://napi.yaoulive.com", + //serverHost : "https://napi.yaoulive.com", // 测试 -// serverHost : "https://ceshi.yaoulive.com", + serverHost : "https://ceshi.yaoulive.com", //百度语音识别 diff --git a/gradle.properties b/gradle.properties index 15d390c86..38b11a081 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,8 +23,6 @@ android.enableJetifier=true systemProp.http.proxyHost=127.0.0.1 systemProp.https.proxyHost=127.0.0.1 -systemProp.https.proxyPort=7890 -systemProp.http.proxyPort=7890 -#systemProp.https.proxyPort=10809 -#systemProp.http.proxyPort=10809 +systemProp.https.proxyPort=10809 +systemProp.http.proxyPort=10809 #android.enableR8.fullMode=true \ No newline at end of file diff --git a/lib_faceunity/.gitignore b/lib_faceunity/.gitignore new file mode 100644 index 000000000..bcc2eb0f5 --- /dev/null +++ b/lib_faceunity/.gitignore @@ -0,0 +1,4 @@ +/build +/src/main/assets/makeup +/src/main/assets/sticker +authpack.java \ No newline at end of file diff --git a/lib_faceunity/build.gradle b/lib_faceunity/build.gradle new file mode 100644 index 000000000..cfa97aa94 --- /dev/null +++ b/lib_faceunity/build.gradle @@ -0,0 +1,79 @@ +apply plugin: 'com.android.library' +apply plugin: 'maven-publish' +apply plugin: 'kotlin-android' + +android { + compileSdkVersion 31 + buildToolsVersion "30.0.3" + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 31 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + if (new File("$AGORA_RTC_SDK").exists()) { + api fileTree(dir: "${AGORA_RTC_SDK}", include: ['*.jar', '*.aar']) + } else { + api "$AGORA_RTC_SDK" + } + api project(path: ':FaceUnity') +} + +// Because the components are created only during the afterEvaluate phase, you must +// configure your publications using the afterEvaluate() lifecycle method. +afterEvaluate { + publishing { + publications { + // Creates a Maven publication called "release". + release(MavenPublication) { + // Applies the component for the release build variant. + from components.release + + // You can then customize attributes of the publication as shown below. + groupId = 'com.github.AgoraIO-Community.BeautyAPI' + artifactId = 'FaceUnity' + version = "$LIB_VERSION" + } + // Creates a Maven publication called “debug”. + debug(MavenPublication) { + // Applies the component for the debug build variant. + from components.debug + + groupId = 'com.github.AgoraIO-Community.BeautyAPI' + artifactId = 'FaceUnity' + version = "$LIB_VERSION" + } + } + if(IS_PUBLISH_LOCAL){ + repositories { + maven { + url = "file://${rootProject.projectDir.path}/maven" + println("maven publish to ${url}") + } + } + } + } +} \ No newline at end of file diff --git a/lib_faceunity/consumer-rules.pro b/lib_faceunity/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/lib_faceunity/proguard-rules.pro b/lib_faceunity/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/lib_faceunity/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/lib_faceunity/src/main/AndroidManifest.xml b/lib_faceunity/src/main/AndroidManifest.xml new file mode 100644 index 000000000..0ec7a4108 --- /dev/null +++ b/lib_faceunity/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/FaceUnityBeautyAPI.kt b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/FaceUnityBeautyAPI.kt new file mode 100644 index 000000000..1058ea229 --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/FaceUnityBeautyAPI.kt @@ -0,0 +1,179 @@ +/* + * MIT License + * + * Copyright (c) 2023 Agora Community + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.agora.beautyapi.faceunity + +import android.content.Context +import android.view.View +import com.faceunity.core.faceunity.FURenderKit +import io.agora.base.VideoFrame +import io.agora.rtc2.Constants +import io.agora.rtc2.RtcEngine + +const val VERSION = "1.0.6" + +enum class CaptureMode{ + Agora, // 使用声网内部的祼数据接口进行处理 + Custom // 自定义模式,需要自己调用onFrame接口将原始视频帧传给BeautyAPI做处理 +} + +interface IEventCallback{ + + /** + * 统计数据回调,每处理完一帧后会回调一次 + * + * @param stats 美颜统计数据 + */ + fun onBeautyStats(stats: BeautyStats) +} + +data class BeautyStats( + val minCostMs:Long, // 统计区间内的最小值 + val maxCostMs: Long, // 统计区间内的最大值 + val averageCostMs: Long // 统计区间内的平均值 +) + +enum class MirrorMode { + + // 没有镜像正常画面的定义:前置拍到画面和手机看到画面是左右不一致的,后置拍到画面和手机看到画面是左右一致的 + + MIRROR_LOCAL_REMOTE, //本地远端都镜像,前置默认,本地和远端贴纸都正常 + MIRROR_LOCAL_ONLY, // 仅本地镜像,远端不镜像,,远端贴纸正常,本地贴纸镜像。用于打电话场景,电商直播场景(保证电商直播后面的告示牌文字是正的);这种模式因为本地远端是反的,所以肯定有一边的文字贴纸方向会是反的 + MIRROR_REMOTE_ONLY, // 仅远端镜像,本地不镜像,远端贴纸正常,本地贴纸镜像 + MIRROR_NONE // 本地远端都不镜像,后置默认,本地和远端贴纸都正常 +} + +data class CameraConfig( + val frontMirror: MirrorMode = MirrorMode.MIRROR_LOCAL_REMOTE, // 前置默认镜像:本地远端都镜像 + val backMirror: MirrorMode = MirrorMode.MIRROR_NONE // 后置默认镜像:本地远端都不镜像 +) + +data class Config( + val context: Context, // Android Context 上下文 + val rtcEngine: RtcEngine, // 声网Rtc引擎 + val fuRenderKit: FURenderKit, // 美颜SDK处理句柄 + val eventCallback: IEventCallback? = null, // 事件回调 + val captureMode: CaptureMode = CaptureMode.Agora, // 处理模式 + val statsDuration: Long = 1000, // 统计区间 + val statsEnable: Boolean = false, // 是否开启统计 + val cameraConfig: CameraConfig = CameraConfig() // 摄像头镜像配置 +) + +enum class ErrorCode(val value: Int) { + ERROR_OK(0), // 一切正常 + ERROR_HAS_NOT_INITIALIZED(101), // 没有调用Initialize或调用失败情况下调用了其他API + ERROR_HAS_INITIALIZED(102), // 已经Initialize成功后再次调用报错 + ERROR_HAS_RELEASED(103), // 已经调用release销毁后还调用其他API + ERROR_PROCESS_NOT_CUSTOM(104), // 非Custom处理模式下调用onFrame接口从外部传入视频帧 + ERROR_VIEW_TYPE_ERROR(105), // 当调用setupLocalVideo时view类型错误时返回 + ERROR_FRAME_SKIPPED(106), // 当处理帧忽略时在onFrame返回 +} + +enum class BeautyPreset { + CUSTOM, // 不使用推荐的美颜参数 + DEFAULT // 默认的 +} + +fun createFaceUnityBeautyAPI(): FaceUnityBeautyAPI = FaceUnityBeautyAPIImpl() + +interface FaceUnityBeautyAPI { + + /** + * 初始化API + * + * @param config 配置参数 + * @return 见ErrorCode + */ + fun initialize(config: Config): Int + + /** + * 开启/关闭美颜 + * + * @param enable true:开启; false: 关闭 + * @return 见ErrorCode + */ + fun enable(enable: Boolean): Int + + /** + * 本地视图渲染,由内部来处理镜像问题 + * + * @param view SurfaceView或TextureView + * @param renderMode 渲染缩放模式 + * @return 见ErrorCode + */ + fun setupLocalVideo(view: View, renderMode: Int = Constants.RENDER_MODE_HIDDEN): Int + + /** + * 当ProcessMode==Custom时由外部传入原始视频帧 + * + * @param videoFrame 原始视频帧 + * @return 见ErrorCode + */ + fun onFrame(videoFrame: VideoFrame): Int + + /** + * 声网提供的美颜最佳默认参数 + * + * @return 见ErrorCode + */ + fun setBeautyPreset(preset: BeautyPreset = BeautyPreset.DEFAULT): Int + + /** + * 更新摄像头配置 + */ + fun updateCameraConfig(config: CameraConfig): Int + + /** + * 是否是前置摄像头 + * PS:只在美颜处理中才能知道准确的值,否则会一直是true + */ + fun isFrontCamera(): Boolean + + /** + * 获取镜像状态 + * + * @return 镜像状态,true: 镜像,false:非镜像 + */ + fun getMirrorApplied(): Boolean + + /** + * 在处理线程里执行操作 + * + * @param run 操作run + */ + fun runOnProcessThread(run: ()->Unit) + + /** + * 私参配置,用于不对外api的调用,多用于测试 + */ + fun setParameters(key: String, value: String) + + /** + * 释放资源,一旦释放后这个实例将无法使用 + * + * @return 见ErrorCode + */ + fun release(): Int + +} \ No newline at end of file diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/FaceUnityBeautyAPIImpl.kt b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/FaceUnityBeautyAPIImpl.kt new file mode 100644 index 000000000..5c17a503d --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/FaceUnityBeautyAPIImpl.kt @@ -0,0 +1,818 @@ +/* + * MIT License + * + * Copyright (c) 2023 Agora Community + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.agora.beautyapi.faceunity + +import android.graphics.Matrix +import android.opengl.GLES11Ext +import android.opengl.GLES20 +import android.view.SurfaceView +import android.view.TextureView +import android.view.View +import com.faceunity.core.entity.FUBundleData +import com.faceunity.core.entity.FURenderInputData +import com.faceunity.core.enumeration.CameraFacingEnum +import com.faceunity.core.enumeration.FUInputBufferEnum +import com.faceunity.core.enumeration.FUInputTextureEnum +import com.faceunity.core.enumeration.FUTransformMatrixEnum +import com.faceunity.core.faceunity.FUAIKit +import com.faceunity.core.faceunity.FURenderKit +import com.faceunity.core.model.facebeauty.FaceBeauty +import com.faceunity.core.model.facebeauty.FaceBeautyFilterEnum +import io.agora.base.TextureBufferHelper +import io.agora.base.VideoFrame +import io.agora.base.VideoFrame.I420Buffer +import io.agora.base.VideoFrame.SourceType +import io.agora.base.VideoFrame.TextureBuffer +import io.agora.base.internal.video.EglBase +import io.agora.base.internal.video.YuvHelper +import io.agora.beautyapi.faceunity.utils.FuDeviceUtils +import io.agora.beautyapi.faceunity.utils.LogUtils +import io.agora.beautyapi.faceunity.utils.StatsHelper +import io.agora.beautyapi.faceunity.utils.egl.GLFrameBuffer +import io.agora.beautyapi.faceunity.utils.egl.TextureProcessHelper +import io.agora.rtc2.Constants +import io.agora.rtc2.gl.EglBaseProvider +import io.agora.rtc2.video.IVideoFrameObserver +import io.agora.rtc2.video.VideoCanvas +import java.io.File +import java.nio.ByteBuffer +import java.util.Collections +import java.util.concurrent.Callable + +class FaceUnityBeautyAPIImpl : FaceUnityBeautyAPI, IVideoFrameObserver { + private val TAG = "FaceUnityBeautyAPIImpl" + private val reportId = "scenarioAPI" + private val reportCategory = "beauty_android_$VERSION" + private var beautyMode = 0 // 0: 自动根据buffer类型切换,1:固定使用OES纹理,2:固定使用i420,3: 单纹理模式 + private var enableTextureAsync = true // 是否开启纹理+异步缓存处理,不支持在预览中实时切换。对于GPU性能好的手机可以减小美颜处理耗时,对于中端机开启后效果也不明显。 + + private var textureBufferHelper: TextureBufferHelper? = null + private var wrapTextureBufferHelper: TextureBufferHelper? = null + private var byteBuffer: ByteBuffer? = null + private var byteArray: ByteArray? = null + private var config: Config? = null + private var enable: Boolean = false + private var enableChange: Boolean = false + private var isReleased: Boolean = false + private var captureMirror = false + private var renderMirror = false + private val identityMatrix = Matrix() + private var mTextureProcessHelper: TextureProcessHelper? = null + private var statsHelper: StatsHelper? = null + private var skipFrame = 0 + private enum class ProcessSourceType{ + UNKNOWN, + TEXTURE_OES_ASYNC, + TEXTURE_2D_ASYNC, + TEXTURE_OES, + TEXTURE_2D, + I420 + } + private var currProcessSourceType = ProcessSourceType.UNKNOWN + private var deviceLevel = FuDeviceUtils.DEVICEINFO_UNKNOWN + private var isFrontCamera = true + private var cameraConfig = CameraConfig() + private var localVideoRenderMode = Constants.RENDER_MODE_HIDDEN + private val pendingProcessRunList = Collections.synchronizedList(mutableListOf<()->Unit>()) + private val transformGLFrameBuffer = GLFrameBuffer() + + override fun initialize(config: Config): Int { + if (this.config != null) { + LogUtils.e(TAG, "initialize >> The beauty api has been initialized!") + return ErrorCode.ERROR_HAS_INITIALIZED.value + } + this.config = config + this.cameraConfig = config.cameraConfig + if (config.captureMode == CaptureMode.Agora) { + config.rtcEngine.registerVideoFrameObserver(this) + } + statsHelper = StatsHelper(config.statsDuration){ + this.config?.eventCallback?.onBeautyStats(it) + } + LogUtils.i(TAG, "initialize >> config = $config") + LogUtils.i(TAG, "initialize >> beauty api version=$VERSION, beauty sdk version=${FURenderKit.getInstance().getVersion()}") + + // config face beauty + if (deviceLevel == FuDeviceUtils.DEVICEINFO_UNKNOWN) { + deviceLevel = FuDeviceUtils.judgeDeviceLevel(config.context) + FUAIKit.getInstance().faceProcessorSetFaceLandmarkQuality(deviceLevel) + if (deviceLevel > FuDeviceUtils.DEVICE_LEVEL_MID) { + FUAIKit.getInstance().fuFaceProcessorSetDetectSmallFace(true) + } + } + LogUtils.i(TAG, "initialize >> FuDeviceUtils deviceLevel=$deviceLevel") + config.rtcEngine.sendCustomReportMessage(reportId, reportCategory, "initialize", "config=$config, deviceLevel=$deviceLevel", 0) + return ErrorCode.ERROR_OK.value + } + + override fun enable(enable: Boolean): Int { + LogUtils.i(TAG, "enable >> enable = $enable") + if (config == null) { + LogUtils.e(TAG, "enable >> The beauty api has not been initialized!") + return ErrorCode.ERROR_HAS_NOT_INITIALIZED.value + } + if (isReleased) { + LogUtils.e(TAG, "enable >> The beauty api has been released!") + return ErrorCode.ERROR_HAS_RELEASED.value + } + if(config?.captureMode == CaptureMode.Custom){ + skipFrame = 2 + LogUtils.i(TAG, "enable >> skipFrame = $skipFrame") + } + config?.rtcEngine?.sendCustomReportMessage(reportId, reportCategory, "enable", "enable=$enable", 0) + + if(this.enable != enable){ + this.enable = enable + enableChange = true + LogUtils.i(TAG, "enable >> enableChange") + } + return ErrorCode.ERROR_OK.value + } + + override fun setupLocalVideo(view: View, renderMode: Int): Int { + val rtcEngine = config?.rtcEngine + if(rtcEngine == null){ + LogUtils.e(TAG, "setupLocalVideo >> The beauty api has not been initialized!") + return ErrorCode.ERROR_HAS_NOT_INITIALIZED.value + } + LogUtils.i(TAG, "setupLocalVideo >> view=$view, renderMode=$renderMode") + localVideoRenderMode = renderMode + rtcEngine.sendCustomReportMessage(reportId, reportCategory, "enable", "view=$view, renderMode=$renderMode", 0) + if (view is TextureView || view is SurfaceView) { + val canvas = VideoCanvas(view, renderMode, 0) + canvas.mirrorMode = Constants.VIDEO_MIRROR_MODE_DISABLED + rtcEngine.setupLocalVideo(canvas) + return ErrorCode.ERROR_OK.value + } + return ErrorCode.ERROR_VIEW_TYPE_ERROR.value + } + + override fun onFrame(videoFrame: VideoFrame): Int { + val conf = config + if(conf == null){ + LogUtils.e(TAG, "onFrame >> The beauty api has not been initialized!") + return ErrorCode.ERROR_HAS_NOT_INITIALIZED.value + } + if (isReleased) { + LogUtils.e(TAG, "onFrame >> The beauty api has been released!") + return ErrorCode.ERROR_HAS_RELEASED.value + } + if (conf.captureMode != CaptureMode.Custom) { + LogUtils.e(TAG, "onFrame >> The capture mode is not Custom!") + return ErrorCode.ERROR_PROCESS_NOT_CUSTOM.value + } + if (processBeauty(videoFrame)) { + return ErrorCode.ERROR_OK.value + } + LogUtils.i(TAG, "onFrame >> Skip Frame.") + return ErrorCode.ERROR_FRAME_SKIPPED.value + } + + override fun updateCameraConfig(config: CameraConfig): Int { + LogUtils.i(TAG, "updateCameraConfig >> oldCameraConfig=$cameraConfig, newCameraConfig=$config") + cameraConfig = CameraConfig(config.frontMirror, config.backMirror) + this.config?.rtcEngine?.sendCustomReportMessage(reportId, reportCategory, "updateCameraConfig", "config=$config", 0) + + return ErrorCode.ERROR_OK.value + } + + override fun runOnProcessThread(run: () -> Unit) { + if (config == null) { + LogUtils.e(TAG, "runOnProcessThread >> The beauty api has not been initialized!") + return + } + if (isReleased) { + LogUtils.e(TAG, "runOnProcessThread >> The beauty api has been released!") + return + } + if (textureBufferHelper?.handler?.looper?.thread == Thread.currentThread()) { + run.invoke() + } else if (textureBufferHelper != null) { + textureBufferHelper?.handler?.post(run) + } else { + pendingProcessRunList.add(run) + } + } + + override fun isFrontCamera() = isFrontCamera + + override fun setParameters(key: String, value: String) { + when(key){ + "beauty_mode" -> beautyMode = value.toInt() + "enableTextureAsync" -> enableTextureAsync = value.toBoolean() + } + } + + override fun setBeautyPreset(preset: BeautyPreset): Int { + val conf = config + if(conf == null){ + LogUtils.e(TAG, "setBeautyPreset >> The beauty api has not been initialized!") + return ErrorCode.ERROR_HAS_NOT_INITIALIZED.value + } + if (isReleased) { + LogUtils.e(TAG, "setBeautyPreset >> The beauty api has been released!") + return ErrorCode.ERROR_HAS_RELEASED.value + } + + LogUtils.i(TAG, "setBeautyPreset >> preset = $preset") + config?.rtcEngine?.sendCustomReportMessage(reportId, reportCategory, "enable", "preset=$preset", 0) + + val recommendFaceBeauty = FaceBeauty(FUBundleData("graphics" + File.separator + "face_beautification.bundle")) + if (preset == BeautyPreset.DEFAULT) { + recommendFaceBeauty.filterName = FaceBeautyFilterEnum.FENNEN_1 + recommendFaceBeauty.filterIntensity = 0.7 + // 美牙 + recommendFaceBeauty.toothIntensity = 0.3 + // 亮眼 + recommendFaceBeauty.eyeBrightIntensity = 0.3 + // 大眼 + recommendFaceBeauty.eyeEnlargingIntensity = 0.5 + // 红润 + recommendFaceBeauty.redIntensity = 0.5 * 2 + // 美白 + recommendFaceBeauty.colorIntensity = 0.75 * 2 + // 磨皮 + recommendFaceBeauty.blurIntensity = 0.75 * 6 + if (deviceLevel > FuDeviceUtils.DEVICE_LEVEL_MID) { + val score = FUAIKit.getInstance().getFaceProcessorGetConfidenceScore(0) + if (score > 0.95) { + recommendFaceBeauty.blurType = 3 + recommendFaceBeauty.enableBlurUseMask = true + } else { + recommendFaceBeauty.blurType = 2 + recommendFaceBeauty.enableBlurUseMask = false + } + } else { + recommendFaceBeauty.blurType = 2 + recommendFaceBeauty.enableBlurUseMask = false + } + // 嘴型 + recommendFaceBeauty.mouthIntensity = 0.3 + // 瘦鼻 + recommendFaceBeauty.noseIntensity = 0.1 + // 额头 + recommendFaceBeauty.forHeadIntensity = 0.3 + // 下巴 + recommendFaceBeauty.chinIntensity = 0.0 + // 瘦脸 + recommendFaceBeauty.cheekThinningIntensity = 0.3 + // 窄脸 + recommendFaceBeauty.cheekNarrowIntensity = 0.0 + // 小脸 + recommendFaceBeauty.cheekSmallIntensity = 0.0 + // v脸 + recommendFaceBeauty.cheekVIntensity = 0.0 + } + conf.fuRenderKit.faceBeauty = recommendFaceBeauty + return ErrorCode.ERROR_OK.value + } + + override fun release(): Int { + val conf = config + val fuRenderer = conf?.fuRenderKit + if(fuRenderer == null){ + LogUtils.e(TAG, "release >> The beauty api has not been initialized!") + return ErrorCode.ERROR_HAS_NOT_INITIALIZED.value + } + if (isReleased) { + LogUtils.e(TAG, "setBeautyPreset >> The beauty api has been released!") + return ErrorCode.ERROR_HAS_RELEASED.value + } + LogUtils.i(TAG, "release") + if (conf.captureMode == CaptureMode.Agora) { + conf.rtcEngine.registerVideoFrameObserver(null) + } + conf.rtcEngine.sendCustomReportMessage(reportId, reportCategory, "release", "", 0) + + isReleased = true + textureBufferHelper?.let { + textureBufferHelper = null + it.handler.removeCallbacksAndMessages(null) + it.invoke { + fuRenderer.release() + mTextureProcessHelper?.release() + mTextureProcessHelper = null + transformGLFrameBuffer.release() + null + } + // it.handler.looper.quit() + it.dispose() + } + wrapTextureBufferHelper?.let { + wrapTextureBufferHelper = null + it.dispose() + } + statsHelper?.reset() + statsHelper = null + pendingProcessRunList.clear() + return ErrorCode.ERROR_OK.value + } + + private fun processBeauty(videoFrame: VideoFrame): Boolean { + if (isReleased) { + LogUtils.e(TAG, "processBeauty >> The beauty api has been released!") + return false + } + + val cMirror = + if (isFrontCamera) { + when (cameraConfig.frontMirror) { + MirrorMode.MIRROR_LOCAL_REMOTE -> true + MirrorMode.MIRROR_LOCAL_ONLY -> false + MirrorMode.MIRROR_REMOTE_ONLY -> true + MirrorMode.MIRROR_NONE -> false + } + } else { + when (cameraConfig.backMirror) { + MirrorMode.MIRROR_LOCAL_REMOTE -> true + MirrorMode.MIRROR_LOCAL_ONLY -> false + MirrorMode.MIRROR_REMOTE_ONLY -> true + MirrorMode.MIRROR_NONE -> false + } + } + val rMirror = + if (isFrontCamera) { + when (cameraConfig.frontMirror) { + MirrorMode.MIRROR_LOCAL_REMOTE -> false + MirrorMode.MIRROR_LOCAL_ONLY -> true + MirrorMode.MIRROR_REMOTE_ONLY -> true + MirrorMode.MIRROR_NONE -> false + } + } else { + when (cameraConfig.backMirror) { + MirrorMode.MIRROR_LOCAL_REMOTE -> false + MirrorMode.MIRROR_LOCAL_ONLY -> true + MirrorMode.MIRROR_REMOTE_ONLY -> true + MirrorMode.MIRROR_NONE -> false + } + } + if (captureMirror != cMirror || renderMirror != rMirror) { + LogUtils.w(TAG, "processBeauty >> enable=$enable, captureMirror=$captureMirror->$cMirror, renderMirror=$renderMirror->$rMirror") + captureMirror = cMirror + if(renderMirror != rMirror){ + renderMirror = rMirror + config?.rtcEngine?.setLocalRenderMode( + localVideoRenderMode, + if(renderMirror) Constants.VIDEO_MIRROR_MODE_ENABLED else Constants.VIDEO_MIRROR_MODE_DISABLED + ) + } + textureBufferHelper?.invoke { + mTextureProcessHelper?.reset() + } + skipFrame = 2 + return false + } + + val oldIsFrontCamera = isFrontCamera + isFrontCamera = videoFrame.sourceType == SourceType.kFrontCamera + if(oldIsFrontCamera != isFrontCamera){ + LogUtils.w(TAG, "processBeauty >> oldIsFrontCamera=$oldIsFrontCamera, isFrontCamera=$isFrontCamera") + return false + } + + if(enableChange){ + enableChange = false + textureBufferHelper?.invoke { + mTextureProcessHelper?.reset() + } + return false + } + + if(!enable){ + return true + } + + if (textureBufferHelper == null) { + textureBufferHelper = TextureBufferHelper.create( + "FURender", + EglBaseProvider.instance().rootEglBase.eglBaseContext + ) + textureBufferHelper?.invoke { + synchronized(pendingProcessRunList){ + val iterator = pendingProcessRunList.iterator() + while (iterator.hasNext()){ + iterator.next().invoke() + iterator.remove() + } + } + } + LogUtils.i(TAG, "processBeauty >> create texture buffer, beautyMode=$beautyMode") + } + if (wrapTextureBufferHelper == null) { + wrapTextureBufferHelper = TextureBufferHelper.create( + "FURenderWrap", + EglBaseProvider.instance().rootEglBase.eglBaseContext + ) + LogUtils.i(TAG, "processBeauty >> create texture buffer wrap, beautyMode=$beautyMode") + } + val startTime = System.currentTimeMillis() + val processTexId = when (beautyMode) { + 2 -> processBeautySingleBuffer(videoFrame) + 3 -> { + if (enableTextureAsync) { + processBeautySingleTextureAsync(videoFrame) + } else { + processBeautySingleTexture(videoFrame) + } + } + else -> processBeautyAuto(videoFrame) + } + + if(config?.statsEnable == true){ + val costTime = System.currentTimeMillis() - startTime + statsHelper?.once(costTime) + } + + if (processTexId <= 0) { + LogUtils.w(TAG, "processBeauty >> processTexId <= 0") + return false + } + + if(skipFrame > 0){ + skipFrame -- + LogUtils.w(TAG, "processBeauty >> skipFrame=$skipFrame") + return false + } + + val processBuffer: TextureBuffer = wrapTextureBufferHelper?.wrapTextureBuffer( + videoFrame.rotatedWidth, + videoFrame.rotatedHeight, + TextureBuffer.Type.RGB, + processTexId, + identityMatrix + ) ?: return false + videoFrame.replaceBuffer(processBuffer, 0, videoFrame.timestampNs) + return true + } + + private fun processBeautyAuto(videoFrame: VideoFrame): Int { + val buffer = videoFrame.buffer + return if (buffer is TextureBuffer) { + if (enableTextureAsync) { + processBeautySingleTextureAsync(videoFrame) + } else { + processBeautySingleTexture(videoFrame) + } + } else { + processBeautySingleBuffer(videoFrame) + } + } + + private fun processBeautySingleTextureAsync(videoFrame: VideoFrame): Int { + val texBufferHelper = wrapTextureBufferHelper ?: return -1 + val textureBuffer = videoFrame.buffer as? TextureBuffer ?: return -1 + + when(textureBuffer.type){ + TextureBuffer.Type.OES -> { + if(currProcessSourceType != ProcessSourceType.TEXTURE_OES_ASYNC){ + LogUtils.i(TAG, "processBeauty >> process source type change old=$currProcessSourceType, new=${ProcessSourceType.TEXTURE_OES_ASYNC}") + if (currProcessSourceType != ProcessSourceType.UNKNOWN) { + skipFrame = 3 + } + currProcessSourceType = ProcessSourceType.TEXTURE_OES_ASYNC + return -1 + } + } + else -> { + if(currProcessSourceType != ProcessSourceType.TEXTURE_2D_ASYNC){ + LogUtils.i(TAG, "processBeauty >> process source type change old=$currProcessSourceType, new=${ProcessSourceType.TEXTURE_2D_ASYNC}") + if (currProcessSourceType != ProcessSourceType.UNKNOWN) { + skipFrame = 3 + } + currProcessSourceType = ProcessSourceType.TEXTURE_2D_ASYNC + skipFrame = 6 + return -1 + } + } + } + + if(mTextureProcessHelper == null) { + mTextureProcessHelper = TextureProcessHelper() + mTextureProcessHelper?.setFilter { frame -> + val fuRenderKit = config?.fuRenderKit ?: return@setFilter -1 + + val input = FURenderInputData(frame.width, frame.height) + input.texture = FURenderInputData.FUTexture( + FUInputTextureEnum.FU_ADM_FLAG_COMMON_TEXTURE, + frame.textureId + ) + val isFront = frame.isFrontCamera + input.renderConfig.let { + if (isFront) { + it.cameraFacing = CameraFacingEnum.CAMERA_FRONT + it.inputBufferMatrix = FUTransformMatrixEnum.CCROT0 + it.inputTextureMatrix = FUTransformMatrixEnum.CCROT0 + it.outputMatrix = FUTransformMatrixEnum.CCROT0_FLIPVERTICAL + it.deviceOrientation = 270 + } else { + it.cameraFacing = CameraFacingEnum.CAMERA_BACK + it.inputBufferMatrix = FUTransformMatrixEnum.CCROT0 + it.inputTextureMatrix = FUTransformMatrixEnum.CCROT0 + it.outputMatrix = FUTransformMatrixEnum.CCROT0_FLIPVERTICAL + it.deviceOrientation = 270 + } + } + if (isReleased) { + return@setFilter -1 + } + val ret = textureBufferHelper?.invoke { + synchronized(EglBase.lock){ + return@invoke fuRenderKit.renderWithInput(input).texture?.texId ?: -1 + } + } + return@setFilter ret ?: -1 + } + } + + return texBufferHelper.invoke { + if(isReleased){ + return@invoke -1 + } + + return@invoke mTextureProcessHelper?.process( + textureBuffer.textureId, + when (textureBuffer.type) { + TextureBuffer.Type.OES -> GLES11Ext.GL_TEXTURE_EXTERNAL_OES + else -> GLES20.GL_TEXTURE_2D + }, + textureBuffer.width, + textureBuffer.height, + videoFrame.rotation, + textureBuffer.transformMatrixArray, + isFrontCamera, + (isFrontCamera && !captureMirror) || (!isFrontCamera && captureMirror) + )?: -1 + } + } + + private fun processBeautySingleTexture(videoFrame: VideoFrame): Int { + val texBufferHelper = wrapTextureBufferHelper ?: return -1 + val textureBuffer = videoFrame.buffer as? TextureBuffer ?: return -1 + + when(textureBuffer.type){ + TextureBuffer.Type.OES -> { + if(currProcessSourceType != ProcessSourceType.TEXTURE_OES){ + LogUtils.i(TAG, "processBeauty >> process source type change old=$currProcessSourceType, new=${ProcessSourceType.TEXTURE_OES}") + if (currProcessSourceType != ProcessSourceType.UNKNOWN) { + skipFrame = 3 + } + currProcessSourceType = ProcessSourceType.TEXTURE_OES + return -1 + } + } + else -> { + if(currProcessSourceType != ProcessSourceType.TEXTURE_2D){ + LogUtils.i(TAG, "processBeauty >> process source type change old=$currProcessSourceType, new=${ProcessSourceType.TEXTURE_2D}") + if (currProcessSourceType != ProcessSourceType.UNKNOWN) { + skipFrame = 3 + } + currProcessSourceType = ProcessSourceType.TEXTURE_2D + skipFrame = 6 + return -1 + } + } + } + + val width = videoFrame.rotatedWidth + val height = videoFrame.rotatedHeight + val isFront = videoFrame.sourceType == SourceType.kFrontCamera + val rotation = videoFrame.rotation + + return texBufferHelper.invoke { + val fuRenderKit = config?.fuRenderKit ?: return@invoke -1 + + transformGLFrameBuffer.setSize(width, height) + transformGLFrameBuffer.resetTransform() + transformGLFrameBuffer.setTexMatrix(textureBuffer.transformMatrixArray) + transformGLFrameBuffer.setRotation(rotation) + var flipH = isFront + if((isFrontCamera && !captureMirror) || (!isFrontCamera && captureMirror)){ + flipH = !flipH + } + transformGLFrameBuffer.setFlipH(flipH) + val transformTexId = transformGLFrameBuffer.process( + textureBuffer.textureId, when (textureBuffer.type) { + TextureBuffer.Type.OES -> GLES11Ext.GL_TEXTURE_EXTERNAL_OES + else -> GLES20.GL_TEXTURE_2D + } + ) + + val input = FURenderInputData(width, height) + input.texture = FURenderInputData.FUTexture( + FUInputTextureEnum.FU_ADM_FLAG_COMMON_TEXTURE, + transformTexId + ) + input.renderConfig.let { + if (isFront) { + it.cameraFacing = CameraFacingEnum.CAMERA_FRONT + it.inputBufferMatrix = FUTransformMatrixEnum.CCROT0 + it.inputTextureMatrix = FUTransformMatrixEnum.CCROT0 + it.outputMatrix = FUTransformMatrixEnum.CCROT0_FLIPVERTICAL + it.deviceOrientation = 270 + } else { + it.cameraFacing = CameraFacingEnum.CAMERA_BACK + it.inputBufferMatrix = FUTransformMatrixEnum.CCROT0 + it.inputTextureMatrix = FUTransformMatrixEnum.CCROT0 + it.outputMatrix = FUTransformMatrixEnum.CCROT0_FLIPVERTICAL + it.deviceOrientation = 270 + } + } + if (isReleased) { + return@invoke -1 + } + synchronized(EglBase.lock){ + return@invoke fuRenderKit.renderWithInput(input).texture?.texId ?: -1 + } + } + } + + private fun processBeautySingleBuffer(videoFrame: VideoFrame): Int { + val texBufferHelper = textureBufferHelper ?: return -1 + if(currProcessSourceType != ProcessSourceType.I420){ + LogUtils.i(TAG, "processBeauty >> process source type change old=$currProcessSourceType, new=${ProcessSourceType.I420}") + if (currProcessSourceType != ProcessSourceType.UNKNOWN) { + skipFrame = 3 + } + currProcessSourceType = ProcessSourceType.I420 + return -1 + } + val bufferArray = getNV21Buffer(videoFrame) ?: return -1 + val buffer = videoFrame.buffer + val width = buffer.width + val height = buffer.height + val isFront = videoFrame.sourceType == SourceType.kFrontCamera + val mirror = (isFrontCamera && !captureMirror) || (!isFrontCamera && captureMirror) + val rotation = videoFrame.rotation + + return texBufferHelper.invoke(Callable { + if(isReleased){ + return@Callable -1 + } + val fuRenderKit = config?.fuRenderKit ?: return@Callable -1 + val input = FURenderInputData(width, height) + input.imageBuffer = FURenderInputData.FUImageBuffer( + FUInputBufferEnum.FU_FORMAT_NV21_BUFFER, + bufferArray + ) + input.renderConfig.let { + if (isFront) { + it.cameraFacing = CameraFacingEnum.CAMERA_FRONT + it.inputBufferMatrix = if(mirror) { + when (rotation) { + 0 -> FUTransformMatrixEnum.CCROT0 + 180 -> FUTransformMatrixEnum.CCROT180 + else -> FUTransformMatrixEnum.CCROT90 + } + } else { + when (rotation) { + 0 -> FUTransformMatrixEnum.CCROT0_FLIPHORIZONTAL + 180 -> FUTransformMatrixEnum.CCROT0_FLIPVERTICAL + else -> FUTransformMatrixEnum.CCROT90_FLIPHORIZONTAL + } + } + it.inputTextureMatrix = if(mirror) { + when (rotation) { + 0 -> FUTransformMatrixEnum.CCROT0 + 180 -> FUTransformMatrixEnum.CCROT180 + else -> FUTransformMatrixEnum.CCROT90 + } + } else { + when (rotation) { + 0 -> FUTransformMatrixEnum.CCROT0_FLIPHORIZONTAL + 180 -> FUTransformMatrixEnum.CCROT0_FLIPVERTICAL + else -> FUTransformMatrixEnum.CCROT90_FLIPHORIZONTAL + } + } + it.deviceOrientation = when(rotation){ + 0 -> 270 + 180 -> 90 + else -> 0 + } + it.outputMatrix = FUTransformMatrixEnum.CCROT0 + } else { + it.cameraFacing = CameraFacingEnum.CAMERA_BACK + it.inputBufferMatrix = if(mirror) { + when (rotation) { + 0 -> FUTransformMatrixEnum.CCROT0_FLIPHORIZONTAL + 180 -> FUTransformMatrixEnum.CCROT0_FLIPVERTICAL + else -> FUTransformMatrixEnum.CCROT90_FLIPVERTICAL + } + } else { + when (rotation) { + 0 -> FUTransformMatrixEnum.CCROT0 + 180 -> FUTransformMatrixEnum.CCROT180 + else -> FUTransformMatrixEnum.CCROT270 + } + } + it.inputTextureMatrix = if(mirror) { + when (rotation) { + 0 -> FUTransformMatrixEnum.CCROT0_FLIPHORIZONTAL + 180 -> FUTransformMatrixEnum.CCROT0_FLIPVERTICAL + else -> FUTransformMatrixEnum.CCROT90_FLIPVERTICAL + } + } else { + when (rotation) { + 0 -> FUTransformMatrixEnum.CCROT0 + 180 -> FUTransformMatrixEnum.CCROT180 + else -> FUTransformMatrixEnum.CCROT270 + } + } + it.deviceOrientation = when(rotation){ + 0 -> 270 + 180 -> 90 + else -> 0 + } + it.outputMatrix = FUTransformMatrixEnum.CCROT0 + } + } + + mTextureProcessHelper?.let { + if(it.size() > 0){ + it.reset() + return@Callable -1 + } + } + synchronized(EglBase.lock){ + return@Callable fuRenderKit.renderWithInput(input).texture?.texId ?: -1 + } + }) + } + + private fun getNV21Buffer(videoFrame: VideoFrame): ByteArray? { + val buffer = videoFrame.buffer + val width = buffer.width + val height = buffer.height + val size = (width * height * 3.0f / 2.0f + 0.5f).toInt() + if (byteBuffer == null || byteBuffer?.capacity() != size || byteArray == null || byteArray?.size != size) { + byteBuffer?.clear() + byteBuffer = ByteBuffer.allocateDirect(size) + byteArray = ByteArray(size) + return null + } + val outArray = byteArray ?: return null + val outBuffer = byteBuffer ?: return null + val i420Buffer = buffer as? I420Buffer ?: buffer.toI420() + YuvHelper.I420ToNV12( + i420Buffer.dataY, i420Buffer.strideY, + i420Buffer.dataV, i420Buffer.strideV, + i420Buffer.dataU, i420Buffer.strideU, + outBuffer, width, height + ) + outBuffer.position(0) + outBuffer.get(outArray) + if(buffer !is I420Buffer){ + i420Buffer.release() + } + return outArray + } + + // IVideoFrameObserver implements + + override fun onCaptureVideoFrame(sourceType: Int, videoFrame: VideoFrame?): Boolean { + videoFrame ?: return false + return processBeauty(videoFrame) + } + + override fun onPreEncodeVideoFrame(sourceType: Int, videoFrame: VideoFrame?) = false + + override fun onMediaPlayerVideoFrame(videoFrame: VideoFrame?, mediaPlayerId: Int) = false + + override fun onRenderVideoFrame( + channelId: String?, + uid: Int, + videoFrame: VideoFrame? + ) = false + + override fun getVideoFrameProcessMode() = IVideoFrameObserver.PROCESS_MODE_READ_WRITE + + override fun getVideoFormatPreference() = IVideoFrameObserver.VIDEO_PIXEL_DEFAULT + + override fun getRotationApplied() = false + + override fun getMirrorApplied() = captureMirror && !enable + + override fun getObservedFramePosition() = IVideoFrameObserver.POSITION_POST_CAPTURER + +} \ No newline at end of file diff --git a/common/src/main/java/com/yunbao/common/manager/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java similarity index 99% rename from common/src/main/java/com/yunbao/common/manager/SWAuManager.java rename to lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index e69707e99..e22394f46 100644 --- a/common/src/main/java/com/yunbao/common/manager/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -1,10 +1,11 @@ -package com.yunbao.common.manager; +package io.agora.beautyapi.faceunity.agora; import android.app.Activity; import android.content.Context; import android.view.SurfaceView; import android.widget.FrameLayout; + import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.manager.base.BaseCacheManager; diff --git a/common/src/main/java/com/yunbao/common/manager/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java similarity index 77% rename from common/src/main/java/com/yunbao/common/manager/SWManager.java rename to lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 2d17287ea..6fa380edf 100644 --- a/common/src/main/java/com/yunbao/common/manager/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -1,4 +1,4 @@ -package com.yunbao.common.manager; +package io.agora.beautyapi.faceunity.agora; import android.app.Activity; import android.content.Context; @@ -10,11 +10,20 @@ import com.yunbao.common.CommonAppContext; import com.yunbao.common.bean.SwTokenModel; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.base.BaseCacheManager; import com.yunbao.common.utils.L; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; +import com.yunbao.faceunity.utils.FURenderer; +import io.agora.beautyapi.faceunity.BeautyPreset; +import io.agora.beautyapi.faceunity.CameraConfig; +import io.agora.beautyapi.faceunity.CaptureMode; +import io.agora.beautyapi.faceunity.Config; +import io.agora.beautyapi.faceunity.FaceUnityBeautyAPI; +import io.agora.beautyapi.faceunity.FaceUnityBeautyAPIKt; +import io.agora.beautyapi.faceunity.MirrorMode; import io.agora.rtc2.ChannelMediaOptions; import io.agora.rtc2.Constants; import io.agora.rtc2.IRtcEngineEventHandler; @@ -35,8 +44,9 @@ public class SWManager extends BaseCacheManager { private Activity mContext; public static SWManager manager; private RtcEngineEx mRtcEngine; + private final FaceUnityBeautyAPI faceUnityBeautyAPI = FaceUnityBeautyAPIKt.createFaceUnityBeautyAPI(); private int uid; - VideoEncoderConfiguration cfg; + private VideoEncoderConfiguration cfg; private FrameLayout anchorContainer; //主播视图 private FrameLayout pkContainer1; //pk主播视图1 private FrameLayout pkContainer2; //pk主播视图2 @@ -111,8 +121,23 @@ public class SWManager extends BaseCacheManager { // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 SurfaceView surfaceView = new SurfaceView(mContext); anchorContainer.addView(surfaceView); + Config config = new Config(mContext, mRtcEngine, FURenderer.INSTANCE.mFURenderKit, null, CaptureMode.Agora, 0, false, new CameraConfig(MirrorMode.MIRROR_NONE,MirrorMode.MIRROR_NONE)); + faceUnityBeautyAPI.initialize(config); + faceUnityBeautyAPI.enable(true); + + faceUnityBeautyAPI.setBeautyPreset(BeautyPreset.CUSTOM); + //FaceUnityBeautyManage.getInstance().mFURenderKit.setFaceBeauty(); + // 设置视图 - mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); + faceUnityBeautyAPI.setupLocalVideo(surfaceView, Constants.RENDER_MODE_HIDDEN); + //faceUnityBeautyAPI.updateCameraConfig(new CameraConfig(MirrorMode.MIRROR_NONE,MirrorMode.MIRROR_NONE)); + //mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); + } + + public void setEnableBeauty(boolean flag){ + if(faceUnityBeautyAPI!=null){ + faceUnityBeautyAPI.enable(flag); + } } /** @@ -133,9 +158,51 @@ public class SWManager extends BaseCacheManager { break; } mRtcEngine.setVideoEncoderConfiguration(cfg); + // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 + SurfaceView surfaceView = new SurfaceView(mContext); + anchorContainer.addView(surfaceView); + // 设置视图 + mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); } } + /** + * 设置镜像模式 + */ + public void setMirrorMode(){ + if(cfg!=null&&mRtcEngine!=null){ + L.eSw("setMirrorMode设置镜像"+cfg.mirrorMode); + if(cfg.mirrorMode==VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_ENABLED){ + cfg.mirrorMode = VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_DISABLED; //取消镜像 + }else{ + cfg.mirrorMode = VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_ENABLED; //设置镜像 + } + mRtcEngine.setVideoEncoderConfiguration(cfg); + SurfaceView surfaceView = new SurfaceView(mContext); + anchorContainer.addView(surfaceView); + mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); + } + } + + /** + * 设置镜像模式 + */ + public void switchCamera(){ + if(mRtcEngine!=null){ + mRtcEngine.switchCamera(); + } + } + + /** + * 设置美颜 + */ + public void setBeautPreset(){ + if(mRtcEngine!=null){ + + } + } + + /** * 创建直播间 */ @@ -231,6 +298,15 @@ public class SWManager extends BaseCacheManager { mRtcEngine.leaveChannelEx(rtcConnection); } + /** + * 退出所有频道 + */ + public void exitChannelAll(){ + if(mRtcEngine!=null){ + mRtcEngine.leaveChannel(); + } + } + //设置对方主播视图 private void setupRemoteVideo(int uid) { SurfaceView surfaceView = new SurfaceView(mContext); @@ -292,6 +368,12 @@ public class SWManager extends BaseCacheManager { super.onLeaveChannel(stats); L.eSw("onLeaveChannel退出頻道"); } + + @Override + public void onLocalVideoStateChanged(Constants.VideoSourceType source, int state, int error) { + super.onLocalVideoStateChanged(source, state, error); + L.eSw("onLocalVideoStateChanged_source"+source+" state_"+state+" error_"+error); + } }; private void refreshToken() { diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/FuDeviceUtils.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/FuDeviceUtils.java new file mode 100644 index 000000000..60de92611 --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/FuDeviceUtils.java @@ -0,0 +1,607 @@ +/* + * MIT License + * + * Copyright (c) 2023 Agora Community + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.agora.beautyapi.faceunity.utils; + +import android.annotation.TargetApi; +import android.app.ActivityManager; +import android.content.Context; +import android.os.Build; +import android.text.TextUtils; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class FuDeviceUtils { + + public static final String TAG = "FuDeviceUtils"; + + public static final int DEVICE_LEVEL_HIGH = 2; + public static final int DEVICE_LEVEL_MID = 1; + public static final int DEVICE_LEVEL_LOW = 0; + + /** + * The default return value of any method in this class when an + * error occurs or when processing fails (Currently set to -1). Use this to check if + * the information about the device in question was successfully obtained. + */ + public static final int DEVICEINFO_UNKNOWN = -1; + + private static final FileFilter CPU_FILTER = new FileFilter() { + @Override + public boolean accept(File pathname) { + String path = pathname.getName(); + //regex is slow, so checking char by char. + if (path.startsWith("cpu")) { + for (int i = 3; i < path.length(); i++) { + if (!Character.isDigit(path.charAt(i))) { + return false; + } + } + return true; + } + return false; + } + }; + + + /** + * Calculates the total RAM of the device through Android API or /proc/meminfo. + * + * @param c - Context object for current running activity. + * @return Total RAM that the device has, or DEVICEINFO_UNKNOWN = -1 in the event of an error. + */ + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + public static long getTotalMemory(Context c) { + // memInfo.totalMem not supported in pre-Jelly Bean APIs. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); + ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); + am.getMemoryInfo(memInfo); + if (memInfo != null) { + return memInfo.totalMem; + } else { + return DEVICEINFO_UNKNOWN; + } + } else { + long totalMem = DEVICEINFO_UNKNOWN; + try { + FileInputStream stream = new FileInputStream("/proc/meminfo"); + try { + totalMem = parseFileForValue("MemTotal", stream); + totalMem *= 1024; + } finally { + stream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + return totalMem; + } + } + + /** + * Method for reading the clock speed of a CPU core on the device. Will read from either + * {@code /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq} or {@code /proc/cpuinfo}. + * + * @return Clock speed of a core on the device, or -1 in the event of an error. + */ + public static int getCPUMaxFreqKHz() { + int maxFreq = DEVICEINFO_UNKNOWN; + try { + for (int i = 0; i < getNumberOfCPUCores(); i++) { + String filename = + "/sys/devices/system/cpu/cpu" + i + "/cpufreq/cpuinfo_max_freq"; + File cpuInfoMaxFreqFile = new File(filename); + if (cpuInfoMaxFreqFile.exists() && cpuInfoMaxFreqFile.canRead()) { + byte[] buffer = new byte[128]; + FileInputStream stream = new FileInputStream(cpuInfoMaxFreqFile); + try { + stream.read(buffer); + int endIndex = 0; + //Trim the first number out of the byte buffer. + while (Character.isDigit(buffer[endIndex]) && endIndex < buffer.length) { + endIndex++; + } + String str = new String(buffer, 0, endIndex); + Integer freqBound = Integer.parseInt(str); + if (freqBound > maxFreq) { + maxFreq = freqBound; + } + } catch (NumberFormatException e) { + //Fall through and use /proc/cpuinfo. + } finally { + stream.close(); + } + } + } + if (maxFreq == DEVICEINFO_UNKNOWN) { + FileInputStream stream = new FileInputStream("/proc/cpuinfo"); + try { + int freqBound = parseFileForValue("cpu MHz", stream); + freqBound *= 1024; //MHz -> kHz + if (freqBound > maxFreq) maxFreq = freqBound; + } finally { + stream.close(); + } + } + } catch (IOException e) { + maxFreq = DEVICEINFO_UNKNOWN; //Fall through and return unknown. + } + return maxFreq; + } + + /** + * Reads the number of CPU cores from the first available information from + * {@code /sys/devices/system/cpu/possible}, {@code /sys/devices/system/cpu/present}, + * then {@code /sys/devices/system/cpu/}. + * + * @return Number of CPU cores in the phone, or DEVICEINFO_UKNOWN = -1 in the event of an error. + */ + public static int getNumberOfCPUCores() { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { + // Gingerbread doesn't support giving a single application access to both cores, but a + // handful of devices (Atrix 4G and Droid X2 for example) were released with a dual-core + // chipset and Gingerbread; that can let an app in the background run without impacting + // the foreground application. But for our purposes, it makes them single core. + return 1; + } + int cores; + try { + cores = getCoresFromFileInfo("/sys/devices/system/cpu/possible"); + if (cores == DEVICEINFO_UNKNOWN) { + cores = getCoresFromFileInfo("/sys/devices/system/cpu/present"); + } + if (cores == DEVICEINFO_UNKNOWN) { + cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length; + } + } catch (SecurityException e) { + cores = DEVICEINFO_UNKNOWN; + } catch (NullPointerException e) { + cores = DEVICEINFO_UNKNOWN; + } + return cores; + } + + /** + * Tries to read file contents from the file location to determine the number of cores on device. + * + * @param fileLocation The location of the file with CPU information + * @return Number of CPU cores in the phone, or DEVICEINFO_UKNOWN = -1 in the event of an error. + */ + private static int getCoresFromFileInfo(String fileLocation) { + InputStream is = null; + try { + is = new FileInputStream(fileLocation); + BufferedReader buf = new BufferedReader(new InputStreamReader(is)); + String fileContents = buf.readLine(); + buf.close(); + return getCoresFromFileString(fileContents); + } catch (IOException e) { + return DEVICEINFO_UNKNOWN; + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + // Do nothing. + } + } + } + } + + /** + * Converts from a CPU core information format to number of cores. + * + * @param str The CPU core information string, in the format of "0-N" + * @return The number of cores represented by this string + */ + private static int getCoresFromFileString(String str) { + if (str == null || !str.matches("0-[\\d]+$")) { + return DEVICEINFO_UNKNOWN; + } + return Integer.valueOf(str.substring(2)) + 1; + } + + /** + * Helper method for reading values from system files, using a minimised buffer. + * + * @param textToMatch - Text in the system files to read for. + * @param stream - FileInputStream of the system file being read from. + * @return A numerical value following textToMatch in specified the system file. + * -1 in the event of a failure. + */ + private static int parseFileForValue(String textToMatch, FileInputStream stream) { + byte[] buffer = new byte[1024]; + try { + int length = stream.read(buffer); + for (int i = 0; i < length; i++) { + if (buffer[i] == '\n' || i == 0) { + if (buffer[i] == '\n') i++; + for (int j = i; j < length; j++) { + int textIndex = j - i; + //Text doesn't match query at some point. + if (buffer[j] != textToMatch.charAt(textIndex)) { + break; + } + //Text matches query here. + if (textIndex == textToMatch.length() - 1) { + return extractValue(buffer, j); + } + } + } + } + } catch (IOException e) { + //Ignore any exceptions and fall through to return unknown value. + } catch (NumberFormatException e) { + } + return DEVICEINFO_UNKNOWN; + } + + /** + * Helper method used by {@link #parseFileForValue(String, FileInputStream) parseFileForValue}. Parses + * the next available number after the match in the file being read and returns it as an integer. + * + * @param index - The index in the buffer array to begin looking. + * @return The next number on that line in the buffer, returned as an int. Returns + * DEVICEINFO_UNKNOWN = -1 in the event that no more numbers exist on the same line. + */ + private static int extractValue(byte[] buffer, int index) { + while (index < buffer.length && buffer[index] != '\n') { + if (Character.isDigit(buffer[index])) { + int start = index; + index++; + while (index < buffer.length && Character.isDigit(buffer[index])) { + index++; + } + String str = new String(buffer, 0, start, index - start); + return Integer.parseInt(str); + } + index++; + } + return DEVICEINFO_UNKNOWN; + } + + /** + * 获取当前剩余内存(ram) + * + * @param context + * @return + */ + public static long getAvailMemory(Context context) { + ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); + am.getMemoryInfo(mi); + return mi.availMem; + } + + /** + * 获取厂商信息 + * + * @return + */ + public static String getBrand() { + return Build.BRAND; + } + + /** + * 获取手机机型 + * + * @return + */ + public static String getModel() { + return Build.MODEL; + } + + /** + * 获取硬件信息(cpu型号) + * + * @return + */ + public static String getHardWare() { + try { + FileReader fr = new FileReader("/proc/cpuinfo"); + BufferedReader br = new BufferedReader(fr); + String text; + String last = ""; + while ((text = br.readLine()) != null) { + last = text; + } + //一般机型的cpu型号都会在cpuinfo文件的最后一行 + if (last.contains("Hardware")) { + String[] hardWare = last.split(":\\s+", 2); + return hardWare[1]; + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return Build.HARDWARE; + } + + + /** + * Level judgement based on current memory and CPU. + * + * @param context - Context object. + * @return + */ + public static int judgeDeviceLevel(Context context) { + int level; + //有一些设备不符合下述的判断规则,则走一个机型判断模式 + int specialDevice = judgeDeviceLevelInDeviceName(); + if (specialDevice >= 0) return specialDevice; + + int ramLevel = judgeMemory(context); + int cpuLevel = judgeCPU(); + if (ramLevel == 0 || ramLevel == 1 || cpuLevel == 0) { + level = DEVICE_LEVEL_LOW; + } else { + if (cpuLevel > 1) { + level = DEVICE_LEVEL_HIGH; + } else { + level = DEVICE_LEVEL_MID; + } + } + LogUtils.d(TAG,"DeviceLevel: " + level); + return level; + } + + /** + * -1 不是特定的高低端机型 + * @return + */ + private static int judgeDeviceLevelInDeviceName() { + String currentDeviceName = getDeviceName(); + for (String deviceName:upscaleDevice) { + if (deviceName.equals(currentDeviceName)) { + return DEVICE_LEVEL_HIGH; + } + } + + for (String deviceName:middleDevice) { + if (deviceName.equals(currentDeviceName)) { + return DEVICE_LEVEL_MID; + } + } + + for (String deviceName:lowDevice) { + if (deviceName.equals(currentDeviceName)) { + return DEVICE_LEVEL_LOW; + } + } + return -1; + } + + public static final String[] upscaleDevice = {"vivo X6S A","MHA-AL00","VKY-AL00","V1838A"}; + public static final String[] lowDevice = {}; + public static final String[] middleDevice = {"OPPO R11s","PAR-AL00","MI 8 Lite","ONEPLUS A6000","PRO 6","PRO 7 Plus"}; + + /** + * 评定内存的等级. + * + * @return + */ + private static int judgeMemory(Context context) { + long ramMB = getTotalMemory(context) / (1024 * 1024); + int level = -1; + if (ramMB <= 2000) { //2G或以下的最低档 + level = 0; + } else if (ramMB <= 3000) { //2-3G + level = 1; + } else if (ramMB <= 4000) { //4G档 2018主流中端机 + level = 2; + } else if (ramMB <= 6000) { //6G档 高端机 + level = 3; + } else { //6G以上 旗舰机配置 + level = 4; + } + return level; + } + + /** + * 评定CPU等级.(按频率和厂商型号综合判断) + * + * @return + */ + private static int judgeCPU() { + int level = 0; + String cpuName = getHardWare(); + int freqMHz = getCPUMaxFreqKHz() / 1024; + + //一个不符合下述规律的高级白名单 + //如果可以获取到CPU型号名称 -> 根据不同的名称走不同判定策略 + if (!TextUtils.isEmpty(cpuName)) { + if (cpuName.contains("qcom") || cpuName.contains("Qualcomm")) { //高通骁龙 + return judgeQualcommCPU(cpuName, freqMHz); + } else if (cpuName.contains("hi") || cpuName.contains("kirin")) { //海思麒麟 + return judgeSkinCPU(cpuName, freqMHz); + } else if (cpuName.contains("MT")) {//联发科 + return judgeMTCPU(cpuName, freqMHz); + } + } + + //cpu型号无法获取的普通规则 + if (freqMHz <= 1600) { //1.5G 低端 + level = 0; + } else if (freqMHz <= 1950) { //2GHz 低中端 + level = 1; + } else if (freqMHz <= 2500) { //2.2 2.3g 中高端 + level = 2; + } else { //高端 + level = 3; + } + return level; + } + + /** + * 联发科芯片等级判定 + * + * @return + */ + private static int judgeMTCPU(String cpuName, int freqMHz) { + //P60之前的全是低端机 MT6771V/C + int level = 0; + int mtCPUVersion = getMTCPUVersion(cpuName); + if (mtCPUVersion == -1) { + //读取不出version 按照一个比较严格的方式来筛选出高端机 + if (freqMHz <= 1600) { //1.5G 低端 + level = 0; + } else if (freqMHz <= 2200) { //2GHz 低中端 + level = 1; + } else if (freqMHz <= 2700) { //2.2 2.3g 中高端 + level = 2; + } else { //高端 + level = 3; + } + } else if (mtCPUVersion < 6771) { + //均为中低端机 + if (freqMHz <= 1600) { //1.5G 低端 + level = 0; + } else { //2GHz 中端 + level = 1; + } + } else { + if (freqMHz <= 1600) { //1.5G 低端 + level = 0; + } else if (freqMHz <= 1900) { //2GHz 低中端 + level = 1; + } else if (freqMHz <= 2500) { //2.2 2.3g 中高端 + level = 2; + } else { //高端 + level = 3; + } + } + + return level; + } + + /** + * 通过联发科CPU型号定义 -> 获取cpu version + * + * @param cpuName + * @return + */ + private static int getMTCPUVersion(String cpuName) { + //截取MT后面的四位数字 + int cpuVersion = -1; + if (cpuName.length() > 5) { + String cpuVersionStr = cpuName.substring(2, 6); + try { + cpuVersion = Integer.valueOf(cpuVersionStr); + } catch (NumberFormatException exception) { + exception.printStackTrace(); + } + } + + return cpuVersion; + } + + /** + * 高通骁龙芯片等级判定 + * + * @return + */ + private static int judgeQualcommCPU(String cpuName, int freqMHz) { + int level = 0; + //xxxx inc MSM8937 比较老的芯片 + //7 8 xxx inc SDM710 + if (cpuName.contains("MSM")) { + //老芯片 + if (freqMHz <= 1600) { //1.5G 低端 + level = 0; + } else { //2GHz 低中端 + level = 1; + } + } else { + //新的芯片 + if (freqMHz <= 1600) { //1.5G 低端 + level = 0; + } else if (freqMHz <= 2000) { //2GHz 低中端 + level = 1; + } else if (freqMHz <= 2500) { //2.2 2.3g 中高端 + level = 2; + } else { //高端 + level = 3; + } + } + + return level; + } + + /** + * 麒麟芯片等级判定 + * + * @param freqMHz + * @return + */ + private static int judgeSkinCPU(String cpuName, int freqMHz) { + //型号 -> kirin710之后 & 最高核心频率 + int level = 0; + if (cpuName.startsWith("hi")) { + //这个是海思的芯片中低端 + if (freqMHz <= 1600) { //1.5G 低端 + level = 0; + } else if (freqMHz <= 2000) { //2GHz 低中端 + level = 1; + } + } else { + //这个是海思麒麟的芯片 + if (freqMHz <= 1600) { //1.5G 低端 + level = 0; + } else if (freqMHz <= 2000) { //2GHz 低中端 + level = 1; + } else if (freqMHz <= 2500) { //2.2 2.3g 中高端 + level = 2; + } else { //高端 + level = 3; + } + } + + return level; + } + + public static final String Nexus_6P = "Nexus 6P"; + + /** + * 获取设备名 + * + * @return + */ + public static String getDeviceName() { + String deviceName = ""; + if (Build.MODEL != null) deviceName = Build.MODEL; + LogUtils.e(TAG,"deviceName: " + deviceName); + return deviceName; + } +} diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/LogUtils.kt b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/LogUtils.kt new file mode 100644 index 000000000..4c1a5252d --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/LogUtils.kt @@ -0,0 +1,57 @@ +/* + * MIT License + * + * Copyright (c) 2023 Agora Community + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.agora.beautyapi.faceunity.utils + +import io.agora.base.internal.Logging + +object LogUtils { + private const val beautyType = "FaceUnity" + + + @JvmStatic + fun i(tag: String, content: String, vararg args: Any) { + val consoleMessage = "[BeautyAPI][$beautyType] : ${String.format(content, args)}" + Logging.log(Logging.Severity.LS_INFO, tag, consoleMessage) + } + + @JvmStatic + fun d(tag: String, content: String, vararg args: Any) { + val consoleMessage = "[BeautyAPI][$beautyType] : ${String.format(content, args)}" + Logging.d(tag, consoleMessage) + } + + @JvmStatic + fun w(tag: String, content: String, vararg args: Any){ + val consoleMessage = "[BeautyAPI][$beautyType] : ${String.format(content, args)}" + Logging.w(tag, consoleMessage) + } + + @JvmStatic + fun e(tag: String, content: String, vararg args: Any){ + val consoleMessage = "[BeautyAPI][$beautyType] : ${String.format(content, args)}" + Logging.e(tag, consoleMessage) + } + +} \ No newline at end of file diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/StatsHelper.kt b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/StatsHelper.kt new file mode 100644 index 000000000..cb4cf1292 --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/StatsHelper.kt @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) 2023 Agora Community + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.agora.beautyapi.faceunity.utils + +import android.os.Handler +import android.os.Looper +import io.agora.beautyapi.faceunity.BeautyStats +import kotlin.math.max +import kotlin.math.min + +class StatsHelper( + private val statsDuration: Long, + private val onStatsChanged: (BeautyStats) -> Unit +) { + + private val mMainHandler = Handler(Looper.getMainLooper()) + private var mStartTime = 0L + private var mCostList = mutableListOf() + private var mCostMax = 0L + private var mCostMin = Long.MAX_VALUE + + fun once(cost: Long) { + val curr = System.currentTimeMillis() + if (mStartTime == 0L) { + mStartTime = curr + } else if (curr - mStartTime >= statsDuration) { + mStartTime = curr + var total = 0L + mCostList.forEach { + total += it + } + val average = total / mCostList.size + val costMin = mCostMin + val costMax = mCostMax + mMainHandler.post { + onStatsChanged.invoke(BeautyStats(costMin, costMax, average)) + } + + mCostList.clear() + mCostMax = 0L + mCostMin = Long.MAX_VALUE + } + + mCostList.add(cost) + mCostMax = max(mCostMax, cost) + mCostMin = min(mCostMin, cost) + } + + fun reset() { + mMainHandler.removeCallbacksAndMessages(null) + mStartTime = 0 + mCostList.clear() + mCostMax = 0L + mCostMin = Long.MAX_VALUE + } + + +} \ No newline at end of file diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/EGLContextHelper.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/EGLContextHelper.java new file mode 100644 index 000000000..97b3c7a53 --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/EGLContextHelper.java @@ -0,0 +1,210 @@ +/* + * MIT License + * + * Copyright (c) 2023 Agora Community + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.agora.beautyapi.faceunity.utils.egl; + +import static android.opengl.EGL14.EGL_CONTEXT_CLIENT_VERSION; + +import android.opengl.GLDebugHelper; + +import javax.microedition.khronos.egl.EGL10; +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.egl.EGLContext; +import javax.microedition.khronos.egl.EGLDisplay; +import javax.microedition.khronos.egl.EGLSurface; + +import io.agora.beautyapi.faceunity.utils.LogUtils; + +public class EGLContextHelper { + private static final String DEBUG_TAG = "EGLContextManager"; + private final int mRedSize = 8; + private final int mGreenSize = 8; + private final int mBlueSize = 8; + private final int mAlphaSize = 0; + private final int mDepthSize = 16; + private final int mStencilSize = 0; + private final int mRenderType = 4; + public EGLContextHelper(){} + + public void initEGL(EGLContext shareContext) throws Exception { + mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(), + GLDebugHelper.CONFIG_CHECK_GL_ERROR + | GLDebugHelper.CONFIG_CHECK_THREAD, null); + + if (mEGL == null) { + throw new Exception("Couldn't get EGL"); + } + + mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); + + if (mGLDisplay == null) { + throw new Exception("Couldn't get display for GL"); + } + + int[] curGLVersion = new int[2]; + mEGL.eglInitialize(mGLDisplay, curGLVersion); + + LogUtils.i(DEBUG_TAG, "GL version = " + curGLVersion[0] + "." + + curGLVersion[1]); + + int[] num_config = new int[1]; + if(!mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, null, 1, + num_config)){ + throw new IllegalArgumentException("eglChooseConfig failed"); + } + int numConfigs = num_config[0]; + if (numConfigs <= 0) { + throw new IllegalArgumentException( + "No configs match configSpec"); + } + + EGLConfig[] configs = new EGLConfig[numConfigs]; + if (!mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, numConfigs, + num_config)) { + throw new IllegalArgumentException("eglChooseConfig#2 failed"); + } + mGLConfig = chooseConfig(mEGL, mGLDisplay, configs); + if (mGLConfig == null) { + mGLConfig = configs[0]; + } + + int[] surfaceAttribs = { + EGL10.EGL_WIDTH, 1, + EGL10.EGL_HEIGHT, 1, + EGL10.EGL_NONE + }; + mGLSurface = mEGL.eglCreatePbufferSurface(mGLDisplay, mGLConfig, surfaceAttribs); + + if (mGLSurface == null) { + throw new Exception("Couldn't create new surface"); + } + + int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE}; + mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig, + shareContext, attrib_list); + + if (mGLContext == null) { + throw new Exception("Couldn't create new context"); + } + + +// if (!mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext)) { +// throw new Exception("Failed to eglMakeCurrent"); +// } + + } + + public EGLContext getEGLContext() { + return mGLContext; + } + + public EGLDisplay getGLDisplay() { + return mGLDisplay; + } + + public EGLConfig getGLConfig() { + return mGLConfig; + } + + public EGLSurface getGLSurface() { + return mGLSurface; + } + + public EGL10 getEGL() { + return mEGL; + } + + EGL10 mEGL; + EGLDisplay mGLDisplay; + EGLConfig mGLConfig; + EGLSurface mGLSurface; + EGLContext mGLContext; + + int[] mConfigSpec = new int[]{ + EGL10.EGL_RED_SIZE, mRedSize, + EGL10.EGL_GREEN_SIZE, mGreenSize, + EGL10.EGL_BLUE_SIZE, mBlueSize, + EGL10.EGL_ALPHA_SIZE, mAlphaSize, + EGL10.EGL_DEPTH_SIZE, mDepthSize, + EGL10.EGL_STENCIL_SIZE, mStencilSize, + EGL10.EGL_RENDERABLE_TYPE, mRenderType,//egl版本 2.0 + EGL10.EGL_NONE}; + + public void release() { + mEGL.eglMakeCurrent(mGLDisplay, EGL10.EGL_NO_SURFACE, + EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); + mEGL.eglDestroySurface(mGLDisplay, mGLSurface); + mEGL.eglDestroyContext(mGLDisplay, mGLContext); + mEGL.eglTerminate(mGLDisplay); + + LogUtils.i(DEBUG_TAG, "GL Cleaned up"); + } + + public boolean eglMakeCurrent(){ + if(mGLContext == EGL10.EGL_NO_CONTEXT){ + return false; + }else{ + return mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext); + } + } + + public boolean eglMakeNoCurrent(){ + return mEGL.eglMakeCurrent(mGLDisplay, EGL10.EGL_NO_SURFACE, + EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); + } + + private EGLConfig chooseConfig(EGL10 egl, EGLDisplay display, + EGLConfig[] configs) { + for (EGLConfig config : configs) { + int d = findConfigAttrib(egl, display, config, + EGL10.EGL_DEPTH_SIZE, 0); + int s = findConfigAttrib(egl, display, config, + EGL10.EGL_STENCIL_SIZE, 0); + if ((d >= mDepthSize) && (s >= mStencilSize)) { + int r = findConfigAttrib(egl, display, config, + EGL10.EGL_RED_SIZE, 0); + int g = findConfigAttrib(egl, display, config, + EGL10.EGL_GREEN_SIZE, 0); + int b = findConfigAttrib(egl, display, config, + EGL10.EGL_BLUE_SIZE, 0); + int a = findConfigAttrib(egl, display, config, + EGL10.EGL_ALPHA_SIZE, 0); + if ((r == mRedSize) && (g == mGreenSize) + && (b == mBlueSize) && (a == mAlphaSize)) { + return config; + } + } + } + return null; + } + + private int findConfigAttrib(EGL10 egl, EGLDisplay display, + EGLConfig config, int attribute, int defaultValue) { + int[] value = new int[1]; + if (egl.eglGetConfigAttrib(display, config, attribute, value)) { + return value[0]; + } + return defaultValue; + } +} diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLCopyHelper.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLCopyHelper.java new file mode 100644 index 000000000..b475f39d9 --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLCopyHelper.java @@ -0,0 +1,84 @@ +/* + * MIT License + * + * Copyright (c) 2023 Agora Community + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.agora.beautyapi.faceunity.utils.egl; + +import android.opengl.GLES11Ext; +import android.opengl.GLES20; +import android.opengl.GLES30; + +public class GLCopyHelper { + private final int bufferCount; + + public GLCopyHelper(){ + this(1); + } + + public GLCopyHelper(int bufferCount){ + this.bufferCount = bufferCount; + } + + private int[] mDstFrameBuffer; + private int[] mSrcFrameBuffer; + + public void copy2DTextureToOesTexture( + int srcTexture, + int dstTexture, + int width, int height, + int index){ + if(mDstFrameBuffer == null){ + mDstFrameBuffer = new int[bufferCount]; + GLES20.glGenFramebuffers(bufferCount, mDstFrameBuffer, 0); + } + + if(mSrcFrameBuffer == null){ + mSrcFrameBuffer = new int[bufferCount]; + GLES20.glGenFramebuffers(bufferCount, mSrcFrameBuffer, 0); + } + + GLES30.glBindFramebuffer(GLES30.GL_READ_FRAMEBUFFER, mSrcFrameBuffer[index]); + GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, srcTexture); + GLES30.glFramebufferTexture2D(GLES30.GL_READ_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, srcTexture, 0); + GLES30.glBindFramebuffer(GLES30.GL_DRAW_FRAMEBUFFER, mDstFrameBuffer[index]); + GLES30.glFramebufferTexture2D(GLES30.GL_DRAW_FRAMEBUFFER, + GLES30.GL_COLOR_ATTACHMENT0, GLES11Ext.GL_TEXTURE_EXTERNAL_OES, dstTexture, 0); + GLES30.glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GLES30.GL_COLOR_BUFFER_BIT, GLES30.GL_LINEAR); + GLES30.glBindFramebuffer(GLES30.GL_DRAW_FRAMEBUFFER, 0); + GLES30.glBindFramebuffer(GLES30.GL_READ_FRAMEBUFFER, 0); + GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); + GLES30.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0); + } + + public void release(){ + if(mDstFrameBuffer != null){ + GLES20.glDeleteFramebuffers(mDstFrameBuffer.length, mDstFrameBuffer, 0); + mDstFrameBuffer = null; + } + + if(mSrcFrameBuffer != null){ + GLES20.glDeleteFramebuffers(mSrcFrameBuffer.length, mSrcFrameBuffer, 0); + mSrcFrameBuffer = null; + } + } +} diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java new file mode 100644 index 000000000..e7588a7e6 --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java @@ -0,0 +1,204 @@ +package io.agora.beautyapi.faceunity.utils.egl; + +import android.graphics.Matrix; +import android.opengl.GLES11Ext; +import android.opengl.GLES20; + +import io.agora.base.internal.video.EglBase; +import io.agora.base.internal.video.GlRectDrawer; +import io.agora.base.internal.video.RendererCommon; + +public class GLFrameBuffer { + + private int mFramebufferId = -1; + private int mTextureId = -1; + private int mWidth, mHeight, mRotation; + private boolean isFlipV, isFlipH, isTextureInner, isTextureChanged, isSizeChanged; + + private RendererCommon.GlDrawer drawer; + + private float[] mTexMatrix = GLUtils.IDENTITY_MATRIX; + + public GLFrameBuffer() { + + } + + public boolean setSize(int width, int height) { + if (mWidth != width || mHeight != height) { + mWidth = width; + mHeight = height; + isSizeChanged = true; + return true; + } + return false; + } + + public void setRotation(int rotation) { + if (mRotation != rotation) { + mRotation = rotation; + } + } + + public void setFlipV(boolean flipV) { + if (isFlipV != flipV) { + isFlipV = flipV; + } + } + + public void setFlipH(boolean flipH) { + if (isFlipH != flipH) { + isFlipH = flipH; + } + } + + public void setTextureId(int textureId){ + if(mTextureId != textureId){ + deleteTexture(); + mTextureId = textureId; + isTextureChanged = true; + } + } + + public int getTextureId(){ + return mTextureId; + } + + public void setTexMatrix(float[] matrix) { + if (matrix != null) { + mTexMatrix = matrix; + } else { + mTexMatrix = GLUtils.IDENTITY_MATRIX; + } + } + + public void resetTransform(){ + mTexMatrix = GLUtils.IDENTITY_MATRIX; + isFlipH = isFlipV = false; + mRotation = 0; + } + + public int process(int textureId, int textureType) { + if (mWidth <= 0 && mHeight <= 0) { + throw new RuntimeException("setSize firstly!"); + } + + if(mTextureId == -1){ + mTextureId = createTexture(mWidth, mHeight); + bindFramebuffer(mTextureId); + isTextureInner = true; + }else if(isTextureInner && isSizeChanged){ + GLES20.glDeleteTextures(1, new int[]{mTextureId}, 0); + mTextureId = createTexture(mWidth, mHeight); + bindFramebuffer(mTextureId); + }else if(isTextureChanged){ + bindFramebuffer(mTextureId); + } + isTextureChanged = false; + isSizeChanged = false; + + if(drawer == null){ + drawer = new GlRectDrawer(); + } + + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFramebufferId); + GLUtils.checkGlError("glBindFramebuffer"); + + Matrix transform = RendererCommon.convertMatrixToAndroidGraphicsMatrix(mTexMatrix); + transform.preTranslate(0.5f, 0.5f); + transform.preRotate(mRotation, 0.f, 0.f); + transform.preScale( + isFlipH ? -1.f: 1.f, + isFlipV ? -1.f: 1.f + ); + transform.preTranslate(-0.5f, -0.5f); + float[] matrix = RendererCommon.convertMatrixFromAndroidGraphicsMatrix(transform); + + synchronized (EglBase.lock){ + if(textureType == GLES11Ext.GL_TEXTURE_EXTERNAL_OES){ + drawer.drawOes(textureId, matrix, mWidth, mHeight, 0, 0, mWidth, mHeight); + }else{ + drawer.drawRgb(textureId, matrix, mWidth, mHeight, 0, 0, mWidth, mHeight); + } + } + + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_NONE); + GLES20.glFinish(); + + return mTextureId; + } + + public void release(){ + deleteTexture(); + deleteFramebuffer(); + + if(drawer != null){ + drawer.release(); + drawer = null; + } + } + + + private void deleteFramebuffer() { + if (mFramebufferId != -1) { + GLES20.glDeleteFramebuffers(1, new int[]{mFramebufferId}, 0); + mFramebufferId = -1; + } + } + + public int createTexture(int width, int height){ + int[] textures = new int[1]; + GLES20.glGenTextures(1, textures, 0); + GLUtils.checkGlError("glGenTextures"); + int textureId = textures[0]; + + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, + GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); + + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, GLES20.GL_NONE); + + return textureId; + } + + public void resizeTexture(int textureId, int width, int height) { + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, + GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, GLES20.GL_NONE); + } + + private void deleteTexture() { + if (isTextureInner && mTextureId != -1) { + GLES20.glDeleteTextures(1, new int[]{mTextureId}, 0); + } + isTextureInner = false; + mTextureId = -1; + } + + private void bindFramebuffer(int textureId) { + if(mFramebufferId == -1){ + int[] framebuffers = new int[1]; + GLES20.glGenFramebuffers(1, framebuffers, 0); + GLUtils.checkGlError("glGenFramebuffers"); + mFramebufferId = framebuffers[0]; + } + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFramebufferId); + GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, + GLES20.GL_COLOR_ATTACHMENT0, + GLES20.GL_TEXTURE_2D, + textureId, 0); + + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, GLES20.GL_NONE); + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_NONE); + } + +} diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLTextureBufferQueue.kt b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLTextureBufferQueue.kt new file mode 100644 index 000000000..c8d193f8f --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLTextureBufferQueue.kt @@ -0,0 +1,180 @@ +/* + * MIT License + * + * Copyright (c) 2023 Agora Community + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.agora.beautyapi.faceunity.utils.egl + +import android.opengl.GLES20 +import android.util.Log +import android.util.Size +import java.util.concurrent.ConcurrentLinkedQueue + +class GLTextureBufferQueue( + private val glFrameBuffer: GLFrameBuffer = GLFrameBuffer(), + private val cacheCount: Int = 6, + private val loggable: Boolean = false +) { + private val TAG = "GLTextureBufferQueue" + + private var cacheIndex = 0 + private val cacheTextureOuts = arrayOfNulls(cacheCount) + private val textureIdQueue = ConcurrentLinkedQueue() + + + fun enqueue(iN: TextureIn): Int { + var size = textureIdQueue.size + if (size < cacheCount) { + var out = cacheTextureOuts[cacheIndex] + val outSize = when (iN.rotation) { + 90, 270 -> Size(iN.height, iN.width) + else -> Size(iN.width, iN.height) + } + + if (out == null) { + val textureId = glFrameBuffer.createTexture(outSize.width, outSize.height) + out = TextureOut( + 0, + textureId, + GLES20.GL_TEXTURE_2D, + outSize.width, + outSize.height, + iN.isFrontCamera, + iN.isMirror, + ) + cacheTextureOuts[cacheIndex] = out + } else if (out.width != outSize.width || out.height != outSize.height) { + glFrameBuffer.resizeTexture(out.textureId, outSize.width, outSize.height) + out = TextureOut( + 0, + out.textureId, + out.textureType, + outSize.width, + outSize.height, + iN.isFrontCamera, + iN.isMirror, + ) + cacheTextureOuts[cacheIndex] = out + } else if(out.isFrontCamera != iN.isFrontCamera){ + out = TextureOut( + 0, + out.textureId, + out.textureType, + out.width, + out.height, + iN.isFrontCamera, + iN.isMirror, + ) + cacheTextureOuts[cacheIndex] = out + } + + glFrameBuffer.textureId = out.textureId + glFrameBuffer.setSize(out.width, out.height) + glFrameBuffer.resetTransform() + glFrameBuffer.setRotation(iN.rotation) + if (iN.transform != null) { + glFrameBuffer.setTexMatrix(iN.transform) + var flipH = iN.isFrontCamera + if(iN.isMirror){ + flipH = !flipH + } + glFrameBuffer.setFlipH(flipH) + } else { + var flipH = !iN.isFrontCamera + if(iN.isMirror){ + flipH = !flipH + } + glFrameBuffer.setFlipH(flipH) + } + glFrameBuffer.setFlipV(iN.flipV) + glFrameBuffer.process(iN.textureId, iN.textureType) + out.index = cacheIndex + out.tag = iN.tag + textureIdQueue.offer(out) + if(loggable){ + Log.d(TAG, "TextureIdQueue enqueue index=$cacheIndex, size=$size") + } + cacheIndex = (cacheIndex + 1) % cacheCount + size++ + + } else { + if(loggable){ + Log.e(TAG, "TextureIdQueue is full!!") + } + } + + return size + } + + fun dequeue(remove: Boolean = true): TextureOut? { + val size = textureIdQueue.size + val poll = if(remove){ + textureIdQueue.poll() + }else{ + textureIdQueue.peek() + } + if(loggable){ + Log.d(TAG, "TextureIdQueue dequeue index=${poll?.index}, size=$size") + } + return poll + } + + fun reset() { + cacheIndex = 0 + textureIdQueue.clear() + } + + fun release() { + cacheIndex = 0 + cacheTextureOuts.forEachIndexed { index, textureOut -> + if (textureOut != null) { + GLES20.glDeleteTextures(1, intArrayOf(textureOut.textureId), 0) + cacheTextureOuts[index] = null + } + } + textureIdQueue.clear() + glFrameBuffer.release() + } + + data class TextureIn( + val textureId: Int, + val textureType: Int, + val width: Int, + val height: Int, + val rotation: Int, + val flipV: Boolean, + val isFrontCamera: Boolean, + val isMirror: Boolean, + val transform: FloatArray?, + val tag: Any? = null + ) + + data class TextureOut( + var index: Int = 0, + val textureId: Int, + val textureType: Int, + val width: Int, + val height: Int, + val isFrontCamera: Boolean, + var tag: Any? = null + ) +} \ No newline at end of file diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLUtils.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLUtils.java new file mode 100644 index 000000000..e56f743ec --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLUtils.java @@ -0,0 +1,279 @@ +/* + * MIT License + * + * Copyright (c) 2023 Agora Community + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.agora.beautyapi.faceunity.utils.egl; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.ImageFormat; +import android.graphics.Rect; +import android.graphics.YuvImage; +import android.opengl.GLES11Ext; +import android.opengl.GLES20; +import android.opengl.Matrix; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.util.Objects; + +import javax.microedition.khronos.egl.EGL10; +import javax.microedition.khronos.egl.EGLContext; + +import io.agora.beautyapi.faceunity.utils.LogUtils; + +public class GLUtils { + private static final String TAG = "GLUtils"; + public static final float[] IDENTITY_MATRIX = new float[16]; + + static { + Matrix.setIdentityM(IDENTITY_MATRIX, 0); + } + + private GLUtils() { + } + + public static Bitmap getTexture2DImage(int textureID, int width, int height) { + try { + int[] oldFboId = new int[1]; + GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, IntBuffer.wrap(oldFboId)); + + int[] framebuffers = new int[1]; + GLES20.glGenFramebuffers(1, framebuffers, 0); + int framebufferId = framebuffers[0]; + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebufferId); + + int[] renderbuffers = new int[1]; + GLES20.glGenRenderbuffers(1, renderbuffers, 0); + int renderId = renderbuffers[0]; + GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderId); + GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height); + + GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, textureID, 0); + GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, renderId); + if (GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER) != GLES20.GL_FRAMEBUFFER_COMPLETE) { + LogUtils.e(TAG, "Framebuffer error"); + } + + ByteBuffer rgbaBuf = ByteBuffer.allocateDirect(width * height * 4); + rgbaBuf.position(0); + GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, rgbaBuf); + + Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + bitmap.copyPixelsFromBuffer(rgbaBuf); + + GLES20.glDeleteRenderbuffers(1, IntBuffer.wrap(framebuffers)); + GLES20.glDeleteFramebuffers(1, IntBuffer.allocate(framebufferId)); + + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, oldFboId[0]); + + return bitmap; + } catch (Exception e) { + LogUtils.e(TAG, e.toString()); + } + return null; + } + + public static Bitmap getTextureOESImage(int textureID, int width, int height) { + try { + int[] oldFboId = new int[1]; + GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, IntBuffer.wrap(oldFboId)); + + int[] framebuffers = new int[1]; + GLES20.glGenFramebuffers(1, framebuffers, 0); + int framebufferId = framebuffers[0]; + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebufferId); + + int[] renderbuffers = new int[1]; + GLES20.glGenRenderbuffers(1, renderbuffers, 0); + int renderId = renderbuffers[0]; + GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderId); + GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height); + + GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureID, 0); + GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, renderId); + if (GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER) != GLES20.GL_FRAMEBUFFER_COMPLETE) { + LogUtils.e(TAG, "Framebuffer error"); + } + + ByteBuffer rgbaBuf = ByteBuffer.allocateDirect(width * height * 4); + rgbaBuf.position(0); + GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, rgbaBuf); + + Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + bitmap.copyPixelsFromBuffer(rgbaBuf); + + GLES20.glDeleteRenderbuffers(1, IntBuffer.wrap(framebuffers)); + GLES20.glDeleteFramebuffers(1, IntBuffer.allocate(framebufferId)); + + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, oldFboId[0]); + + return bitmap; + } catch (Exception e) { + LogUtils.e(TAG, e.toString()); + } + return null; + } + + public static Bitmap nv21ToBitmap(byte[] nv21, int width, int height) { + Bitmap bitmap = null; + try { + YuvImage image = new YuvImage(nv21, ImageFormat.NV21, width, height, null); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + image.compressToJpeg(new Rect(0, 0, width, height), 80, stream); + bitmap = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size()); + stream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return bitmap; + } + + private static Bitmap readBitmap(int width, int height) { + ByteBuffer rgbaBuf = ByteBuffer.allocateDirect(width * height * 4); + rgbaBuf.position(0); + GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, rgbaBuf); + + Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + bitmap.copyPixelsFromBuffer(rgbaBuf); + return bitmap; + } + + public static float[] createTransformMatrix(int rotation, boolean flipH, boolean flipV) { + float[] renderMVPMatrix = new float[16]; + float[] tmp = new float[16]; + Matrix.setIdentityM(tmp, 0); + + boolean _flipH = flipH; + boolean _flipV = flipV; + if (rotation % 180 != 0) { + _flipH = flipV; + _flipV = flipH; + } + + if (_flipH) { + Matrix.rotateM(tmp, 0, tmp, 0, 180, 0, 1f, 0); + } + if (_flipV) { + Matrix.rotateM(tmp, 0, tmp, 0, 180, 1f, 0f, 0); + } + + float _rotation = rotation; + if (_rotation != 0) { + if (_flipH != _flipV) { + _rotation *= -1; + } + Matrix.rotateM(tmp, 0, tmp, 0, _rotation, 0, 0, 1); + } + + Matrix.setIdentityM(renderMVPMatrix, 0); + Matrix.multiplyMM(renderMVPMatrix, 0, tmp, 0, renderMVPMatrix, 0); + return renderMVPMatrix; + } + + public static EGLContext getCurrGLContext() { + EGL10 egl = (EGL10) javax.microedition.khronos.egl.EGLContext.getEGL(); + if (egl != null && !Objects.equals(egl.eglGetCurrentContext(), EGL10.EGL_NO_CONTEXT)) { + return egl.eglGetCurrentContext(); + } + return null; + } + + public static void checkGlError(String op) { + int error = GLES20.glGetError(); + if (error != GLES20.GL_NO_ERROR) { + String msg = op + ": glError 0x" + Integer.toHexString(error); + LogUtils.e(TAG, msg); + throw new RuntimeException(msg); + } + } + + public static int createProgram(String vertexSource, String fragmentSource) { + int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource); + if (vertexShader == 0) { + return 0; + } + int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource); + if (pixelShader == 0) { + return 0; + } + int program = GLES20.glCreateProgram(); + checkGlError("glCreateProgram"); + if (program == 0) { + LogUtils.e(TAG, "Could not create program"); + } + GLES20.glAttachShader(program, vertexShader); + checkGlError("glAttachShader"); + GLES20.glAttachShader(program, pixelShader); + checkGlError("glAttachShader"); + GLES20.glLinkProgram(program); + int[] linkStatus = new int[1]; + GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0); + if (linkStatus[0] != GLES20.GL_TRUE) { + LogUtils.e(TAG, "Could not link program: "); + LogUtils.e(TAG, GLES20.glGetProgramInfoLog(program)); + GLES20.glDeleteProgram(program); + program = 0; + } + return program; + } + + public static int loadShader(int shaderType, String source) { + int shader = GLES20.glCreateShader(shaderType); + checkGlError("glCreateShader type=" + shaderType); + GLES20.glShaderSource(shader, source); + GLES20.glCompileShader(shader); + int[] compiled = new int[1]; + GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0); + if (compiled[0] == 0) { + LogUtils.e(TAG, "Could not compile shader " + shaderType + ":"); + LogUtils.e(TAG, " " + GLES20.glGetShaderInfoLog(shader)); + GLES20.glDeleteShader(shader); + shader = 0; + } + return shader; + } + + public static int createTexture(int textureTarget, Bitmap bitmap, int minFilter, + int magFilter, int wrapS, int wrapT) { + int[] textureHandle = new int[1]; + + GLES20.glGenTextures(1, textureHandle, 0); + checkGlError("glGenTextures"); + GLES20.glBindTexture(textureTarget, textureHandle[0]); + checkGlError("glBindTexture " + textureHandle[0]); + GLES20.glTexParameterf(textureTarget, GLES20.GL_TEXTURE_MIN_FILTER, minFilter); + GLES20.glTexParameterf(textureTarget, GLES20.GL_TEXTURE_MAG_FILTER, magFilter); //线性插值 + GLES20.glTexParameteri(textureTarget, GLES20.GL_TEXTURE_WRAP_S, wrapS); + GLES20.glTexParameteri(textureTarget, GLES20.GL_TEXTURE_WRAP_T, wrapT); + + if (bitmap != null) { + android.opengl.GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); + } + + checkGlError("glTexParameter"); + return textureHandle[0]; + } +} diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/TextureProcessHelper.kt b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/TextureProcessHelper.kt new file mode 100644 index 000000000..1451750b4 --- /dev/null +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/TextureProcessHelper.kt @@ -0,0 +1,214 @@ +/* + * MIT License + * + * Copyright (c) 2023 Agora Community + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.agora.beautyapi.faceunity.utils.egl + +import android.opengl.GLES20 +import io.agora.beautyapi.faceunity.utils.LogUtils +import java.util.concurrent.Callable +import java.util.concurrent.ConcurrentLinkedQueue +import java.util.concurrent.CountDownLatch +import java.util.concurrent.Executors +import java.util.concurrent.Future +import javax.microedition.khronos.egl.EGLContext + +class TextureProcessHelper( + private val cacheCount: Int = 2 +) { + private val TAG = "TextureProcessHelper" + private val glTextureBufferQueueIn = GLTextureBufferQueue(cacheCount = cacheCount, loggable = true) + private val glTextureBufferQueueOut = GLTextureBufferQueue(cacheCount = cacheCount, loggable = false) + private val glFrameBuffer = GLFrameBuffer() + private val futureQueue = ConcurrentLinkedQueue>() + private val workerThread = Executors.newSingleThreadExecutor() + private val eglContextHelper = + EGLContextHelper() + private var eglContextBase: EGLContext? = null + private var isReleased = false + private var filter: ((GLTextureBufferQueue.TextureOut) -> Int)? = null + private var isBegin = false + private var frameIndex = 0 + + fun setFilter(filter: (GLTextureBufferQueue.TextureOut) -> Int) { + this.filter = filter + } + + fun process( + texId: Int, texType: Int, + width: Int, height: Int, rotation: Int, + transform: FloatArray, + isFrontCamera: Boolean, + isMirror: Boolean + ): Int { + if (isReleased) { + return -1 + } + val currGLContext = GLUtils.getCurrGLContext() ?: return -1 + + if (eglContextBase == null) { + eglContextBase = currGLContext + executeSync { + eglContextHelper.initEGL(eglContextBase) + eglContextHelper.eglMakeCurrent() + } + } else if (eglContextBase != currGLContext) { + eglContextBase = currGLContext + executeSync { + eglContextHelper.release() + eglContextHelper.initEGL(eglContextBase) + eglContextHelper.eglMakeCurrent() + } + } + + glTextureBufferQueueIn.enqueue( + GLTextureBufferQueue.TextureIn( + texId, + texType, + width, + height, + rotation, + false, + isFrontCamera, + isMirror, + transform, + frameIndex + ) + ) + frameIndex ++ + + if (isReleased) { + return -1 + } + + futureQueue.offer(workerThread.submit(Callable { + if (isReleased) { + return@Callable -2 + } + + val frame = glTextureBufferQueueIn.dequeue(false) ?: return@Callable -2 + val filterTexId = filter?.invoke(frame) ?: -1 + if (filterTexId >= 0) { + glTextureBufferQueueOut.enqueue( + GLTextureBufferQueue.TextureIn( + filterTexId, + GLES20.GL_TEXTURE_2D, + frame.width, + frame.height, + 0, + false, + false, + true, + null, + frame.tag + ) + ) + } else { + glTextureBufferQueueOut.enqueue( + GLTextureBufferQueue.TextureIn( + frame.textureId, + frame.textureType, + frame.width, + frame.height, + 0, + false, + false, + true, + null, + frame.tag + ) + ) + } + glTextureBufferQueueIn.dequeue(true) + return@Callable 0 + })) + + var ret = 0 + if (isBegin || futureQueue.size >= cacheCount) { + isBegin = true + try { + val get = futureQueue.poll()?.get() ?: -1 + if (get == 0) { + val dequeue = glTextureBufferQueueOut.dequeue() ?: return -1 + glFrameBuffer.setSize(dequeue.width, dequeue.height) + ret = glFrameBuffer.process(dequeue.textureId, dequeue.textureType) + } + }catch (e: Exception){ + LogUtils.e(TAG, "process end with exception: $e") + } + } + + return ret + } + + fun reset(){ + if(frameIndex == 0){ + return + } + isBegin = false + frameIndex = 0 + var future = futureQueue.poll() + while (future != null) { + future.cancel(true) + future = futureQueue.poll() + } + glTextureBufferQueueIn.reset() +// glFrameBuffer.release() + executeSync { + glTextureBufferQueueOut.reset() + } + } + + fun size() = futureQueue.size + + fun release() { + isReleased = true + filter = null + isBegin = false + frameIndex = 0 + var future = futureQueue.poll() + while (future != null) { + future.cancel(true) + future = futureQueue.poll() + } + glTextureBufferQueueIn.release() + glFrameBuffer.release() + executeSync { + glTextureBufferQueueOut.release() + if (eglContextBase != null) { + eglContextHelper.release() + eglContextBase = null + } + } + workerThread.shutdown() + } + + fun executeSync(run: () -> Unit) { + val latch = CountDownLatch(1) + workerThread.execute { + run.invoke() + latch.countDown() + } + latch.await() + } +} \ No newline at end of file diff --git a/live/build.gradle b/live/build.gradle index b9a209670..6f1d3dc42 100644 --- a/live/build.gradle +++ b/live/build.gradle @@ -1 +1 @@ -apply plugin: 'com.android.library' apply plugin: 'img-optimizer' apply plugin: 'kotlin-android' android { compileSdkVersion rootProject.ext.android.compileSdkVersion buildToolsVersion rootProject.ext.android.buildToolsVersion aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false packagingOptions { pickFirst "lib/armeabi/libyuvutils.so" pickFirst "lib/arm64-v8a/libyuvutils.so" pickFirst "lib/armeabi-v7a/libyuvutils.so" pickFirst "lib/armeabi/libyuvtools.so" pickFirst "lib/arm64-v8a/libyuvtools.so" pickFirst "lib/armeabi-v7a/libyuvtools.so" exclude "lib/arm64-v8a/libmmcv_api_handgesture.so" exclude "lib/arm64-v8a/libmmcv_api_express.so" exclude "lib/arm64-v8a/libMediaEncoder.so" exclude "lib/arm64-v8a/libarcore_sdk_c.so" exclude "lib/arm64-v8a/libmediadecoder.so" exclude "lib/arm64-v8a/libMediaMuxer.so" exclude "lib/arm64-v8a/libarcore_sdk_jni.so" exclude "lib/arm64-v8a/libMediaUtils.so" exclude "lib/arm64-v8a/libcosmosffmpeg.so" } defaultConfig { minSdkVersion rootProject.ext.android.minSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion versionCode rootProject.ext.android.versionCode versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { abiFilters "armeabi-v7a", "arm64-v8a" } javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } aaptOptions { cruncherEnabled = false useNewCruncher = false } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } kotlinOptions { allWarningsAsErrors = true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { flatDir { dirs 'libs', '../libs' } mavenCentral() } dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.0' implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation (name:'../libs/beautysdk-202202241203',ext:'aar') implementation (name:'../libs/svgaplayer-release-v1.2.1',ext:'aar') //socket.io implementation('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } //common api project(path: ':common') api project(path:':FaceUnity')//新娱美颜 api project(':Share')//分享 annotationProcessor rootProject.ext.dependencies["arouter-compiler"] //工具 api rootProject.ext.dependencies["blank-utilcode"] implementation 'com.eightbitlab:blurview:1.6.6' implementation 'com.google.code.gson:gson:2.8.6' implementation "com.getkeepsafe.relinker:relinker:1.4.4" //ExoPlayer,腾讯的播放器不支持无缝切换 implementation 'com.google.android.exoplayer:exoplayer:2.18.2' implementation 'com.google.android.exoplayer:exoplayer-core:2.18.2@aar' } \ No newline at end of file +apply plugin: 'com.android.library' apply plugin: 'img-optimizer' apply plugin: 'kotlin-android' android { compileSdkVersion rootProject.ext.android.compileSdkVersion buildToolsVersion rootProject.ext.android.buildToolsVersion aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false packagingOptions { pickFirst "lib/armeabi/libyuvutils.so" pickFirst "lib/arm64-v8a/libyuvutils.so" pickFirst "lib/armeabi-v7a/libyuvutils.so" pickFirst "lib/armeabi/libyuvtools.so" pickFirst "lib/arm64-v8a/libyuvtools.so" pickFirst "lib/armeabi-v7a/libyuvtools.so" exclude "lib/arm64-v8a/libmmcv_api_handgesture.so" exclude "lib/arm64-v8a/libmmcv_api_express.so" exclude "lib/arm64-v8a/libMediaEncoder.so" exclude "lib/arm64-v8a/libarcore_sdk_c.so" exclude "lib/arm64-v8a/libmediadecoder.so" exclude "lib/arm64-v8a/libMediaMuxer.so" exclude "lib/arm64-v8a/libarcore_sdk_jni.so" exclude "lib/arm64-v8a/libMediaUtils.so" exclude "lib/arm64-v8a/libcosmosffmpeg.so" } defaultConfig { minSdkVersion rootProject.ext.android.minSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion versionCode rootProject.ext.android.versionCode versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { abiFilters "armeabi-v7a", "arm64-v8a" } javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } aaptOptions { cruncherEnabled = false useNewCruncher = false } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } kotlinOptions { allWarningsAsErrors = true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { flatDir { dirs 'libs', '../libs' } mavenCentral() } dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.0' implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation (name:'../libs/beautysdk-202202241203',ext:'aar') implementation (name:'../libs/svgaplayer-release-v1.2.1',ext:'aar') //socket.io implementation('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } //common api project(path:':lib_faceunity')//新娱美颜 api project(':Share')//分享 annotationProcessor rootProject.ext.dependencies["arouter-compiler"] //工具 api rootProject.ext.dependencies["blank-utilcode"] implementation 'com.eightbitlab:blurview:1.6.6' implementation 'com.google.code.gson:gson:2.8.6' implementation "com.getkeepsafe.relinker:relinker:1.4.4" //ExoPlayer,腾讯的播放器不支持无缝切换 implementation 'com.google.android.exoplayer:exoplayer:2.18.2' implementation 'com.google.android.exoplayer:exoplayer-core:2.18.2@aar' } \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 6154ec5ad..a8a7db008 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -272,6 +272,13 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl RandomPkManager.getInstance().addOnRandomPkTimer(onRandomPkTimer); + manager.setOnMirrorChanged(new FaceManager.OnMirrorChanged() { + @Override + public void onChange(boolean falg) { + mLivePushViewHolder.setEnableBeauty(falg); + } + }); + //添加开播前设置控件 mLiveReadyViewHolder = new LiveNewReadyRyViewHolder(mContext, mContainer, mLiveSDK); mLiveReadyViewHolder.setManager(manager); @@ -1476,7 +1483,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl @Override public void onLinkMicToPk(String uid, String pkhead, String pkname) { - L.eSw("onLinkMicToPkonLinkMicToPkonLinkMicToPk"); + } @Override diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveFaceUnityDialogNewFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveFaceUnityDialogNewFragment.java new file mode 100644 index 000000000..6e3f25227 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/LiveFaceUnityDialogNewFragment.java @@ -0,0 +1,87 @@ +package com.yunbao.live.dialog; + +import android.app.ActionBar; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.view.Gravity; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; + +import androidx.annotation.Nullable; + +import com.yunbao.common.dialog.AbsDialogFragment; +import com.yunbao.faceunity.FaceManager; +import com.yunbao.faceunity.ui.FaceUnityView; +import com.yunbao.live.R; + +/** + * 新娱美颜SDK,暂时不用,不要删除 + */ +public class LiveFaceUnityDialogNewFragment extends AbsDialogFragment { + private Context mContext; + private FaceUnityView faceView; + private FaceManager manager; + private View mRootView; + + public LiveFaceUnityDialogNewFragment(Context mContext) { + this.mContext = mContext; + } + + @Override + protected int getLayoutId() { + return 0; + } + + @Override + protected View getLayoutView() { + faceView = new FaceUnityView(mContext); + return faceView; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog4; + } + + @Override + protected boolean canCancel() { + return true; + } + + @Override + protected void setWindowAttributes(Window window) { + + WindowManager.LayoutParams params = window.getAttributes(); + params.width = ActionBar.LayoutParams.MATCH_PARENT; + params.height = ActionBar.LayoutParams.WRAP_CONTENT; + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + manager.setFaceUnityView(faceView); + manager.loadConfig(); + } + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + if(mRootView!=null) { + mRootView.setVisibility(View.VISIBLE); + } + } + + public void setManager(FaceManager manager) { + this.manager = manager; + } + + + public void setDismissShowUi(View mRootView) { + this.mRootView=mRootView; + } +} diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 2fd16e034..cd382ddeb 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -68,6 +68,7 @@ import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketRyLinkMicPkUtil; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.views.LiveLinkMicPkViewHolder; +import com.yunbao.live.views.LivePlayRyViewHolder; import com.yunbao.live.views.LivePushRyViewHolder; import org.greenrobot.eventbus.EventBus; @@ -685,112 +686,10 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar())); Log.e("eve", u.getId() + ""); L.eSw("主播接受了主播的PK邀請"); - /** - * 加入副房间 - * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 - * - * @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_` - * @param callBack 加入房间回调 - * @group 房间管理 - */ RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); - /*RCRTCEngine.getInstance().joinOtherRoom(u.getId(), new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - //遍历远端用户列表 - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry", stream.getMediaType() + "类型"); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.mPreView1.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.mPreView1.addView(remoteView); - } - //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 - inputStreamList.add(stream); - - - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); -//视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); -//大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); -//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 -//如不设置宽高值则服务端将使用默认宽高 360 * 640 -//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, -//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 960; - int height = 720; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //1. 设置自适应合流布局模式 - config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); - //2. 合流画布设置 - if (rcrtcLiveInfo == null) { - Log.w("PkDebug", "PK合流失败,rcrtcLiveInfo为空"); - } - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功13"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } - } - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "11111加入其他房间失败 :" + rtcErrorCode.getReason()); - } - });*/ LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); LiveRyAnchorActivity.isDRPK = 1; ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - /*LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); - params.weight = 1; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);*/ livePushRyViewHolder.setAnPkRtc(u);//设置对方主播视图 final SocketSendBean msg1 = new SocketSendBean() @@ -802,6 +701,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { .param("pkhead", u.getAvatar()) .param("pkname", u.getUserNiceName()); msg1.create(); + LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); /*Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); @@ -839,19 +739,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); LiveRyAnchorActivity.isDRPK = 1; - /*JSONObject msg1 = new JSONObject(); - msg1.put("uid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb()); - msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar())); - - if (bean != null && bean.isRandomPk()) { - msg1.put("random_pk", bean.isRandomPk() ? 1 : 0); - msg1.put("is_ladders", bean.getRankPkImgUrl()); - }*/ - - /*---------------------------------------------------------------- */ final SocketSendBean msg1 = new SocketSendBean() .param("_method_", SOCKET_LINK_MIC_PK) @@ -898,116 +785,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { onLinkMicPkStart(mApplyUid, 2); } }); - - /*IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.mPreView1.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.mPreView1.addView(remoteView); - } - //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 - inputStreamList.add(stream); - } - } - - Log.e("ry", "asa" + inputStreamList.size()); - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - List streams = new ArrayList<>(); - streams.add(RCRTCEngine.getInstance().getDefaultVideoStream()); - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); -//视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); -//大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); -//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 -//如不设置宽高值则服务端将使用默认宽高 360 * 640 -//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, -//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 960; - int height = 720; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //1. 设置自适应合流布局模式 - config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); - //2. 合流画布设置 - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功14"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "订阅资源失败: " + rtcErrorCode); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); - Log.i("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); - } - }); - - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); - LiveRyAnchorActivity.isDRPK = 1; - LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); - SocketRyLinkMicPkUtil.linkMicPkAccept(mSocketRyClient, mApplyUid, mApplyUrl, mApplyNmae); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid)); - onLinkMicPkStart(mApplyUid, 2); - } - }); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - ToastUtil.show("接受失败"); - } - });*/ - } //与用户连麦 @@ -2321,7 +2098,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (mIsAnchor) { ((LiveRyAnchorActivity) mContext).setPkBtnVisible(false); mPkTimeCount = PK_TIME_MAX; - } else { // mPkTimeCount=mPkTimeFromServer; mPkTimeCount = PK_TIME_MAX; diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index 75b078f2e..c76564e77 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -1260,6 +1260,7 @@ public class SocketRyClient { mListener.onLinkMicPkApply(u, map.getString("stream"), 1); break; case 2://收到对方主播PK回调 + L.eSw("收到对方主播PK回调"); RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); mListener.onLinkMicToPk(map.getString("uid"), map.getString("pkhead"), map.getString("pkname")); mListener.onLinkMicPkStart(map.getString("uid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); @@ -1274,6 +1275,7 @@ public class SocketRyClient { mListener.onLinkMicPkRefuse(); break; case 4://所有人收到PK开始址的回调 + L.eSw("所有人收到PK开始址的回调"); // RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(map.getString("pkuid"))); mListener.onLinkMicPkStart(map.getString("pkuid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders")); diff --git a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java index dcca21861..75e3aaa8b 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java @@ -44,7 +44,6 @@ import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.interfaces.ImageResultCallback; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.manager.SWManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.L; @@ -66,6 +65,7 @@ import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.dialog.LiveAnchorEditCallMeDialog; import com.yunbao.live.dialog.LiveAnchorSayPopDialog; import com.yunbao.live.dialog.LiveFaceUnityDialogFragment; +import com.yunbao.live.dialog.LiveFaceUnityDialogNewFragment; import com.yunbao.live.dialog.LiveNewRoomClassDialogFragment; import com.yunbao.live.dialog.LiveNewRoomTypeDialogFragment; import com.yunbao.live.dialog.LiveTimeDialogFragment; @@ -77,10 +77,7 @@ import org.greenrobot.eventbus.ThreadMode; import java.io.File; import java.util.Locale; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.stream.RCRTCCameraOutputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; -import cn.rongcloud.rtc.base.RCRTCParamsType; +import io.agora.beautyapi.faceunity.agora.SWManager; public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnClickListener { @@ -328,36 +325,6 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl liveOpenCustomPopup.setSelectClarity(selectClarity); } SWManager.get().setDimensions(selectClarity); - - /*//設置開播分辨率 - RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - int minRate = 200; - int maxRate = 900; - switch (selectClarity) { - case 0: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - minRate = 200; - maxRate = 900; - break; - case 1: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; - minRate = 250; - maxRate = 2200; - break; - case 2: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; - minRate = 400; - maxRate = 4000; - break; - } - RCRTCVideoStreamConfig config = - RCRTCVideoStreamConfig.Builder.create() - .setMinRate(minRate) - .setMaxRate(maxRate) - .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_15) - .setVideoResolution(rcrtcVideoResolution) - .build(); - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config);*/ Log.e("切换分辨率", "时间戳" + System.currentTimeMillis()); //重新发布一下流 Bus.get().post(new LivePushRyEvent()); @@ -569,8 +536,7 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl } else if (i == R.id.btn_locaiton) { switchLocation(); } else if (i == R.id.btn_horizontally) { - RCRTCCameraOutputStream cameraStream = RCRTCEngine.getInstance().getDefaultVideoStream(); - cameraStream.setPreviewMirror(!cameraStream.isPreviewMirror()); + SWManager.get().setMirrorMode(); } else if (i == R.id.btn_robot) { new XPopup.Builder(mContext) .asCustom(new LiveRobotSettingCustomPopup(mContext)) @@ -614,6 +580,20 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl } } + public void setFaceUnityNew(boolean init){ + LiveFaceUnityDialogNewFragment fragment = new LiveFaceUnityDialogNewFragment(mContext); + fragment.setManager(manager); + fragment.setDismissShowUi(mRootView); + if (mContext instanceof LiveRyAnchorActivity) { + fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "FaceUnity"); + mRootView.setVisibility(View.INVISIBLE); + if (init) { + fragment.dismiss(); + } + } + } + + /** * 打开心愿单窗口 */ diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 204f15b59..df57ab96b 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -38,7 +38,6 @@ import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.manager.SWAuManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; @@ -53,7 +52,6 @@ import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.live.utils.LiveExoPlayerManager; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -89,6 +87,7 @@ import cn.rongcloud.rtc.base.RCRTCRoomType; import cn.rongcloud.rtc.base.RCRTCStreamType; import cn.rongcloud.rtc.base.RTCErrorCode; import cn.rongcloud.rtc.core.RendererCommon; +import io.agora.beautyapi.faceunity.agora.SWAuManager; public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @@ -121,7 +120,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { static int vHeight;//视频高 private TextView debugView; - private LiveExoPlayerManager mPlayer; + //private LiveExoPlayerManager mPlayer; private boolean isPk = false; private boolean userJoinLinkMic = false;//用户是否已加入房间 @@ -174,10 +173,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params.height = vHeight; mPkContainer.requestLayout(); - mPlayer = new LiveExoPlayerManager(mContext); - mPlayer.setMainView(mVideoView); - mPlayer.setListener(new ExoPlayerListener()); - debugView = new TextView(mContext); debugView.setBackgroundColor(Color.WHITE); } @@ -185,7 +180,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void initSwEngine(String liveUid) { this.liveUid = liveUid; swAuManager = SWAuManager.get(); - swAuManager.setAudienceContainer(playFrameLayout); + swAuManager.setAudienceContainer(ry_view); swAuManager.initRtcEngine((Activity) mContext); swAuManager.setupRemoteVideo(Integer.parseInt(liveUid)); swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); @@ -229,10 +224,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Log.i(TAG, "setLiveBeanLandscape: " + landscape + " isPk: " + isPk); this.landscape = landscape; this.videoLandscape = landscape; - if (mPlayer != null) { - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); - } - if (landscape == 2) { Log.i(TAG, "还原9:16"); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); @@ -297,13 +288,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { */ @Override public void resumePlay() { - if (!mPlayer.isPlaying()) { - new Handler(Looper.getMainLooper()) - .postDelayed(() -> { - mPlayer.replay(); - // ToastUtil.show("强制播放" + val); - }, 100); - } + } /** @@ -317,30 +302,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { PLAY_MODEL = playModel; waitNextUrl = null; Log.i(TAG, "play" + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape" + videoLandscape); - if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); - if (landscape == VIDEO_VERTICAL && !isPk) { - url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); - } else if (landscape == VIDEO_HORIZONTAL || isPk) { - url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); - } - } else if (!url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(false); - } - Log.e("purl121", url); - - if (TextUtils.isEmpty(url) || mVideoView == null) { - return; - } - - if (TextUtils.isEmpty(url) || mVideoView == null) { - return; - } - if (mPlayer.isPlaying()) { - mPlayer.stop(); - mPlayer.clearUrl(); - } - mPlayer.startUrl(url); purl = url; onPrepared(); } @@ -351,14 +312,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { PLAY_MODEL = playModel; Log.i(TAG, "switchStream: " + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape = " + videoLandscape + " ispk = " + isPk + " bean = " + roomModel.getEnterRoomInfo().getIsconnection()); if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); if (landscape == VIDEO_VERTICAL && !isPk) { url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); } else if (landscape == VIDEO_HORIZONTAL || isPk) { url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); } } else if (!url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(false); } Log.e("purl121", url); @@ -370,7 +329,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { if (TextUtils.isEmpty(url) || mVideoView == null) { return; } - mPlayer.switchUrl(url); purl = url; } @@ -383,7 +341,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Log.i(TAG, "switchStreamPk: isPk1" + isPk + " tmp = " + !tmpPk + " isPk2 = " + this.isPk); if (this.isPk && tmpPk) return; if (isPk && !tmpPk || this.isPk) { - mPlayer.setViewResizeMode(false); String url; if (PLAY_MODEL != -1) { url = srcUrl.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); @@ -393,7 +350,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { if (!tmpPk) { waitNextUrl = url; } - mPlayer.switchUrl(srcUrl); tmpPk = true; } else if (!isPk) { tmpPk = false; @@ -404,14 +360,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } else { waitNextUrl = null; } - mPlayer.switchUrl(srcUrl); } } @Override public void clearFrame() { super.clearFrame(); - mPlayer.clearFrame(); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); params.height = ViewGroup.LayoutParams.WRAP_CONTENT; params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); @@ -436,10 +390,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void release() { mEnd = true; mStarted = false; - if (mPlayer != null) { - mPlayer.stop(); - mPlayer.release(); - } Bus.getOff(this); EventBus.getDefault().unregister(this); L.e(TAG, "release------->"); @@ -454,9 +404,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mCover.setVisibility(View.VISIBLE); } } - if (mPlayer != null) { - mPlayer.stop(); - } stopPlay2(); } @@ -481,10 +428,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params1.addRule(RelativeLayout.ALIGN_TOP); ry_view.requestLayout(); isPk = true; - if (mPlayer.getUrl().contains("848_24.flv") || mPlayer.getUrl().contains("1280_24.flv")) { - tmpPk = false; - switchStreamPk(true); - } } /** @@ -501,7 +444,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } else { height = ViewGroup.LayoutParams.WRAP_CONTENT; } - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); if (landscape == 2) { Log.i(TAG, "onPrepared:还原9:16 land=" + videoLandscape); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); @@ -804,20 +746,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } else { ToastUtil.show("You have successfully exited the voice connection"); } - if (mPlayer.getNowPlayer() != null) { - mPlayer.play(); - Log.e("ry", mPlayer.isPlaying() + "purl" + purl); - if (!mPlayer.isPlaying()) { - mPlayer.switchUrl(purl); - } - ry_view.removeAllViews(); - ry_view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; - onPrepared(); - rcrtcRoom = null; - MicStatusManager.getInstance().clear(); + ry_view.removeAllViews(); + ry_view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; + onPrepared(); + rcrtcRoom = null; + MicStatusManager.getInstance().clear(); - resumePlay(); - } + resumePlay(); if (onMicCallback != null) { onMicCallback.onMikUpdate(); @@ -1021,7 +956,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Log.i(TAG, "资源流 type: " + stream.getMediaType()); if (stream.getMediaType() == RCRTCMediaType.VIDEO) { //暂停播放 - mPlayer.stop(); + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 @@ -1314,7 +1249,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } else if (videoLandscape == VIDEO_HORIZONTAL) { url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); } - mPlayer.switchUrl(url); } private class ExoPlayerListener implements Player.Listener { @@ -1364,7 +1298,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { loadingListener.onPlayer(); } if (waitNextUrl != null) { - mPlayer.switchUrl(waitNextUrl); waitNextUrl = null; } } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java deleted file mode 100644 index f421d920f..000000000 --- a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java +++ /dev/null @@ -1,1374 +0,0 @@ -package com.yunbao.live.views; - -import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; - -import android.Manifest; -import android.app.Dialog; -import android.content.Context; -import android.graphics.Color; -import android.media.AudioManager; -import android.os.Build; -import android.os.Handler; -import android.os.Looper; -import android.text.TextUtils; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewParent; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import com.google.android.exoplayer2.PlaybackException; -import com.google.android.exoplayer2.Player; -import com.google.android.exoplayer2.ui.StyledPlayerView; -import com.google.android.exoplayer2.video.VideoSize; -import com.lxj.xpopup.XPopup; -import com.lxj.xpopup.core.BasePopupView; -import com.lxj.xpopup.interfaces.XPopupCallback; -import com.lzf.easyfloat.EasyFloat; -import com.lzy.okserver.OkDownload; -import com.yunbao.common.bean.EnterRoomNewModel; -import com.yunbao.common.dialog.LiveFontSizeSettingDialog; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.HttpClient; -import com.yunbao.common.interfaces.OnItemClickListener; -import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.utils.Bus; -import com.yunbao.common.utils.DialogUitl; -import com.yunbao.common.utils.DpUtil; -import com.yunbao.common.utils.L; -import com.yunbao.common.utils.MicStatusManager; -import com.yunbao.common.utils.ScreenDimenUtil; -import com.yunbao.common.utils.SpUtil; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; -import com.yunbao.common.views.LiveClarityCustomPopup; -import com.yunbao.live.R; -import com.yunbao.live.activity.LiveActivity; -import com.yunbao.live.activity.LiveAudienceActivity; -import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.live.utils.LiveExoPlayerManager; - -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.RCRTCRoomConfig; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; -import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleDataCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCVideoInputFrameListener; -import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; -import cn.rongcloud.rtc.api.stream.RCRTCOutputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoInputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; -import cn.rongcloud.rtc.api.stream.RCRTCVideoView; -import cn.rongcloud.rtc.base.RCRTCLiveRole; -import cn.rongcloud.rtc.base.RCRTCMediaType; -import cn.rongcloud.rtc.base.RCRTCParamsType; -import cn.rongcloud.rtc.base.RCRTCRemoteVideoFrame; -import cn.rongcloud.rtc.base.RCRTCRoomType; -import cn.rongcloud.rtc.base.RCRTCStreamType; -import cn.rongcloud.rtc.base.RTCErrorCode; -import cn.rongcloud.rtc.core.RendererCommon; - -public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { - - private static final String TAG = "LivePlayViewHolder"; - private ViewGroup mRoot; - private ViewGroup mSmallContainer; - private ViewGroup mLeftContainer; - private ViewGroup mRightContainer; - private RelativeLayout mPkContainer; - public StyledPlayerView mVideoView; - - private View mLoading, mLoading2; - private ImageView mCover; - private boolean mPaused;//是否切后台了 - private boolean mStarted;//是否开始了播放 - private boolean mEnd;//是否结束了播放 - public static ImageView leave; - - private boolean mPausedPlay;//是否被动暂停了播放 - public int landscape; //1h 2s - public Context contexts; - public FrameLayout ry_view; - - private static final int VIDEO_VERTICAL = 2; - private static final int VIDEO_HORIZONTAL = 1; - int videoLandscape = -1; // 视频方向,2=竖屏,1=横屏 - - static int vHeight;//视频高 - private TextView debugView; - private LiveExoPlayerManager mPlayer; - private boolean isPk = false; - private boolean userJoinLinkMic = false;//用户是否已加入房间 - - //0未申请1申请中2连麦中 - RCRTCRoom rcrtcRoom; - String purl, srcUrl; - - public int getLandscape() { - return landscape; - } - - public LivePlaySwViewHolder(Context context, ViewGroup parentView, int landscapes) { - super(context, parentView); - contexts = context; - landscape = landscapes; - Log.i("收收收", landscape + ""); - } - - - @Override - protected int getLayoutId() { - return R.layout.view_live_play_ksy; - } - - @Override - public void init() { - Log.i(TAG, "init: 初始化播放器ViewHolder"); - EventBus.getDefault().register(this); - Bus.getOn(this); - mRoot = (ViewGroup) findViewById(R.id.root); - mSmallContainer = (ViewGroup) findViewById(R.id.small_container); - mLeftContainer = (ViewGroup) findViewById(R.id.left_container); - mRightContainer = (ViewGroup) findViewById(R.id.right_container); - mPkContainer = (RelativeLayout) findViewById(R.id.pk_container); - mVideoView = (StyledPlayerView) findViewById(R.id.video_view); - ry_view = (FrameLayout) findViewById(R.id.ry_view); - leave = (ImageView) findViewById(R.id.leave); - mLoading = findViewById(R.id.loading); - mLoading2 = findViewById(R.id.loading2); - mCover = (ImageView) findViewById(R.id.cover); - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - vHeight = mScreenWdith * 720 / 960; - - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mPkContainer.getLayoutParams(); - params.height = vHeight; - mPkContainer.requestLayout(); - - mPlayer = new LiveExoPlayerManager(mContext); - mPlayer.setMainView(mVideoView); - mPlayer.setListener(new ExoPlayerListener()); - debugView = new TextView(mContext); - debugView.setBackgroundColor(Color.WHITE); - - } - - @Override - public void hideCover() { -// if (mCover != null) { -// if (mCover.getVisibility()==View.VISIBLE){ -//// new Handler().postDelayed(new Runnable() { -//// @Override -//// public void run() { -//// -//// } -//// },200); -// mCover.setVisibility(View.GONE); -// mLoading2.setVisibility(View.GONE); -// } -// -// -// } - } - - @Override - public void setCover(String coverUrl) { -// if (mCover != null) { -// mCover.setVisibility(View.VISIBLE); -// mLoading2.setVisibility(View.VISIBLE); -// ImgLoader.displayBlurLive(mContext, coverUrl, mCover, 400, 600); -// -// } - }// - - @Override - public synchronized void setLiveBeanLandscape(int landscape) { -// landscape=1; - Log.i(TAG, "setLiveBeanLandscape: " + landscape + " isPk: " + isPk); - this.landscape = landscape; - this.videoLandscape = landscape; - if (mPlayer != null) { - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); - } - - if (landscape == 2) { - Log.i(TAG, "还原9:16"); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = RelativeLayout.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - mVideoView.setLayoutParams(params); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = RelativeLayout.LayoutParams.MATCH_PARENT; - params1.topMargin = 0; - ry_view.setLayoutParams(params1); - ry_view.requestLayout(); - RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - params2.height = RelativeLayout.LayoutParams.MATCH_PARENT; - params2.topMargin = 0; - mCover.setLayoutParams(params2); - mCover.requestLayout(); - - } else { - Log.i(TAG, "还原16:9"); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.setLayoutParams(params); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = vHeight; - params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params1.addRule(RelativeLayout.ALIGN_TOP); - ry_view.setLayoutParams(params1); - ry_view.requestLayout(); - RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - params2.height = DpUtil.dp2px(270); - params2.topMargin = DpUtil.dp2px(120); - mCover.setLayoutParams(params2); - mCover.requestLayout(); - } - } - - @Override - public void setLiveEnterRoomNewModel(EnterRoomNewModel data) { - super.setLiveEnterRoomNewModel(data); - isPk = data.getEnterRoomInfo().getIsconnection().equals("1"); - if (isPk) { - setLiveBeanLandscape(1); - } - } - - /** - * 暂停播放 - */ - @Override - public void pausePlay() { - - } - - /** - * 暂停播放后恢复 - */ - @Override - public void resumePlay() { - if (!mPlayer.isPlaying()) { - new Handler(Looper.getMainLooper()) - .postDelayed(() -> { - mPlayer.replay(); - // ToastUtil.show("强制播放" + val); - }, 100); - } - } - - /** - * 开始播放 - * - * @param url 流地址 - */ - @Override - public void play(String url, int playModel) { - srcUrl = url; - PLAY_MODEL = playModel; - waitNextUrl = null; - Log.i(TAG, "play" + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape" + videoLandscape); - if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); - if (landscape == VIDEO_VERTICAL && !isPk) { - url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); - } else if (landscape == VIDEO_HORIZONTAL || isPk) { - url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); - } - } else if (!url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(false); - } - Log.e("purl121", url); - - if (TextUtils.isEmpty(url) || mVideoView == null) { - return; - } - - if (TextUtils.isEmpty(url) || mVideoView == null) { - return; - } - if (mPlayer.isPlaying()) { - mPlayer.stop(); - mPlayer.clearUrl(); - } - mPlayer.startUrl(url); - purl = url; - onPrepared(); - } - - @Override - public void switchStream(String url, int playModel) { - srcUrl = url; - PLAY_MODEL = playModel; - Log.i(TAG, "switchStream: " + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape = " + videoLandscape + " ispk = " + isPk + " bean = " + roomModel.getEnterRoomInfo().getIsconnection()); - if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); - if (landscape == VIDEO_VERTICAL && !isPk) { - url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); - } else if (landscape == VIDEO_HORIZONTAL || isPk) { - url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); - } - } else if (!url.contains(videoFps[0] + ".flv")) { - mPlayer.setViewResizeMode(false); - } - Log.e("purl121", url); - - if (TextUtils.isEmpty(url) || mVideoView == null) { - return; - } - - - if (TextUtils.isEmpty(url) || mVideoView == null) { - return; - } - mPlayer.switchUrl(url); - purl = url; - } - - boolean tmpPk = false; - String waitNextUrl = null; - - @Override - public void switchStreamPk(boolean isPk) { - super.switchStreamPk(isPk); - Log.i(TAG, "switchStreamPk: isPk1" + isPk + " tmp = " + !tmpPk + " isPk2 = " + this.isPk); - if (this.isPk && tmpPk) return; - if (isPk && !tmpPk || this.isPk) { - mPlayer.setViewResizeMode(false); - String url; - if (PLAY_MODEL != -1) { - url = srcUrl.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); - } else { - url = srcUrl.replace(".flv", videoRatioHorizontal[1] + videoFps[0] + ".flv"); - } - if (!tmpPk) { - waitNextUrl = url; - } - mPlayer.switchUrl(srcUrl); - tmpPk = true; - } else if (!isPk) { - tmpPk = false; - if (landscape == VIDEO_VERTICAL && PLAY_MODEL != -1) { - waitNextUrl = srcUrl.replace(".flv", videoRatioVertical[PLAY_MODEL] + videoFps[0] + ".flv"); - } else if (landscape == VIDEO_HORIZONTAL && PLAY_MODEL != -1) { - waitNextUrl = srcUrl.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); - } else { - waitNextUrl = null; - } - mPlayer.switchUrl(srcUrl); - } - } - - @Override - public void clearFrame() { - super.clearFrame(); - mPlayer.clearFrame(); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = ViewGroup.LayoutParams.WRAP_CONTENT; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.setLayoutParams(params); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = ViewGroup.LayoutParams.WRAP_CONTENT; - params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params1.addRule(RelativeLayout.ALIGN_TOP); - ry_view.setLayoutParams(params1); - ry_view.requestLayout(); - RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - params2.height = DpUtil.dp2px(270); - params2.topMargin = DpUtil.dp2px(120); - mCover.setLayoutParams(params2); - mCover.requestLayout(); - } - - @Override - public void release() { - mEnd = true; - mStarted = false; - if (mPlayer != null) { - mPlayer.stop(); - mPlayer.release(); - } - Bus.getOff(this); - EventBus.getDefault().unregister(this); - L.e(TAG, "release------->"); - } - - @Override - public void stopPlay() { - Log.i(TAG, "stopPlay: "); - if (mCover != null) { - mCover.setAlpha(1f); - if (mCover.getVisibility() != View.VISIBLE) { - mCover.setVisibility(View.VISIBLE); - } - } - if (mPlayer != null) { - mPlayer.stop(); - } - stopPlay2(); - } - - @Override - public void stopPlay2() { - - } - - @Override - public void setViewUP(int i) { - if (mVideoView == null) return; - Log.e("PK状态", "" + i); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; - params.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = vHeight; - params1.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top); - params1.addRule(RelativeLayout.ALIGN_TOP); - ry_view.requestLayout(); - isPk = true; - if (mPlayer.getUrl().contains("848_24.flv") || mPlayer.getUrl().contains("1280_24.flv")) { - tmpPk = false; - switchStreamPk(true); - } - } - - /** - * 播放开始 - */ - public void onPrepared() { - if (mEnd) { - release(); - return; - } - int height; - if (videoLandscape == VIDEO_VERTICAL) { - height = ViewGroup.LayoutParams.MATCH_PARENT; - } else { - height = ViewGroup.LayoutParams.WRAP_CONTENT; - } - mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); - if (landscape == 2) { - Log.i(TAG, "onPrepared:还原9:16 land=" + videoLandscape); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = height; - params.topMargin = 0; - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.setLayoutParams(params); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = height; - params1.topMargin = 0; - ry_view.setLayoutParams(params1); - ry_view.requestLayout(); - RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - params2.height = height; - params2.topMargin = 0; - mCover.setLayoutParams(params2); - mCover.requestLayout(); - } else { - Log.i(TAG, "onPrepared:还原16:9"); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = height; - params.topMargin = 0; - if (videoLandscape == VIDEO_HORIZONTAL) { - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - } - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.setLayoutParams(params); - mVideoView.requestLayout(); - - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); - params1.height = height; - params1.topMargin = 0; - params1.addRule(RelativeLayout.ALIGN_TOP); - if (videoLandscape == VIDEO_HORIZONTAL) { - params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - } - ry_view.setLayoutParams(params1); - ry_view.requestLayout(); - RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - params2.height = height; - params2.topMargin = DpUtil.dp2px(120); - mCover.setLayoutParams(params2); - mCover.requestLayout(); - } - } - - @Override - public void setPkview() { - Log.i("收到socket--->", "变成16:9"); - String url = srcUrl; - isPk = true; - switchStreamPk(true); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - } - - @Override - public synchronized void setPkEndview() { - - Log.i("收收收", landscape + ""); - isPk = false; - tmpPk = false; - switchStreamPk(false); - if (landscape == 2) { - Log.i("收到socket--->", "还原9:16"); - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = RelativeLayout.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - mVideoView.requestLayout(); - - } else { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - } -// if (detailsView != null) { -// mVideoView.removeView(detailsView); -// detailsView = null; -// } - } - - public void removeDetailView() { -// if (detailsView != null) { -// mVideoView.removeView(detailsView); -// detailsView = null; -// } - } - - @Override - public ViewGroup getSmallContainer() { - return mSmallContainer; - } - - - @Override - public ViewGroup getRightContainer() { - return mRightContainer; - } - - @Override - public ViewGroup getPkContainer() { - return mPkContainer; - } - - @Override - public void changeToLeft() { - if (mVideoView != null) { - - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; -// params.height = mContext.getResources().getDimensionPixelOffset(R.dimen.live_view); - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - - } - if (mLoading != null && mLeftContainer != null) { - ViewParent viewParent = mLoading.getParent(); - if (viewParent != null) { - ((ViewGroup) viewParent).removeView(mLoading); - } - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); - params.gravity = Gravity.CENTER; - mLoading.setLayoutParams(params); - mLeftContainer.addView(mLoading); - } - } - - @Override - public void changeToBig() { - if (mVideoView != null) { - RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - mVideoView.setLayoutParams(params); - - } - if (mLoading != null && mRoot != null) { - ViewParent viewParent = mLoading.getParent(); - if (viewParent != null) { - ((ViewGroup) viewParent).removeView(mLoading); - } - RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); - params.addRule(RelativeLayout.CENTER_IN_PARENT); - mLoading.setLayoutParams(params); - mRoot.addView(mLoading); - } - } - - @Override - public void onResume() { - if (!mPausedPlay && mPaused && mVideoView != null) { -// mVideoView.runInForeground(); -// mVideoView.start(); - } - mPaused = false; -// if (mPlayer.isPlaying() == 1) { -// mPlayer.resumeVideo(); -// mPlayer.resumeAudio(); -// } - } - - @Override - public void onPause() { -// if (!mPausedPlay && mVideoView != null) { -// mVideoView.runInBackground(false); -// } -// mPaused = true; -// mPlayer.pauseVideo(); -// mPlayer.pauseAudio(); - } - - @Override - public void onDestroy() { - release(); - } - - //全屏 - @Override - public void fullScreen() { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = RelativeLayout.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - } - - //小屏 - @Override - public void smallScreen() { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); - params.height = vHeight; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - // mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation0); - params.addRule(RelativeLayout.ALIGN_TOP); - mVideoView.requestLayout(); - } - - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onUpdata(String str) { - if ("UsertoRY".equals(str)) { - DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - UsertoRY(); - dialog = null; - } - }); - - } else if ("inviteMic".equals(str)) { - String content = "邀請您進行語音連麥"; - String confirm = "接受"; - String cancel = "拒絕"; - if (!WordUtil.isNewZh()) { - content = "You are invited to join the voice connection"; - confirm = "accept"; - cancel = "cancel"; - } - DialogUitl.Builder builder = new DialogUitl.Builder(mContext) - .setContent(content) - .setTitle(mLiveBean.getUserNiceName()) - .setConfirmString(confirm) - .setCancelString(cancel) - .setView(R.layout.dialog_live_mic_invite) - .setClickCallback(new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - String[] permissions; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - permissions = new String[]{ - Manifest.permission.READ_MEDIA_IMAGES, - Manifest.permission.RECORD_AUDIO - }; - } else { - permissions = new String[]{ - Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE, - Manifest.permission.RECORD_AUDIO - }; - } - LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { - @Override - public void run() { - UsertoRY(); - - } - }); - } - }); - builder.build().show(); - - } else if ("endMic".equals(str)) { - if (rcrtcRoom != null) { - // 开始切换为观众身份 - RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { - - /** - * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 - * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 - */ - @Override - public void onKicked() { - - } - - @Override - public void onSuccess() { - Log.e("ry", "下麦成功"); - // 该用户切换为观众成功,可以以观众身份进行音视频 - //退出rtc播放 - leaveRoom(); - } - - /** - * 当切换失败且不影响当前角色继续音视频时回调 - * @param errorCode 失败错误码 - */ - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "下麦失败" + errorCode); - leaveRoom(); - } - - private void leaveRoom() { - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - userJoinLinkMic = false; - Log.e("ry", "退出多人房间成功"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - if (WordUtil.isNewZh()) { - ToastUtil.show("已成功退出語音連麥"); - } else { - ToastUtil.show("You have successfully exited the voice connection"); - } - if (mPlayer.getNowPlayer() != null) { - mPlayer.play(); - Log.e("ry", mPlayer.isPlaying() + "purl" + purl); - if (!mPlayer.isPlaying()) { - mPlayer.switchUrl(purl); - } - ry_view.removeAllViews(); - ry_view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; - onPrepared(); - rcrtcRoom = null; - MicStatusManager.getInstance().clear(); - - resumePlay(); - } - - if (onMicCallback != null) { - onMicCallback.onMikUpdate(); - } - } - }); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", errorCode + "退出多人房间成功"); - userJoinLinkMic = false; - } - }); - - } - }); - } - } else if ("Debug".equals(str)) { - if (EasyFloat.isShow("Debug")) { - EasyFloat.dismiss("Debug"); - return; - } - EasyFloat.with(mContext) - .setDragEnable(true) - .setTag("Debug") - .setLayout(debugView) - .show(); - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onOpenDrawer(LiveAudienceEvent event) { - if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO) { - int ban = 0;//全模式都可以选择 - switch (roomModel.getClarityType() - 1) { - case PLAY_MODEL_720://仅允许720(高清),ban掉1080(超高清)模式 - ban = LiveClarityCustomPopup.BAN_1080; - break; - case -1://没有该字段 - case PLAY_MODEL_480://仅允许480(流畅),ban掉1080(超高清)和720(高清)模式 - ban = LiveClarityCustomPopup.BAN_720; - break; - - } - LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, - IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR), - ban, - true); - new XPopup.Builder(mContext) - .setPopupCallback(new XPopupCallback() { - @Override - public void onCreated(BasePopupView popupView) { - - } - - @Override - public void beforeShow(BasePopupView popupView) { - - } - - @Override - public void onShow(BasePopupView popupView) { - - } - - @Override - public void onDismiss(BasePopupView popupView) { - int selectClarity = liveClarityCustomPopup.getSelectClarity(); - if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR)) - return; - if (selectClarity == PLAY_MODEL_ANCHOR) { - switchStream(srcUrl, PLAY_MODEL_DEF); - setAudiencePlayModel(selectClarity); - } else { - switchStream(srcUrl, selectClarity); - } - IMLoginManager.get(mContext).put(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, selectClarity); - showToast(); - } - - private void showToast() { - if (WordUtil.isNewZh()) { - DialogUitl.showToast(mContext, "設置成功\n" + - "正在為你轉換中", 3000); - } else { - DialogUitl.showToast(mContext, "successful\n" + - "It's being converted for you", 3000); - } - } - - @Override - public void beforeDismiss(BasePopupView popupView) { - - } - - @Override - public boolean onBackPressed(BasePopupView popupView) { - return false; - } - - @Override - public void onKeyBoardStateChanged(BasePopupView popupView, int height) { - - } - - @Override - public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { - - } - - @Override - public void onClickOutside(BasePopupView popupView) { - - } - }) - .asCustom(liveClarityCustomPopup) - .show(); - } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.FONT_SIZE) { - int fount = 0; - try { - fount = Integer.parseInt(SpUtil.getStringValue("pd_live_room_fount_size")); - } catch (Exception ignored) { - - } - new LiveFontSizeSettingDialog(mContext, fount).setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(Integer bean, int position) { - EventBus.getDefault().post(new LiveAudienceEvent() - .setNums(bean) - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE)); - } - }).showDialog(); - } - } - - /** - * 把观众转换成主播 - */ - public List userinputStreamList = new ArrayList<>(); - - - public void UsertoRY() { - userinputStreamList.clear(); - Log.e("ry", "主播同意了UsertoRY"); - if (userJoinLinkMic) {//已经在房间内,不再joinRoom直接去连麦 - subscribeMic(rcrtcRoom); - return; - } - RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() - // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO - .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) - .setLiveRole(RCRTCLiveRole.AUDIENCE) - .build(); - RCRTCEngine.getInstance().joinRoom(LiveActivity.mLiveUid, roomConfig, new IRCRTCResultDataCallback() { - - - @Override - public void onSuccess(RCRTCRoom data) { - userJoinLinkMic = true; - rcrtcRoom = data; - subscribeMic(data); - - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", LiveActivity.mLiveUid + errorCode + ""); - if (errorCode.getValue() == 50007) {//userJoinLinkMic可能失效,直接leaveRoom - userJoinLinkMic = false; - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - UsertoRY(); - } - }); - } else { - ToastUtil.show("房间失败" + errorCode); - } - - } - }); - - - } - - private void subscribeMic(RCRTCRoom data) { - runOnUiThread(new Runnable() { - @Override - public void run() { - RCRTCEngine.getInstance().enableSpeaker(true); - //遍历远端用户发布的资源列表 - Log.i(TAG, "软件资源数量:" + data.getLiveStreams().size()); - for (RCRTCInputStream stream : data.getLiveStreams()) { - Log.i(TAG, "资源流 type: " + stream.getMediaType()); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - //暂停播放 - mPlayer.stop(); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT); - ry_view.addView(remoteView); - Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + data.getLiveStreams().size()); - } - userinputStreamList.add(stream); - } - rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList, new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", userinputStreamList.size() + LiveActivity.mLiveUid + "订阅失败" + errorCode.toString()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - - @Override - public void onSuccess() { - Log.e("ry", "订阅资源成功"); -// new Handler().postDelayed(new Runnable() { -// @Override -// public void run() { - toMic(); -// } -// }, 3000); - - } - }); - } - }); - } - - /** - * 主房间事件监听 - * 详细说明请参考文档:https://www.rongcloud.cn/docs/api/android/rtclib_v4/cn/rongcloud/rtc/api/callback/IRCRTCRoomEventsListener.html - */ - public IRCRTCRoomEventsListener roomEventsListener = new IRCRTCRoomEventsListener() { - @Override - public void onRemoteUserPublishResource(RCRTCRemoteUser rcrtcRemoteUser, List list) { - Log.e("ry", "远端来了" + list.size()); - //TODO 按需在此订阅远端用户发布的资源 - rcrtcRoom.getLocalUser().subscribeStreams(list, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "远端成功" + list.size()); - - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "远端失败" + list.size()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - - @Override - public void onRemoteUserMuteAudio(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - - } - - @Override - public void onRemoteUserMuteVideo(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - - } - - @Override - public void onRemoteUserUnpublishResource(RCRTCRemoteUser remoteUser, List streams) { - - } - - @Override - public void onUserJoined(RCRTCRemoteUser remoteUser) { - - } - - @Override - public void onUserLeft(RCRTCRemoteUser remoteUser) { - - } - - @Override - public void onUserOffline(RCRTCRemoteUser remoteUser) { - - } - - @Override - public void onPublishLiveStreams(List streams) { - - } - - @Override - public void onUnpublishLiveStreams(List streams) { - - } - }; - - - public List userinputStreamList1 = new ArrayList<>(); - public List userinputStreamList2 = new ArrayList<>(); - - public void toMic() { - RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC, RCRTCParamsType.AudioScenario.MUSIC_CLASSROOM); - userinputStreamList1.clear(); - userinputStreamList2.clear(); - RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - int minRate = 200; - int maxRate = 900; - switch (IMLoginManager.get(mContext).getSelectClarity()) { - case 0: - rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - minRate = landscape == 1 ? 900 : 200; - maxRate = landscape == 1 ? 700 : 900; - break; - case 1: - rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; - minRate = landscape == 1 ? 900 : 250; - maxRate = landscape == 1 ? 700 : 2200; - break; - case 2: - rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; - minRate = landscape == 1 ? 900 : 400; - maxRate = landscape == 1 ? 700 : 4000; - break; - } - // 示例代码使用480x640分辨率演示 - RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig - .Builder.create() - //设置分辨率 - .setVideoResolution(rcrtcVideoResolution) - //设置帧率 - .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_24) - //设置最小码率,480P下推荐200 - .setMinRate(minRate) - //设置最大码率,480P下推荐900 - .setMaxRate(maxRate) - .build(); - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); -// 创建视图渲染视图 -// RCRTCVideoView videoView = new RCRTCVideoView(contexts); -// RCRTCEngine.getInstance().getDefaultVideoStream().setVideoView(videoView); -//TODO 示例代码使用获取本地默认视频流、音频流演示 - ArrayList streams = new ArrayList<>(); -// streams.add(RCRTCEngine.getInstance().getDefaultVideoStream()); - streams.add(RCRTCEngine.getInstance().getDefaultAudioStream()); - if (landscape == 1) { - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - setLiveBeanLandscape(1); - } - }); - - } -// 开启摄像头 -// RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(null); -// 开始切换为主播身份 - RCRTCEngine.getInstance().getRoom().getLocalUser().switchToBroadcaster(streams, new IRCRTCSwitchRoleDataCallback() { - /** - * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 - * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 - */ - @Override - public void onKicked() { - Log.e("ry", "切换onKicked"); - - } - - @Override - public void onSuccess(RCRTCLiveInfo data) { - rcrtcRoom.registerRoomListener(roomEventsListener); - //该用户切换为主播成功,可以以主播身份进行音视频 - Log.e("ry", "切换成功"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - if (onMicCallback != null) { - onMicCallback.onMikUpdate(); - } - //遍历远端用户列表 - for (int i = 0; i < rcrtcRoom.getRemoteUsers().size(); i++) { - Log.e("ry", rcrtcRoom.getRemoteUsers().get(i).getUserId() + "收到rcrtcOtherRoom" + rcrtcRoom.getRemoteUsers().size()); - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry", i + "收到" + stream.getMediaType() + "实打实打算" + rcrtcRoom.getRemoteUsers().get(i).getUserId()); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - if (userinputStreamList1.size() == 0) { - - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setStreamType(RCRTCStreamType.NORMAL); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - ((RCRTCVideoInputStream) stream).setVideoFrameListener(new IRCRTCVideoInputFrameListener() { - @Override - public void onFrame(RCRTCRemoteVideoFrame videoFrame) { - String debugText = " 2、安卓主播开播, 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" + - "rotation:" + videoFrame.getRotation() + "\n" + - "timestampNs:" + videoFrame.getTimestampNs() + "\n" + - "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + - "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n"; - //Log.d("ry", "onFrame: " + debugText); - new Handler(Looper.getMainLooper()).post(() -> { - debugView.setText(debugText); - - }); - } - }); - //todo 本demo只演示添加1个远端用户的视图 - ry_view.removeAllViews(); - remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL); - ry_view.addView(remoteView); - } - userinputStreamList1.add(stream); - } - userinputStreamList2.add(stream); - } - } - //开始订阅资源 - rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList2, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "订阅资源成功"); - MicStatusManager.getInstance().setMicData(MicStatusManager.MIC_TYPE_OPEN, LiveActivity.mLiveUid); - AudioManager audioManager = (AudioManager) contexts.getSystemService(Context.AUDIO_SERVICE); - RCRTCEngine.getInstance().enableSpeaker(true); - audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); - audioManager.setSpeakerphoneOn(true); - - HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm") - .params("roomid", LiveActivity.mLiveUid) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.e("ry", code + "热热热"); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - - - } - - /** - * 当切换失败且不影响当前角色继续音视频时回调 - * @param errorCode 失败错误码 - */ - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", errorCode + "切换失败"); - - } - }); - } - - @Override - public void setLoadViewListener(LoadingListener listener) { - super.setLoadViewListener(listener); - } - - private void showLoadingDialog() { - if (PLAY_MODEL == PLAY_MODEL_480) return; - - new DialogUitl.Builder(mContext) - .setTitle("網絡提示") - .setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。") - .setView(R.layout.dialog_simple_tip) - .setClickCallback(new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - dialog.dismiss(); - } - }).build().show(); - PLAY_MODEL = PLAY_MODEL_480; - String url = srcUrl; - if (videoLandscape == VIDEO_VERTICAL) { - url = url.replace(".flv", videoRatioVertical[PLAY_MODEL_480] + videoFps[0] + ".flv"); - } else if (videoLandscape == VIDEO_HORIZONTAL) { - url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); - } - mPlayer.switchUrl(url); - } - - private class ExoPlayerListener implements Player.Listener { - String TAG = "播放流"; - - @Override - public void onPlayerError(PlaybackException error) { - Player.Listener.super.onPlayerError(error); - debugView.setText("播放出错code=" + error.errorCode + " msg=" + error.getErrorCodeName()); - } - - @Override - public void onVideoSizeChanged(VideoSize videoSize) { - Player.Listener.super.onVideoSizeChanged(videoSize); - Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height); - //ToastUtil.show("分辨率: 宽 = " + videoSize.width + " 高 = " + videoSize.height); - if (videoSize.height > videoSize.width) { - videoLandscape = VIDEO_VERTICAL; - } else { - videoLandscape = VIDEO_HORIZONTAL; - } - } - - @Override - public void onPlaybackStateChanged(int playbackState) { - Player.Listener.super.onPlaybackStateChanged(playbackState); - if (playbackState == Player.STATE_BUFFERING) { - //showLoadingDialog(); - mLoading.setVisibility(View.VISIBLE); - OkDownload.getInstance().pauseAll(); - Log.i(TAG, "onPlaybackStateChanged: 缓存中"); - } else { - mLoading.setVisibility(View.INVISIBLE); - Log.i(TAG, "onPlaybackStateChanged: 播放中"); - } - } - - @Override - public void onIsPlayingChanged(boolean isPlaying) { - Player.Listener.super.onIsPlayingChanged(isPlaying); - if (isPlaying) { - hideCover(); - mLoading.setVisibility(View.INVISIBLE); - Log.i(TAG, "onIsPlayingChanged: 开始播放 | waitNextUrl = " + waitNextUrl); - OkDownload.getInstance().startAll(); - if (loadingListener != null) { - loadingListener.onPlayer(); - } - if (waitNextUrl != null) { - mPlayer.switchUrl(waitNextUrl); - waitNextUrl = null; - } - } - } - } - - private int mPkTimeCount = 0; - - - public interface PlayViewLayoutInterface { - void playViewLayout(int width, int height); - } - - private PlayViewLayoutInterface layoutInterface; - - public void setLayoutInterface(PlayViewLayoutInterface layoutInterface) { - mVideoView.post(new Runnable() { - @Override - public void run() { - int width = mVideoView.getMeasuredWidth(); - int height = mVideoView.getMeasuredHeight(); - if (layoutInterface != null) { - layoutInterface.playViewLayout(width, height); - } - } - }); - } - - -} diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 70a60f04c..d9f2c2e11 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -46,8 +46,6 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.RandomPkManager; -import com.yunbao.common.manager.SWAuManager; -import com.yunbao.common.manager.SWManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; @@ -83,8 +81,8 @@ import cn.rongcloud.rtc.api.stream.RCRTCInputStream; import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; import cn.rongcloud.rtc.base.RCRTCParamsType; import cn.rongcloud.rtc.base.RTCErrorCode; -import cn.rongcloud.rtc.core.CameraVideoCapturer; -import io.agora.rtc2.RtcEngine; +import io.agora.beautyapi.faceunity.agora.SWAuManager; +import io.agora.beautyapi.faceunity.agora.SWManager; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; @@ -96,7 +94,6 @@ import io.rong.message.TextMessage; */ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITXLivePushListener { - private RtcEngine mRtcEngine; private int mMeiBaiVal;//基础美颜 美白 private int mMoPiVal;//基础美颜 磨皮 private int mHongRunVal;//基础美颜 红润 @@ -521,6 +518,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX // TODO: 2024/4/13 退出对方主播直播间 SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),pkUid1); SWManager.get().updateMyChannelView((FrameLayout) mBigContainer); + btn_close.setVisibility(View.GONE);//隐藏连麦按钮 EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); closeButtonGone(); @@ -590,164 +588,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } }); initRtcEngine(); - - /* // 构建 RoomConfig,指定房间类型和主播身份: - RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() - // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO - .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) - .setLiveRole(BROADCASTER) - .build(); - - - //调用 RCRTCEngine 下的 joinRoom 方法创建并加入一个直播房间: - final CommonAppConfig appConfig = CommonAppConfig.getInstance(); - - RCRTCEngine.getInstance().joinRoom(appConfig.getUid(), roomConfig, new IRCRTCResultDataCallback() { - @Override - public void onFailed(RTCErrorCode errorCode) { - ToastUtil.show("开播失败" + errorCode); - } - - @Override - public void onSuccess(final RCRTCRoom room) { - - // 保存房间对象 - rtcRoom = room; - IMRTCManager.getInstance().setRtcRoom(room); - - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - - RCRTCConfig config = RCRTCConfig.Builder.create() - //是否硬解码 - .enableHardwareDecoder(true) - //是否硬编码 - .enableHardwareEncoder(true) - .build(); - - - RCRTCEngine.getInstance().init(contexts, config); - RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC_HIGH, RCRTCParamsType.AudioScenario.MUSIC_CHATROOM); - //設置開播分辨率 - RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - int minRate = 200; - int maxRate = 900; - switch (IMLoginManager.get(mContext).getSelectClarity()) { - case 0: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - minRate = 200; - maxRate = 900; - break; - case 1: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; - minRate = 250; - maxRate = 2200; - break; - case 2: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; - minRate = 400; - maxRate = 4000; - break; - } - - RCRTCVideoStreamConfig videoConfigBuilder = RCRTCVideoStreamConfig.Builder.create() - //设置分辨率 - .setVideoResolution(rcrtcVideoResolution) - //设置帧率 - .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_24) - //设置最小码率,480P下推荐200 - .setMinRate(minRate) - //设置最大码率,480P下推荐900 - .setMaxRate(maxRate) - .build(); - - // 创建本地视频显示视图 - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(videoConfigBuilder); - RCRTCEngine.getInstance().getDefaultVideoStream().enableTinyStream(false); - RCRTCVideoView rongRTCVideoView = new RCRTCVideoView(contexts); - rongRTCVideoView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL); - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoView(rongRTCVideoView); - RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(new IRCRTCResultDataCallback() { - @Override - public void onSuccess(Boolean data) { - //设置摄像头最大缩放比例 - boolean zoom = RCRTCEngine.getInstance().getDefaultVideoStream().setCameraZoomFactor(1.0f); - // ToastUtil.show("设置比例="+zoom); - Log.i("摄像头", "onSuccess: 打开摄像头"); - isNeedOpenCamera = false; - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.i("摄像头", "onFailed: 打开摄像头失败 " + errorCode); - } - }); - RCRTCEngine.getInstance().registerEventListener(new IRCRTCEngineEventListener() { - @Override - public void onKicked(String roomId, RCRTCParamsType.RCRTCKickedReason kickedReason) { - - } - - @Override - public void onError(RTCErrorCode errorCode) { - super.onError(errorCode); - Log.i("摄像头", "onError: 错误码" + errorCode); - } - - @Override - public void onLocalVideoEventNotify(RCRTCVideoEventCode event) { - super.onLocalVideoEventNotify(event); - Log.i("摄像头", "onLocalVideoEventNotify: 本地视频事件" + event.code); - if (event.code == 3) { - isNeedOpenCamera = true; - } - } - }); - //设置摄像头最大缩放比例 - // RCRTCEngine.getInstance().getDefaultVideoStream().setCameraZoomFactor(RCRTCEngine.getInstance().getDefaultVideoStream().getCameraMaxZoomFactor()); - mPreView.addView(rongRTCVideoView); - tencentTRTCBeautyManager = new TencentTRTCBeautyManager(mContext); - - //加入房间成功后可以通过 RCRTCLocalUser 对象发布本地默认音视频流,包括:麦克风采集的音频和摄像头采集的视频。 - RCRTCEngine.getInstance().getDefaultVideoStream().setEncoderMirror(true); - if (rtcRoom == null || rtcRoom.getLocalUser() == null) { - if (room == null || room.getLocalUser() == null) { - ToastUtil.show("开播失败 请稍后再试,错误代码:room is null"); - ((LiveRyAnchorActivity) mContext).endLives(); - return; - } - rtcRoom = room; - IMRTCManager.getInstance().setRtcRoom(room); - } - rtcRoom.getLocalUser().publishDefaultLiveStreams(new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCLiveInfo rcrtcLiveInfo1) { - rcrtcLiveInfo = rcrtcLiveInfo1; - - room.registerRoomListener(roomEventsListener); - - //美颜 -// new Handler(Looper.getMainLooper()).post(new Runnable() { -// public void run() { -// //旧美颜不需要了 -// -// -// } -// }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "rtcErrorCode" + rtcErrorCode); - } - }); - } - - }); - - - } - });*/ } /** @@ -784,6 +624,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void onLinkMicAnchorClose(){ swManager.updateMyChannelView((FrameLayout) mBigContainer); + LivePushRyViewHolder.btn_close.setVisibility(View.GONE); } @Override @@ -825,17 +666,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } else { mCameraFront = true; } - RCRTCEngine.getInstance().getDefaultVideoStream().switchCamera(new CameraVideoCapturer.CameraSwitchHandler() { - @Override - public void onCameraSwitchDone(boolean isFrontCamera) { - - } - - @Override - public void onCameraSwitchError(String errorDescription) { - - } - }); + swManager.switchCamera(); } /** @@ -982,7 +813,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void startBgm(String path) { mBgmPath = path; - } @Override @@ -1107,6 +937,12 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX }); } + public void setEnableBeauty(boolean flag){ + if(swManager!=null){ + swManager.setEnableBeauty(flag); + } + } + @Subscribe(threadMode = ThreadMode.MAIN) public void updateSub(LiveAudienceEvent event) { if (event.getType() == LIVE_PK_END) { @@ -1116,4 +952,12 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } Log.i("PK----->", "updateSub: " + isPk + "|" + event.getType()); } + + @Override + public void onDestroy() { + super.onDestroy(); + if(swManager!=null){ + swManager.exitChannelAll(); + } + } } diff --git a/main/build.gradle b/main/build.gradle index d1895104e..7e6ea783f 100644 --- a/main/build.gradle +++ b/main/build.gradle @@ -72,7 +72,7 @@ dependencies { //短视频 api project(':video') api project(':common') - api project(':FaceUnity')//新娱美颜 + api project(':lib_faceunity')//新娱美颜 api project(':Share')//分享 implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.4.0' diff --git a/pluginsForAnchor/build.gradle b/pluginsForAnchor/build.gradle index ef5b9896d..b4c3f739f 100644 --- a/pluginsForAnchor/build.gradle +++ b/pluginsForAnchor/build.gradle @@ -85,7 +85,7 @@ android { doLast { delete(fileTree(dir: outputDir, includes: [ 'model/ai_bgseg_green.bundle', - 'model/ai_face_processor.bundle', + //'model/ai_face_processor.bundle', //'model/ai_face_processor_lite.bundle', 'model/ai_hairseg.bundle', 'model/ai_hand_processor.bundle', diff --git a/settings.gradle b/settings.gradle index b391e1573..16ddb4134 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,3 +7,4 @@ include ':pluginsForAnchor' //include ':lib_huawei' include ':lib_google' include ':IAP6Helper' +include ':lib_faceunity' From 4147e3c5f51e0b2e0434ea6fbc101559a2efdbed Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Fri, 19 Apr 2024 18:27:56 +0800 Subject: [PATCH 05/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=A4=9A=E4=BA=BAPK]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../faceunity/agora/SWAuManager.java | 61 +++-- .../beautyapi/faceunity/agora/SWManager.java | 2 +- .../live/activity/LiveRyAnchorActivity.java | 56 ++-- .../yunbao/live/event/LiveAudienceEvent.java | 1 - .../presenter/LiveLinkMicPkPresenter.java | 51 +--- .../presenter/LiveRyLinkMicPkPresenter.java | 167 ++++++------ .../yunbao/live/socket/SocketRyClient.java | 10 +- .../live/views/LivePlayRyViewHolder.java | 252 ++++++++---------- .../live/views/LivePushRyViewHolder.java | 31 ++- .../live/views/LiveRyAnchorViewHolder.java | 2 +- .../main/res/layout/view_live_play_ksy.xml | 11 +- 11 files changed, 306 insertions(+), 338 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index e22394f46..28877628d 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -76,6 +76,21 @@ public class SWAuManager extends BaseCacheManager { //mRtcEngine.startPreview(); } + /** + * 更新主播视图 + * @param frameLayout + */ + public void updateMyChannelView(FrameLayout frameLayout,int uid) { + mRtcEngine.setupLocalVideo(null); + SurfaceView surfaceView = new SurfaceView(mContext); + surfaceView.setZOrderMediaOverlay(true); + frameLayout.addView(surfaceView); + + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid); + mRtcEngine.setupRemoteVideo(videoCanvas); + } + + /** * 加入房间 */ @@ -101,14 +116,7 @@ public class SWAuManager extends BaseCacheManager { } - public void joinExRoomEx(String strUid, String token, String channelName) { - int uid; - if (StringUtil.isEmpty(strUid)) { - uid = 0; - } else { - uid = Integer.parseInt(strUid); - } - + public void joinExRoomEx(int strUid, String token, String channelName) { // 创建 ChannelMediaOptions 对象,并进行配置 ChannelMediaOptions options = new ChannelMediaOptions(); // 根据场景将用户角色设置为 AUDIENCE (观众) @@ -119,23 +127,24 @@ public class SWAuManager extends BaseCacheManager { options.autoSubscribeAudio = true; RtcConnection rtcConnection = new RtcConnection(); - rtcConnection.channelId = "g99411"; //對方主播的頻道 - rtcConnection.localUid = 99412;//自己的ID + rtcConnection.channelId = channelName; //對方主播的頻道 + rtcConnection.localUid = Integer.parseInt(CommonAppConfig.getInstance().getUid());//自己的ID mRtcEngine.joinChannelEx(token, rtcConnection, options, new IRtcEngineEventHandler() { @Override public void onJoinChannelSuccess(String channel, int uid, int elapsed) { super.onJoinChannelSuccess(channel, uid, elapsed); - L.eSw("onJoinChannelSuccess:" + channel + " uid " +uid+ " elapsed: " + elapsed); - - SurfaceView surfaceView = new SurfaceView(mContext); - surfaceView.setZOrderMediaOverlay(true); - pkContainer1.addView(surfaceView); - - VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, 99411); - - mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); - + mContext.runOnUiThread(new Runnable() { + @Override + public void run() { + L.eSw("onJoinChannelSuccess:" + channel + " uid " +uid+ " elapsed: " + elapsed); + SurfaceView surfaceView = new SurfaceView(mContext); + surfaceView.setZOrderMediaOverlay(true); + pkContainer1.addView(surfaceView); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, strUid); + mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); + } + }); } @Override @@ -146,6 +155,18 @@ public class SWAuManager extends BaseCacheManager { }); } + /** + * 退出对方直播间 + * @param uid 自己的ID + * @param liveUid 对方直播间号 + */ + public void exitChannelToUid(int uid, String liveUid){ + RtcConnection rtcConnection = new RtcConnection(); + rtcConnection.channelId = getChannelName(liveUid); //對方主播的頻道 + rtcConnection.localUid = uid;//自己的ID + mRtcEngine.leaveChannelEx(rtcConnection); + } + public static String getChannelName(String liveUid) { return CommonAppConfig.SWChannelPrefix + liveUid; } diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 6fa380edf..cd51c1ea4 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -123,7 +123,7 @@ public class SWManager extends BaseCacheManager { anchorContainer.addView(surfaceView); Config config = new Config(mContext, mRtcEngine, FURenderer.INSTANCE.mFURenderKit, null, CaptureMode.Agora, 0, false, new CameraConfig(MirrorMode.MIRROR_NONE,MirrorMode.MIRROR_NONE)); faceUnityBeautyAPI.initialize(config); - faceUnityBeautyAPI.enable(true); + faceUnityBeautyAPI.enable(false); faceUnityBeautyAPI.setBeautyPreset(BeautyPreset.CUSTOM); //FaceUnityBeautyManage.getInstance().mFURenderKit.setFaceBeauty(); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index a8a7db008..170ade09c 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -315,7 +315,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl private void initFaceManager() { manager = new FaceManager(); manager.initFURender(mContext); - manager.drawRongFrame(mContext); + //暂时去掉 + //manager.drawRongFrame(mContext); } public boolean isStartPreview() { @@ -1353,34 +1354,39 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (obj != null) { if (obj.getString("ispk").equals("0")) { - IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { + // TODO: 2024/4/19 邀请主播进行多人连麦 + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LIVE_DRPK) + .param("action", 1) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", pkUid) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + + String targetId = "g" + pkUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override - public void onSuccess() { - if (!extra.equals(SOCKET_LIVE_DRPK_RANDOM)) { - if (WordUtil.isNewZh()) { - ToastUtil.show("邀请 " + pkUid + " 发送成功"); - } else { - ToastUtil.show("invite " + pkUid + " successful"); - } - } - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); + public void onAttached(Message message) { + } @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - //todo 安卓端状态码说明文档:https://docs.rongcloud.cn/v4/views/rtc/call/code/android.html - Log.e("ry", rtcErrorCode + "aaaaaa" + CommonAppConfig.getInstance().getUid() + "VDSSSS" + pkUid); + public void onSuccess(Message message) { + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(message.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); } }); } else { diff --git a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index 54afe4314..55e5044e4 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -490,7 +490,6 @@ public class LiveAudienceEvent extends BaseModel { SUD_GAME_CREATE_ROOM(75, "主播创建sud游戏"), PK_RANK_START(76, "PK排位赛开始"), GuardSpecialEffect(77, "PK排位赛开始"); - private int type; private String name; diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java index 356827e93..dd9aeb4c0 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java @@ -387,7 +387,7 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { //接受PK回调 private void pkAccept() { - mTRTCCloud1 = LivePushTxViewHolder.mTRTCCloud.createSubCloud(); + /*mTRTCCloud1 = LivePushTxViewHolder.mTRTCCloud.createSubCloud(); mTRTCParams1 = new TRTCCloudDef.TRTCParams(); mTRTCParams1.sdkAppId = GenerateTestUserSig.SDKAPPID; mTRTCParams1.userId = CommonAppConfig.getInstance().getUid() + "pk"; @@ -396,7 +396,7 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { mTRTCParams1.role = TRTCCloudDef.TRTCRoleAudience; mTRTCCloud1.enterRoom(mTRTCParams1, TRTC_APP_SCENE_LIVE); mTRTCCloud1.startRemoteView(mApplyUid, LivePushTxViewHolder.mPreView1); - mTRTCCloud1.setListener(new TRTCCloudImplListener(mContext)); + mTRTCCloud1.setListener(new TRTCCloudImplListener(mContext));*/ LivePushTxViewHolder.btn_close.setVisibility(View.VISIBLE); SocketLinkMicPkUtil.linkMicPkAccept(mSocketClient, mApplyUid, mApplyUrl, mApplyNmae); onLinkMicPkStart(mApplyUid, mApplyUrl, mApplyNmae); @@ -734,19 +734,9 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); } if (mAcceptPk) { - - LivePushTxViewHolder.btn_close.setVisibility(View.VISIBLE); - - //把画面设置成九宫格 dr_pk_view.setVisibility(View.VISIBLE); - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mPreView.getLayoutParams(); - params.width = mPreView.getWidth() / 2; - params.height = DpUtil.dp2px(250); - params.topMargin = DpUtil.dp2px(130); - mPreView.setLayoutParams(params); - HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive") .params("uid", CommonAppConfig.getInstance().getUid()) @@ -757,7 +747,6 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess(int code, String msgs, String[] info) { if (code == 0) { - HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") .params("uid", CommonAppConfig.getInstance().getUid()) .params("roomid", u.getId()) @@ -768,15 +757,6 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { public void onSuccess(int code, String msgs, String[] info) { if (code == 0) { JSONObject obj = JSON.parseObject(info[0]); - - if (LiveLinkMicPkPresenter.mTRTCCloud1 != null && LivePushTxViewHolder.mTRTCCloud != null) { - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mContext.getResources().getDimensionPixelOffset(R.dimen.live_view)); - params.weight = 1; - params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - LivePushTxViewHolder.mPreView.setLayoutParams(params); - LivePushTxViewHolder.mPreView1.setLayoutParams(params); - } - List list = JSON.parseArray(obj.getString("userlist"), DrPkbean.class); for (int ii = 0, size = list.size(); ii < size; ii++) { @@ -786,31 +766,6 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { } for (int i = 0, size = list.size(); i < size; i++) { if (!String.valueOf(list.get(i).getId()).equals(CommonAppConfig.getInstance().getUid())) { - Log.i("tsss11", list.size() + "啊啊啊" + list.get(i).getId() + ""); - mTRTCCloud1 = LivePushTxViewHolder.mTRTCCloud.createSubCloud(); - mTRTCParams1 = new TRTCCloudDef.TRTCParams(); - mTRTCParams1.sdkAppId = GenerateTestUserSig.SDKAPPID; - mTRTCParams1.userId = CommonAppConfig.getInstance().getUid() + "pk"; - mTRTCParams1.roomId = list.get(i).getId(); - mTRTCParams1.userSig = GenerateTestUserSig.genTestUserSig(mTRTCParams1.userId); - mTRTCParams1.role = TRTCCloudDef.TRTCRoleAudience; - if (i == 1) { - mTRTCCloud1.enterRoom(mTRTCParams1, TRTC_APP_SCENE_LIVE); - mTRTCCloud1.startRemoteView(list.get(i).getId() + "", LivePushTxViewHolder.dr1_preview); - mTRTCCloud1.setListener(new LiveLinkMicPkPresenter.TRTCCloudImplListener(mContext)); - } else if (i == 2) { - mTRTCCloud1.enterRoom(mTRTCParams1, TRTC_APP_SCENE_LIVE); - mTRTCCloud1.startRemoteView(list.get(i).getId() + "", LivePushTxViewHolder.dr2_preview); - mTRTCCloud1.setListener(new LiveLinkMicPkPresenter.TRTCCloudImplListener(mContext)); - } else if (i == 3) { - mTRTCCloud1.enterRoom(mTRTCParams1, TRTC_APP_SCENE_LIVE); - mTRTCCloud1.startRemoteView(list.get(i).getId() + "", LivePushTxViewHolder.dr3_preview); - mTRTCCloud1.setListener(new LiveLinkMicPkPresenter.TRTCCloudImplListener(mContext)); - } else if (i == 4) { - mTRTCCloud1.enterRoom(mTRTCParams1, TRTC_APP_SCENE_LIVE); - mTRTCCloud1.startRemoteView(list.get(i).getId() + "", LivePushTxViewHolder.dr4_preview); - mTRTCCloud1.setListener(new LiveLinkMicPkPresenter.TRTCCloudImplListener(mContext)); - } Log.i("ssxcs", list.get(i).getId() + ""); final SocketSendBean msg = new SocketSendBean() .param("_method_", Constants.SOCKET_LIVE_DRPK) @@ -842,8 +797,6 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { } }); - - } } }); diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index cd382ddeb..41a6a268a 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -1243,99 +1243,90 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { agree = false; } boolean finalAgree = agree; - IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, agree, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - if (finalAgree == true) { - HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("roomid", u.getId()) - .execute(new HttpCallback() { + if (finalAgree) { + HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("roomid", u.getId()) + .execute(new HttpCallback() { + + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i("多人PK", "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LIVE_DRPK) + .param("action", 10) + .param("uid", CommonAppConfig.getInstance().getUid()); + msg1.create(); + String targetId = "g" + CommonAppConfig.getInstance().getUid(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } @Override - public void onSuccess(int code, String msg, String[] info) { - Log.i("多人PK", "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LIVE_DRPK) - .param("action", 10) - .param("uid", CommonAppConfig.getInstance().getUid()); - msg1.create(); - String targetId = "g" + CommonAppConfig.getInstance().getUid(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗"); - } - }); - if (info.length == 0) { - return; - } - JSONObject obj = JSONObject.parseObject(info[0]); - JSONArray users = obj.getJSONArray("userlist"); - - //添加水印 -// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f); -// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect); - dRjoinOtherRoom(u.getId(), 1); - - for (int i = 0; i < users.size(); i++) { - JSONObject user = users.getJSONObject(i); - Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { - /** - * 向指定用户发送跨房间连麦请求 - *

- * 1: inviterAutoMix为true时: - * - * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 - * - * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 - * - * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 - *

- */ - IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - }); - } - } + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); } } - }); - } - } - @Override - public void onFailed(RTCErrorCode errorCode) { - ToastUtil.show("接受失败"); - } - }); + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗"); + } + }); + if (info.length == 0) { + return; + } + JSONObject obj = JSONObject.parseObject(info[0]); + JSONArray users = obj.getJSONArray("userlist"); + + //添加水印 +// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f); +// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect); + dRjoinOtherRoom(u.getId(), 1); + livePushRyViewHolder.setAnDrPkRtc(u.getId()); + + for (int i = 0; i < users.size(); i++) { + JSONObject user = users.getJSONObject(i); + Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); + if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { + if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { + /** + * 向指定用户发送跨房间连麦请求 + *

+ * 1: inviterAutoMix为true时: + * + * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 + * + * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 + * + * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 + *

+ */ + IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { + @Override + public void onSuccess() { + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + }); + } + } + } + } + }); + } } else { ToastUtil.show(msg); } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index c76564e77..f5c30219f 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -309,10 +309,10 @@ public class SocketRyClient { } //收到对方同意多人PK邀请 else if (action3 == 2) { -// UserBean u = new UserBean(); -//// u.setUserNiceName(map.getString("uname")); -// u.setId(map.getString("uid")); -// mListener.onLinkDRMicPkApplyOk(u); + UserBean u = new UserBean(); +// u.setUserNiceName(map.getString("uname")); + u.setId(map.getString("uid")); + mListener.onLinkDRMicPkApplyOk(u); } else if (action3 == 6) {//开始Pk if (LiveRoomViewHolder.mHandler != null) { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); @@ -1307,7 +1307,7 @@ public class SocketRyClient { break; case 9://pk结束的回调 mListener.onLinkMicPkEnd(map.getString("win_uid")); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END)); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END).setObject(map.getString("uid"))); if (livePushRyViewHolder != null) { livePushRyViewHolder.onLinkMicAnchorClose(); } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index df57ab96b..d9f6c0793 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -96,7 +96,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private ViewGroup mSmallContainer; private ViewGroup mLeftContainer; private ViewGroup mRightContainer; - private RelativeLayout mPkContainer; + private ViewGroup mPkContainer; public StyledPlayerView mVideoView; private FrameLayout playFrameLayout; @@ -158,7 +158,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mSmallContainer = (ViewGroup) findViewById(R.id.small_container); mLeftContainer = (ViewGroup) findViewById(R.id.left_container); mRightContainer = (ViewGroup) findViewById(R.id.right_container); - mPkContainer = (RelativeLayout) findViewById(R.id.pk_container); + mPkContainer = (FrameLayout) findViewById(R.id.pk_container); mVideoView = (StyledPlayerView) findViewById(R.id.video_view); ry_view = (FrameLayout) findViewById(R.id.ry_view); leave = (ImageView) findViewById(R.id.leave); @@ -179,15 +179,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void initSwEngine(String liveUid) { this.liveUid = liveUid; + //初始化声网SDK swAuManager = SWAuManager.get(); swAuManager.setAudienceContainer(ry_view); swAuManager.initRtcEngine((Activity) mContext); swAuManager.setupRemoteVideo(Integer.parseInt(liveUid)); + //进入主播房间 swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); - - //测试-模拟PK场景,加入第二个主播视图 - swAuManager.setPkContainer1(playFrameLayout1); - swAuManager.joinExRoomEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); } @Override @@ -232,11 +230,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + /* RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = RelativeLayout.LayoutParams.MATCH_PARENT; params1.topMargin = 0; ry_view.setLayoutParams(params1); - ry_view.requestLayout(); + ry_view.requestLayout();*/ RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = RelativeLayout.LayoutParams.MATCH_PARENT; params2.topMargin = 0; @@ -252,12 +250,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = vHeight; params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); params1.addRule(RelativeLayout.ALIGN_TOP); ry_view.setLayoutParams(params1); - ry_view.requestLayout(); + ry_view.requestLayout();*/ RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = DpUtil.dp2px(270); params2.topMargin = DpUtil.dp2px(120); @@ -373,12 +371,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + /* RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = ViewGroup.LayoutParams.WRAP_CONTENT; params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); params1.addRule(RelativeLayout.ALIGN_TOP); ry_view.setLayoutParams(params1); - ry_view.requestLayout(); + ry_view.requestLayout();*/ RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = DpUtil.dp2px(270); params2.topMargin = DpUtil.dp2px(120); @@ -422,11 +420,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params.addRule(RelativeLayout.ALIGN_TOP); mVideoView.requestLayout(); - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = vHeight; params1.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top); params1.addRule(RelativeLayout.ALIGN_TOP); - ry_view.requestLayout(); + ry_view.requestLayout();*/ isPk = true; } @@ -453,11 +451,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = height; params1.topMargin = 0; ry_view.setLayoutParams(params1); - ry_view.requestLayout(); + ry_view.requestLayout();*/ RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = height; params2.topMargin = 0; @@ -475,7 +473,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = height; params1.topMargin = 0; params1.addRule(RelativeLayout.ALIGN_TOP); @@ -483,7 +481,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); } ry_view.setLayoutParams(params1); - ry_view.requestLayout(); + ry_view.requestLayout();*/ RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = height; params2.topMargin = DpUtil.dp2px(120); @@ -668,37 +666,24 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { confirm = "accept"; cancel = "cancel"; } - DialogUitl.Builder builder = new DialogUitl.Builder(mContext) - .setContent(content) - .setTitle(mLiveBean.getUserNiceName()) - .setConfirmString(confirm) - .setCancelString(cancel) - .setView(R.layout.dialog_live_mic_invite) - .setClickCallback(new DialogUitl.SimpleCallback() { + DialogUitl.Builder builder = new DialogUitl.Builder(mContext).setContent(content).setTitle(mLiveBean.getUserNiceName()).setConfirmString(confirm).setCancelString(cancel).setView(R.layout.dialog_live_mic_invite).setClickCallback(new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + String[] permissions; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + permissions = new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.RECORD_AUDIO}; + } else { + permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}; + } + LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { @Override - public void onConfirmClick(Dialog dialog, String content) { - String[] permissions; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - permissions = new String[]{ - Manifest.permission.READ_MEDIA_IMAGES, - Manifest.permission.RECORD_AUDIO - }; - } else { - permissions = new String[]{ - Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE, - Manifest.permission.RECORD_AUDIO - }; - } - LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { - @Override - public void run() { - UsertoRY(); + public void run() { + UsertoRY(); - } - }); } }); + } + }); builder.build().show(); } else if ("endMic".equals(str)) { @@ -776,11 +761,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { EasyFloat.dismiss("Debug"); return; } - EasyFloat.with(mContext) - .setDragEnable(true) - .setTag("Debug") - .setLayout(debugView) - .show(); + EasyFloat.with(mContext).setDragEnable(true).setTag("Debug").setLayout(debugView).show(); } } @@ -798,79 +779,71 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { break; } - LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, - IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR), - ban, - true); - new XPopup.Builder(mContext) - .setPopupCallback(new XPopupCallback() { - @Override - public void onCreated(BasePopupView popupView) { + LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR), ban, true); + new XPopup.Builder(mContext).setPopupCallback(new XPopupCallback() { + @Override + public void onCreated(BasePopupView popupView) { - } + } - @Override - public void beforeShow(BasePopupView popupView) { + @Override + public void beforeShow(BasePopupView popupView) { - } + } - @Override - public void onShow(BasePopupView popupView) { + @Override + public void onShow(BasePopupView popupView) { - } + } - @Override - public void onDismiss(BasePopupView popupView) { - int selectClarity = liveClarityCustomPopup.getSelectClarity(); - if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR)) - return; - if (selectClarity == PLAY_MODEL_ANCHOR) { - switchStream(srcUrl, PLAY_MODEL_DEF); - setAudiencePlayModel(selectClarity); - } else { - switchStream(srcUrl, selectClarity); - } - IMLoginManager.get(mContext).put(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, selectClarity); - showToast(); - } + @Override + public void onDismiss(BasePopupView popupView) { + int selectClarity = liveClarityCustomPopup.getSelectClarity(); + if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR)) + return; + if (selectClarity == PLAY_MODEL_ANCHOR) { + switchStream(srcUrl, PLAY_MODEL_DEF); + setAudiencePlayModel(selectClarity); + } else { + switchStream(srcUrl, selectClarity); + } + IMLoginManager.get(mContext).put(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, selectClarity); + showToast(); + } - private void showToast() { - if (WordUtil.isNewZh()) { - DialogUitl.showToast(mContext, "設置成功\n" + - "正在為你轉換中", 3000); - } else { - DialogUitl.showToast(mContext, "successful\n" + - "It's being converted for you", 3000); - } - } + private void showToast() { + if (WordUtil.isNewZh()) { + DialogUitl.showToast(mContext, "設置成功\n" + "正在為你轉換中", 3000); + } else { + DialogUitl.showToast(mContext, "successful\n" + "It's being converted for you", 3000); + } + } - @Override - public void beforeDismiss(BasePopupView popupView) { + @Override + public void beforeDismiss(BasePopupView popupView) { - } + } - @Override - public boolean onBackPressed(BasePopupView popupView) { - return false; - } + @Override + public boolean onBackPressed(BasePopupView popupView) { + return false; + } - @Override - public void onKeyBoardStateChanged(BasePopupView popupView, int height) { + @Override + public void onKeyBoardStateChanged(BasePopupView popupView, int height) { - } + } - @Override - public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { + @Override + public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { - } + } - @Override - public void onClickOutside(BasePopupView popupView) { + @Override + public void onClickOutside(BasePopupView popupView) { - } - }) - .asCustom(liveClarityCustomPopup) - .show(); + } + }).asCustom(liveClarityCustomPopup).show(); } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.FONT_SIZE) { int fount = 0; try { @@ -881,11 +854,24 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { new LiveFontSizeSettingDialog(mContext, fount).setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(Integer bean, int position) { - EventBus.getDefault().post(new LiveAudienceEvent() - .setNums(bean) - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE)); + EventBus.getDefault().post(new LiveAudienceEvent().setNums(bean).setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE)); } }).showDialog(); + } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.PK_TWO_START) { + //将当前主播画面换个画布展示 + swAuManager.updateMyChannelView((FrameLayout) mLeftContainer, Integer.parseInt(liveUid)); + ry_view.removeAllViews(); + + //加入对方主播房间 + swAuManager.setPkContainer1((FrameLayout) mRightContainer); + String pkUid = (String) event.getObject(); + swAuManager.joinExRoomEx(Integer.parseInt(pkUid), CommonAppConfig.SWToken, SWAuManager.getChannelName(pkUid)); + } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_PK_END) { + String pkUid = (String) event.getObject(); + swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), SWAuManager.getChannelName(pkUid)); + swAuManager.updateMyChannelView(ry_view, Integer.parseInt(liveUid)); + mLeftContainer.removeAllViews(); + mRightContainer.removeAllViews(); } } @@ -904,9 +890,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO - .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) - .setLiveRole(RCRTCLiveRole.AUDIENCE) - .build(); + .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO).setLiveRole(RCRTCLiveRole.AUDIENCE).build(); RCRTCEngine.getInstance().joinRoom(LiveActivity.mLiveUid, roomConfig, new IRCRTCResultDataCallback() { @@ -1088,8 +1072,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { break; } // 示例代码使用480x640分辨率演示 - RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig - .Builder.create() + RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig.Builder.create() //设置分辨率 .setVideoResolution(rcrtcVideoResolution) //设置帧率 @@ -1097,8 +1080,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { //设置最小码率,480P下推荐200 .setMinRate(minRate) //设置最大码率,480P下推荐900 - .setMaxRate(maxRate) - .build(); + .setMaxRate(maxRate).build(); RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); // 创建视图渲染视图 // RCRTCVideoView videoView = new RCRTCVideoView(contexts); @@ -1156,11 +1138,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { ((RCRTCVideoInputStream) stream).setVideoFrameListener(new IRCRTCVideoInputFrameListener() { @Override public void onFrame(RCRTCRemoteVideoFrame videoFrame) { - String debugText = " 2、安卓主播开播, 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" + - "rotation:" + videoFrame.getRotation() + "\n" + - "timestampNs:" + videoFrame.getTimestampNs() + "\n" + - "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + - "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n"; + String debugText = " 2、安卓主播开播, 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" + "rotation:" + videoFrame.getRotation() + "\n" + "timestampNs:" + videoFrame.getTimestampNs() + "\n" + "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n"; //Log.d("ry", "onFrame: " + debugText); new Handler(Looper.getMainLooper()).post(() -> { debugView.setText(debugText); @@ -1190,14 +1168,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); audioManager.setSpeakerphoneOn(true); - HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm") - .params("roomid", LiveActivity.mLiveUid) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.e("ry", code + "热热热"); - } - }); + HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm").params("roomid", LiveActivity.mLiveUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.e("ry", code + "热热热"); + } + }); } @Override @@ -1232,16 +1208,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private void showLoadingDialog() { if (PLAY_MODEL == PLAY_MODEL_480) return; - new DialogUitl.Builder(mContext) - .setTitle("網絡提示") - .setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。") - .setView(R.layout.dialog_simple_tip) - .setClickCallback(new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - dialog.dismiss(); - } - }).build().show(); + new DialogUitl.Builder(mContext).setTitle("網絡提示").setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。").setView(R.layout.dialog_simple_tip).setClickCallback(new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + dialog.dismiss(); + } + }).build().show(); PLAY_MODEL = PLAY_MODEL_480; String url = srcUrl; if (videoLandscape == VIDEO_VERTICAL) { diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index d9f2c2e11..80d2795c7 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -50,6 +50,7 @@ import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; +import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; @@ -83,6 +84,7 @@ import cn.rongcloud.rtc.base.RCRTCParamsType; import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.SWAuManager; import io.agora.beautyapi.faceunity.agora.SWManager; +import io.rong.imkit.userinfo.db.model.User; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; @@ -228,7 +230,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX UserBean userBean = new UserBean(); userBean.setId(inviterRoomId); //收到邀请这个时候正在PK或连麦中 自动拒绝对方 - if (isPking() == true) { + if (isPking()) { rtcRoom.getLocalUser().responseJoinOtherRoom(userBean.getId(), userBean.getId(), false, false, "extra", new IRCRTCResultCallback() { @@ -615,18 +617,43 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX //清除 mBigContainer 中的渲染 mBigContainer.removeAllViews(); - + btn_close.setVisibility(View.VISIBLE); //设置对方主播的渲染视图 设置到 rightContainer swManager.setPkContainer1(mRightContainer); swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,u.getId(), SWAuManager.getChannelName(u.getId())); } } + public void setAnDrPkRtc(String uid) { + if (swManager != null && StringUtil.isEmpty(uid)) { + L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid); + + //将自己的渲染视图设置到 leftContainer + swManager.updateMyChannelView((FrameLayout) mLeftContainer); + + //清除 mBigContainer 中的渲染 + mBigContainer.removeAllViews(); + btn_close.setVisibility(View.VISIBLE); + //设置对方主播的渲染视图 设置到 rightContainer + swManager.setPkContainer1(mRightContainer); + swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,uid, SWAuManager.getChannelName(uid)); + } + } + + public void onLinkMicAnchorClose(){ swManager.updateMyChannelView((FrameLayout) mBigContainer); LivePushRyViewHolder.btn_close.setVisibility(View.GONE); } + public void onLinkDRMicPkApply(UserBean userBean){ + if (mLiveRyLinkMicPkPresenter != null) { + mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(userBean); + } + } + + + @Override public void changeToLeft() { if (mPreView != null) { diff --git a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java index d2be9d442..828916dd6 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -130,7 +130,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { public void onClick(View view) { if (pk_nub <= 0) return; //開始多人PK - HttpClient.getInstance().post("live.startDRPK", "live.startDRPK") + HttpClient.getInstance().get("live.startDRPK", "live.startDRPK") .params("roomid", CommonAppConfig.getInstance().getUid()) .execute(new HttpCallback() { @Override diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index 4eea26aeb..5830a365b 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -45,12 +45,11 @@ android:src="@mipmap/zslk" android:visibility="gone" /> - - + android:layout_width="match_parent" + android:layout_height="270dp" + android:layout_marginTop="130dp"> - + Date: Mon, 22 Apr 2024 18:28:01 +0800 Subject: [PATCH 06/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=A4=9A=E4=BA=BAPK]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beautyapi/faceunity/agora/SWManager.java | 121 ++- .../presenter/LiveRyLinkMicPkPresenter.java | 802 ++++++------------ .../yunbao/live/socket/SocketRyClient.java | 3 +- .../live/views/LivePushRyViewHolder.java | 223 +++-- .../src/main/res/layout/view_live_push_ry.xml | 44 +- 5 files changed, 467 insertions(+), 726 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index cd51c1ea4..31228560f 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -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 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) { diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 41a6a268a..003fc065d 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -37,6 +37,7 @@ import android.widget.TextView; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; import com.tencent.trtc.TRTCCloud; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.LiveInfoModel; @@ -60,6 +61,7 @@ import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.bean.LivePKUserListBean; import com.yunbao.live.custom.ProgressTextView; import com.yunbao.live.event.LiveAudienceEvent; @@ -161,6 +163,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public static List inputStreamList1 = new ArrayList<>(); private boolean DRInitiator = false;//是否是duorenPK发起人 + private List drPkbeans = new ArrayList<>(); + public LiveRyLinkMicPkPresenter setDRInitiator(boolean DRInitiator) { this.DRInitiator = DRInitiator; return this; @@ -395,50 +399,34 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { Log.i("tts2", s1); mLiveLinkMicPkViewHolder.setTime(s + " " + s1); if (s1.equals("00:01") && mIsAnchor && !s.contains("懲罰")) { - HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("addtime", "00:00") - .params("type", "0") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - JSONObject datas = JSONObject.parseObject(info[0]); + HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK").params("uid", CommonAppConfig.getInstance().getUid()).params("addtime", "00:00").params("type", "0").params("sign", "1").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + JSONObject datas = JSONObject.parseObject(info[0]); - SocketSendBean seed_msg = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 9) - .param("msgtype", 10) - .param("win_uid", datas.getString("win_uid")) - .param("uid", CommonAppConfig.getInstance().getUid()); - seed_msg.create(); - String pkUid = datas.getString("pkuid"); - Log.i("seed", seed_msg.mResult.toString()); + SocketSendBean seed_msg = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); + seed_msg.create(); + String pkUid = datas.getString("pkuid"); + Log.i("seed", seed_msg.mResult.toString()); - Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid")); + Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid")); - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + pkUid) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - } - }); - } - }); + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + } + }); } - } - }); + }); + + } + } + }); } } @@ -522,140 +510,14 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { showDRApplyDialog(u); } + /** * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 */ - public void onLinkDRMicPkApplyOk(UserBean u) { - /** - * 加入副房间 - * - * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 - * - * @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_` - * @param callBack 加入房间回调 - * @group 房间管理 - */ - RCRTCEngine.getInstance().joinOtherRoom("" + u.getId(), new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - runOnUiThread(new Runnable() { - @Override - public void run() { - //遍历远端用户列表 - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - - if (i == 1) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(mContext); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.mPreView1.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.mPreView1.addView(remoteView); - - } else if (i == 2) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 -// RCRTCVideoView remoteView = new RCRTCVideoView(mContext); -// ((RCRTCVideoInputStream) stream).setVideoView(remoteView); -// //todo 本demo只演示添加1个远端用户的视图 -// LivePushRyViewHolder.dr2_preview.removeAllViews(); -// remoteView.setScalingType(SCALE_ASPECT_FILL); -// LivePushRyViewHolder.dr2_preview.addView(remoteView); - } else if (i == 3) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 -// RCRTCVideoView remoteView = new RCRTCVideoView(mContext); -// ((RCRTCVideoInputStream) stream).setVideoView(remoteView); -// //todo 本demo只演示添加1个远端用户的视图 -// LivePushRyViewHolder.dr3_preview.removeAllViews(); -// remoteView.setScalingType(SCALE_ASPECT_FILL); -// LivePushRyViewHolder.dr3_preview.addView(remoteView); - } else if (i == 4) { - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 -// RCRTCVideoView remoteView = new RCRTCVideoView(mContext); -// ((RCRTCVideoInputStream) stream).setVideoView(remoteView); -// //todo 本demo只演示添加1个远端用户的视图 -// LivePushRyViewHolder.dr4_preview.removeAllViews(); -// remoteView.setScalingType(SCALE_ASPECT_FILL); -// LivePushRyViewHolder.dr4_preview.addView(remoteView); - } - //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 - inputStreamList.add(stream); - } - //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 - inputStreamList1.add(stream); - } - } - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); - //视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); - //大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); - //推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 - //如不设置宽高值则服务端将使用默认宽高 360 * 640 - //例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, - //所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 960; - int height = 720; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //1. 设置自适应合流布局模式 - config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); - //2. 合流画布设置 - if (rcrtcLiveInfo != null) { - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功" + u.getId()); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } else { - Log.w("PkDebug", "PK合流失败,rcrtcLiveInfo为空"); - } - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason()); - } - }); - + if(livePushRyViewHolder!=null){ + livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()),-1); + } } /** @@ -689,17 +551,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); LiveRyAnchorActivity.isDRPK = 1; - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); livePushRyViewHolder.setAnPkRtc(u);//设置对方主播视图 - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 4) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", u.getId()) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("pkhead", u.getAvatar()) - .param("pkname", u.getUserNiceName()); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 4).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", u.getId()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", u.getAvatar()).param("pkname", u.getUserNiceName()); msg1.create(); LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); @@ -740,14 +594,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { LiveRyAnchorActivity.isDRPK = 1; /*---------------------------------------------------------------- */ - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 2) //回复PK申请 2 - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 2) //回复PK申请 2 + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); System.out.println("PK回执 = " + msg1.toString()); Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; @@ -776,8 +624,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { livePushRyViewHolder.setAnPkRtc(bean); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); LiveRyAnchorActivity.isDRPK = 1; LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); SocketRyLinkMicPkUtil.linkMicPkAccept(mSocketRyClient, mApplyUid, mApplyUrl, mApplyNmae); @@ -885,9 +732,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 8); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); msg1.create(); String targetId = u.getId(); @@ -1071,82 +916,70 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 随机PK拒绝对话框 */ public void showPkDialog(UserBean u) { - new DialogUitl.Builder(mContext) - .setHtmlCode(Html.fromHtml( - "有人向您发起PK请求。
" + - "若拒绝PK,将会10分钟内不会再收到任何随机PK请求。" - )) - .setConfirmString("接受") - .setCancelString("拒絕") - .setView(R.layout.dialog_live_random_pk) - .setSimpleCallbackView(new DialogUitl.SimpleCallbackView() { - boolean clickCancel = false; - String titleVal; - TimerTask task; + new DialogUitl.Builder(mContext).setHtmlCode(Html.fromHtml("有人向您发起PK请求。
" + "若拒绝PK,将会10分钟内不会再收到任何随机PK请求。")).setConfirmString("接受").setCancelString("拒絕").setView(R.layout.dialog_live_random_pk).setSimpleCallbackView(new DialogUitl.SimpleCallbackView() { + boolean clickCancel = false; + String titleVal; + TimerTask task; + + @Override + public void onShow(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + task = new TimerTask() { + int time = 11; + final Handler handler = new Handler(Looper.getMainLooper()); @Override - public void onShow(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - task = new TimerTask() { - int time = 11; - final Handler handler = new Handler(Looper.getMainLooper()); - - @Override - public void run() { - if (titleVal == null) { - titleVal = ((TextView) title).getText().toString(); - } - handler.post(() -> ((TextView) title).setText(titleVal + " " + time)); - if (time-- == 0) { - handler.post(() -> showClose(dialog, title, context, confirmBtn, cancelBtn)); - cancel(); - } - } - }; - new Timer().schedule(task, 1000, 1000); - } - - @Override - public void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - dialog.dismiss(); - task.cancel(); - apply(); - } - - @Override - public void onCancel(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - if (!clickCancel) { - titleVal = "拒絕PK提示"; - ((TextView) context).setText(Html.fromHtml( - "若拒絕PK,將會關閉你的隨機PK開關。
" + - "並且10分鍾不會收到任何隨機PK請求。
" - )); - ((TextView) cancelBtn).setText("堅持拒絕"); - clickCancel = true; - return; + public void run() { + if (titleVal == null) { + titleVal = ((TextView) title).getText().toString(); + } + handler.post(() -> ((TextView) title).setText(titleVal + " " + time)); + if (time-- == 0) { + handler.post(() -> showClose(dialog, title, context, confirmBtn, cancelBtn)); + cancel(); } - showClose(dialog, title, context, confirmBtn, cancelBtn); } + }; + new Timer().schedule(task, 1000, 1000); + } - void showClose(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - task.cancel(); - ((TextView) title).setText("您因拒絕隨機PK,被限制關閉中"); - ((TextView) confirmBtn).setText("确定"); - ((TextView) context).setText("隨機PK可打開時間:" + new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis() + 7200000)));//7200000ms=120m=2h - ((TextView) context).setTextSize(12); - ((TextView) context).setTextColor(Color.parseColor("#999999")); - refusePk(u); - cancelBtn.setVisibility(View.GONE); - confirmBtn.setOnClickListener(v -> { - dialog.dismiss(); - }); - } + @Override + public void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + dialog.dismiss(); + task.cancel(); + apply(); + } + + @Override + public void onCancel(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + if (!clickCancel) { + titleVal = "拒絕PK提示"; + ((TextView) context).setText(Html.fromHtml("若拒絕PK,將會關閉你的隨機PK開關。
" + "並且10分鍾不會收到任何隨機PK請求。
")); + ((TextView) cancelBtn).setText("堅持拒絕"); + clickCancel = true; + return; + } + showClose(dialog, title, context, confirmBtn, cancelBtn); + } + + void showClose(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + task.cancel(); + ((TextView) title).setText("您因拒絕隨機PK,被限制關閉中"); + ((TextView) confirmBtn).setText("确定"); + ((TextView) context).setText("隨機PK可打開時間:" + new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis() + 7200000)));//7200000ms=120m=2h + ((TextView) context).setTextSize(12); + ((TextView) context).setTextColor(Color.parseColor("#999999")); + refusePk(u); + cancelBtn.setVisibility(View.GONE); + confirmBtn.setOnClickListener(v -> { + dialog.dismiss(); + }); + } - void apply() { - isPK(u); - } - }) - .build().show(); + void apply() { + isPK(u); + } + }).build().show(); } private void refusePk(UserBean u) { @@ -1159,8 +992,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) // .param("randomPk",u.isRandomPk()+"") .param("action", 3); msg1.create(); @@ -1218,126 +1050,121 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } if (mAcceptPk) { - HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("pkuid", u.getId()) - .params("type", "1") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msgs, String[] info) { - if (code == 0) { - Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); - HttpClient.getInstance().get("live.getdrnum", "live.getdrnum") - .execute(new HttpCallback() { + HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive").params("uid", CommonAppConfig.getInstance().getUid()).params("pkuid", u.getId()).params("type", "1").params("sign", "1").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msgs, String[] info) { + if (code == 0) { + Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); + HttpClient.getInstance().get("live.getdrnum", "live.getdrnum").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + if (info.length > 0) { + JSONObject datas = JSONObject.parseObject(info[0]); + boolean agree = true; + if (datas.getIntValue("pk_num_day") <= 0) { + ToastUtil.show("多人PK次数已用完"); + agree = false; + } + boolean finalAgree = agree; + if (finalAgree) { + HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", u.getId()).execute(new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { - Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - if (info.length > 0) { - - JSONObject datas = JSONObject.parseObject(info[0]); - boolean agree = true; - if (datas.getIntValue("pk_num_day") <= 0) { - ToastUtil.show("多人PK次数已用完"); - agree = false; - } - boolean finalAgree = agree; - if (finalAgree) { - HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("roomid", u.getId()) - .execute(new HttpCallback() { - - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.i("多人PK", "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LIVE_DRPK) - .param("action", 10) - .param("uid", CommonAppConfig.getInstance().getUid()); - msg1.create(); - String targetId = "g" + CommonAppConfig.getInstance().getUid(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗"); - } - }); - if (info.length == 0) { - return; - } - JSONObject obj = JSONObject.parseObject(info[0]); - JSONArray users = obj.getJSONArray("userlist"); - - //添加水印 -// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f); -// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect); - dRjoinOtherRoom(u.getId(), 1); - livePushRyViewHolder.setAnDrPkRtc(u.getId()); - - for (int i = 0; i < users.size(); i++) { - JSONObject user = users.getJSONObject(i); - Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { - /** - * 向指定用户发送跨房间连麦请求 - *

- * 1: inviterAutoMix为true时: - * - * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 - * - * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 - * - * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 - *

- */ - IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - }); - } - } - } - } - }); - } - } else { - ToastUtil.show(msg); + L.eSw("多人PK"+ "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + if (info.length == 0) { + return; } + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"),DrPkbean.class); + for (int i = 0; i + * 1: inviterAutoMix为true时: + * + * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 + * + * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 + * + * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 + *

+ *//* + IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { + @Override + public void onSuccess() { + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + }); + } + } + }*/ } - }); - - + } + } else { + ToastUtil.show(msg); + } } - } - }); + + }); + + + } + } + }); } else { @@ -1351,9 +1178,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 8); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); msg1.create(); String targetId = u.getId(); @@ -1393,9 +1218,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 3); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 3); msg1.create(); String targetId = u.getId(); @@ -1444,183 +1267,53 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void dRjoinOtherRoom(String uid, int i) { Log.e("ry", uid + "洒洒" + i + "VVVV" + i); mApplyUid = uid; - RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - //把多人PK的View显示出来 - if (livePushRyViewHolder.dr_pk_view.getVisibility() == View.GONE) { - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); - params.weight = 1; - params.topMargin = DpUtil.dp2px(123); - livePushRyViewHolder.dr_pk_view.setLayoutParams(params); - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.dr_pk_view.setVisibility(View.VISIBLE); - livePushRyViewHolder.dr1_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr2_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr3_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr4_preview.setVisibility(View.GONE); - detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); - linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); - imageGrade1 = detailsView1.findViewById(R.id.image_grade1); - textGrade1 = detailsView1.findViewById(R.id.text_grade1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.mPreView.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.GONE); - } + /*new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + //把多人PK的View显示出来 + if (livePushRyViewHolder.dr_pk_view.getVisibility() == View.GONE) { + livePushRyViewHolder.dr_pk_view.setVisibility(View.VISIBLE); + livePushRyViewHolder.dr1_preview.setVisibility(View.GONE); + livePushRyViewHolder.dr2_preview.setVisibility(View.GONE); + livePushRyViewHolder.dr3_preview.setVisibility(View.GONE); + livePushRyViewHolder.dr4_preview.setVisibility(View.GONE); + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); + linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); + imageGrade1 = detailsView1.findViewById(R.id.image_grade1); + textGrade1 = detailsView1.findViewById(R.id.text_grade1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + livePushRyViewHolder.mPreView.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.GONE); + } - Log.e("ry", "多人接受成功" + mApplyUid); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - //遍历远端用户列表 - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - Log.e("ry", rcrtcOtherRoom.getRemoteUsers().get(i).getUserId() + "收到rcrtcOtherRoom" + rcrtcOtherRoom.getRemoteUsers().size()); - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry", i + "收到" + stream.getMediaType() + "实打实打算" + rcrtcOtherRoom.getRemoteUsers().get(i).getUserId()); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - if (inputStreamList.size() == 0) { - livePushRyViewHolder.dr1_preview.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(mContext); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.dr1_preview.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.dr1_preview.addView(remoteView); - - - LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(String.valueOf(uid)); - textPkName2.setText(data.getUserNicename()); - livePushRyViewHolder.dr1_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); - - } else if (inputStreamList.size() == 1) { - livePushRyViewHolder.dr3_preview.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(mContext); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.dr3_preview.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.dr3_preview.addView(remoteView); - LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(uid); - textPkName4.setText(data.getUserNicename()); - livePushRyViewHolder.dr3_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - - } - }); - } else if (inputStreamList.size() == 2) { - livePushRyViewHolder.cameraPreview3.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(mContext); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.cameraPreview3.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.cameraPreview3.addView(remoteView); - - LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); - linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); - textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); - imageGrade3 = detailsView3.findViewById(R.id.image_grade3); - textGrade3 = detailsView3.findViewById(R.id.text_grade3); - imageGrade3.setTag(uid); - textPkName3.setText(data.getUserNicename()); - livePushRyViewHolder.cameraPreview3.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.VISIBLE); - linearGrade3.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - - } - }); - } - inputStreamList.add(stream); - } - inputStreamList1.add(stream); - } - } - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - //2. 合流画布设置 - rcrtcLiveInfo.setMixConfig(create_Custom_MixConfig(false, inputStreamList), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "222混成功"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); + //设置多人PK数据 + LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(String.valueOf(uid)); + textPkName2.setText(data.getUserNicename()); + livePushRyViewHolder.dr1_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.GONE); + } + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); } }); - } - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); - Log.i("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); + Log.e("ry", "多人接受成功" + mApplyUid); + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); } - }); + });*/ } /** @@ -2327,7 +2020,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { String pkTime = StringUtil.getDurationText(time * 1000); livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime)); mPkTimeCount = time; - if (time>0){ + if (time > 0) { String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); mHandler.sendEmptyMessage(WHAT_PK_TIME2); @@ -2529,8 +2222,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); } - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); // endDRGif(); if (DRInitiator) { LiveNetManager.get(mContext).jieshuDRPK("" + IMLoginManager.get(mContext).getUserInfo().getId()); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index f5c30219f..4705298e8 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -323,8 +323,6 @@ public class SocketRyClient { // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); } - - } else if (action3 == 5) { // endDRGif(); LiveRoomViewHolder.d_pk_view.setVisibility(View.GONE); @@ -346,6 +344,7 @@ public class SocketRyClient { Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); isDRPK = 1; } else if (action3 == 10) { + //显示pk分数 if (!map.getString("uid").equals(CommonAppConfig.getInstance().getUid())) { // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 80d2795c7..2801022f1 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -84,7 +84,6 @@ import cn.rongcloud.rtc.base.RCRTCParamsType; import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.SWAuManager; import io.agora.beautyapi.faceunity.agora.SWManager; -import io.rong.imkit.userinfo.db.model.User; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; @@ -241,9 +240,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 8); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); msg1.create(); String targetId = userBean.getId(); @@ -497,92 +494,62 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX aheadOfScheduleEndPK(mPkUid, CommonAppConfig.getInstance().getUserBean().getUserNiceName(), (String) tv_avatarOther_name.getTag()); //断开连麦 LiveRyAnchorActivity.isDRPK = 0; - HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - } - }); + HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + } + }); - HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("addtime", "1") - .params("type", "1") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - JSONObject datas = JSONObject.parseObject(info[0]); - String pkUid = datas.getString("pkuid"); + HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK").params("uid", CommonAppConfig.getInstance().getUid()).params("addtime", "1").params("type", "1").params("sign", "1").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + JSONObject datas = JSONObject.parseObject(info[0]); + String pkUid = datas.getString("pkuid"); - //退出副房间 - // TODO: 2024/4/13 退出对方主播直播间 - SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),pkUid1); - SWManager.get().updateMyChannelView((FrameLayout) mBigContainer); - btn_close.setVisibility(View.GONE);//隐藏连麦按钮 - EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); - closeButtonGone(); + //退出副房间 + // TODO: 2024/4/13 退出对方主播直播间 + SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), pkUid1); + SWManager.get().updateMyChannelView((FrameLayout) mBigContainer); + btn_close.setVisibility(View.GONE);//隐藏连麦按钮 + EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); + closeButtonGone(); - SocketSendBean seed_msg = new SocketSendBean() - .param("_method_", Constants.SOCKET_LINK_MIC_PK) - .param("action", 9) - .param("msgtype", 10) - .param("win_uid", datas.getString("win_uid")) - .param("uid", CommonAppConfig.getInstance().getUid()); - seed_msg.create(); - Log.i("seed", seed_msg.mResult.toString()); - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + pkUid) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { + SocketSendBean seed_msg = new SocketSendBean().param("_method_", Constants.SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); + seed_msg.create(); + Log.i("seed", seed_msg.mResult.toString()); + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + SocketSendBean seed_msgs = new SocketSendBean().param("_method_", Constants.SOCKET_LINK_MIC_PK).param("action", 5).param("msgtype", 10).param("uname", "1").param("uimg", "1").param("pkuid", LiveRyLinkMicPkPresenter.oldmPkUid).param("uid", CommonAppConfig.getInstance().getUid()); + seed_msgs.create(); + Log.i("seed", seed_msgs.mResult.toString()); + + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + LiveRyLinkMicPkPresenter.oldmPkUid).params("jsonstr", seed_msgs.mResult.toString()).execute(new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msgs.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - SocketSendBean seed_msgs = new SocketSendBean() - .param("_method_", Constants.SOCKET_LINK_MIC_PK) - .param("action", 5) - .param("msgtype", 10) - .param("uname", "1") - .param("uimg", "1") - .param("pkuid", LiveRyLinkMicPkPresenter.oldmPkUid) - .param("uid", CommonAppConfig.getInstance().getUid()); - seed_msgs.create(); - Log.i("seed", seed_msgs.mResult.toString()); - - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + LiveRyLinkMicPkPresenter.oldmPkUid) - .params("jsonstr", seed_msgs.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) - .params("jsonstr", seed_msgs.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - } - }); - } - }); - } - }); + } + }); } }); - + } + }); } + }); - } - }); + } + + } + }); } @@ -608,6 +575,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX }); } + public void setAnPkRtc(UserBean u) { if (swManager != null && u != null) { L.eSw("设置对方主播的视图setAnPkRtc" + u); @@ -619,41 +587,73 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX mBigContainer.removeAllViews(); btn_close.setVisibility(View.VISIBLE); //设置对方主播的渲染视图 设置到 rightContainer - swManager.setPkContainer1(mRightContainer); - swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,u.getId(), SWAuManager.getChannelName(u.getId())); + swManager.setPkContainer(mRightContainer); + swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); } } - public void setAnDrPkRtc(String uid) { - if (swManager != null && StringUtil.isEmpty(uid)) { - L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid); + private int currentPosition = 0; - //将自己的渲染视图设置到 leftContainer - swManager.updateMyChannelView((FrameLayout) mLeftContainer); + private String drpkUid3 = ""; + public void setAnDrPkRtc(String uid, int position) { + FrameLayout frameLayout = null; + int temp= -1; + if (swManager != null && !StringUtil.isEmpty(uid)) { + L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid + "position:" + position); + if(currentPosition==0){ + position = 2; + } + if(position==-1){ + temp = currentPosition+1; + }else{ + temp = position; + } + switch (temp) { + case 2: + frameLayout = dr2_preview; + dr3_preview.setVisibility(View.GONE); + dr4_preview.setVisibility(View.GONE); + break; + case 3: + drpkUid3 = uid; + frameLayout = dr4_preview; + dr4_preview.setVisibility(View.VISIBLE); + break; + case 4: + dr3_preview.setVisibility(View.VISIBLE); + //將f3->f4 f4->f3 + dr3_preview.removeAllViews(); + swManager.updateDrChannelView(dr3_preview,SWAuManager.getChannelName(drpkUid3),drpkUid3); - //清除 mBigContainer 中的渲染 - mBigContainer.removeAllViews(); + dr4_preview.removeAllViews(); + frameLayout = dr4_preview; + break; + } + + if (temp == 2) { + swManager.updateMyChannelView(dr1_preview); + mBigContainer.removeAllViews(); + } + swManager.joinChannelDrEx(frameLayout,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); btn_close.setVisibility(View.VISIBLE); - //设置对方主播的渲染视图 设置到 rightContainer - swManager.setPkContainer1(mRightContainer); - swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,uid, SWAuManager.getChannelName(uid)); + dr_pk_view.setVisibility(View.VISIBLE); + currentPosition = temp; } } - public void onLinkMicAnchorClose(){ + public void onLinkMicAnchorClose() { swManager.updateMyChannelView((FrameLayout) mBigContainer); LivePushRyViewHolder.btn_close.setVisibility(View.GONE); } - public void onLinkDRMicPkApply(UserBean userBean){ + public void onLinkDRMicPkApply(UserBean userBean) { if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(userBean); } } - @Override public void changeToLeft() { if (mPreView != null) { @@ -907,29 +907,20 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } String ct = "由於 " + uname + " 退出比賽," + pkname + " 獲得勝利"; - SocketSendBean seed_msg = new SocketSendBean() - .param("_method_", Constants.SOCKET_SYSTEM) - .param("action", 1) - .param("ct", ct); + SocketSendBean seed_msg = new SocketSendBean().param("_method_", Constants.SOCKET_SYSTEM).param("action", 1).param("ct", ct); seed_msg.create(); - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + pkUid) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2") - .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) - .params("jsonstr", seed_msg.mResult.toString()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - } - }); } }); + } + }); } private Bitmap decodeResource(Resources resources, int id) { @@ -964,10 +955,10 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX }); } - public void setEnableBeauty(boolean flag){ - if(swManager!=null){ - swManager.setEnableBeauty(flag); - } + public void setEnableBeauty(boolean flag) { + if (swManager != null) { + swManager.setEnableBeauty(flag); + } } @Subscribe(threadMode = ThreadMode.MAIN) @@ -983,7 +974,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onDestroy() { super.onDestroy(); - if(swManager!=null){ + if (swManager != null) { swManager.exitChannelAll(); } } diff --git a/live/src/main/res/layout/view_live_push_ry.xml b/live/src/main/res/layout/view_live_push_ry.xml index 4bf171e2b..8fbd2a49a 100644 --- a/live/src/main/res/layout/view_live_push_ry.xml +++ b/live/src/main/res/layout/view_live_push_ry.xml @@ -1,6 +1,7 @@ @@ -13,6 +14,7 @@ android:id="@+id/camera" android:layout_width="match_parent" android:layout_height="match_parent" + android:visibility="gone" android:orientation="vertical"> + android:orientation="horizontal" + android:visibility="visible"> + android:orientation="vertical"> + android:background="@mipmap/live_icon_vacancy" + tools:ignore="NestedWeights" /> + android:orientation="vertical"> + android:background="@mipmap/live_icon_vacancy" + tools:ignore="NestedWeights" /> From 9320d6c2098c6fe882ce99fc5fdd206616871804 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Thu, 25 Apr 2024 14:13:25 +0800 Subject: [PATCH 07/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=8D=95=E4=BA=BApk,=E8=BF=9B=E5=85=A5=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E9=97=B4=E9=80=BB=E8=BE=91,=E5=8D=95=E4=BA=BAPK=E9=80=BB?= =?UTF-8?q?=E8=BE=91]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../faceunity/agora/SWAuManager.java | 60 ++- .../beautyapi/faceunity/agora/SWManager.java | 22 +- .../live/activity/LiveAnchorActivity.java | 1 + .../live/activity/LiveAudienceActivity.java | 7 +- .../live/activity/LiveRyAnchorActivity.java | 25 +- .../presenter/LiveLinkMicPkPresenter.java | 3 + .../presenter/LiveRyLinkMicPkPresenter.java | 417 +++++++++++------- .../yunbao/live/socket/SocketRyClient.java | 2 +- .../live/views/LivePlayKsyViewHolder.java | 15 +- .../live/views/LivePlayRyViewHolder.java | 112 ++++- .../live/views/LivePlayTxViewHolder.java | 6 + .../views/LivePlayTxViewHolder_backup.java | 6 + .../live/views/LivePushRyViewHolder.java | 35 +- .../live/views/LiveRoomPlayViewHolder.java | 14 + .../live/views/PortraitLiveManager.java | 28 +- .../main/res/layout/view_live_play_ksy.xml | 55 +++ .../src/main/res/layout/view_live_push_ry.xml | 7 +- 17 files changed, 579 insertions(+), 236 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index 28877628d..86fe52473 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -90,7 +90,6 @@ public class SWAuManager extends BaseCacheManager { mRtcEngine.setupRemoteVideo(videoCanvas); } - /** * 加入房间 */ @@ -155,6 +154,65 @@ public class SWAuManager extends BaseCacheManager { }); } + /** + * 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); + } + }); + } + + @Override + public void onLeaveChannel(RtcStats stats) { + super.onLeaveChannel(stats); + } + + @Override + public void onError(int err) { + super.onError(err); + L.eSw("onError:" + err); + } + }); + } + + /** * 退出对方直播间 * @param uid 自己的ID diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 31228560f..98c2124ab 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -134,6 +134,8 @@ public class SWManager extends BaseCacheManager { faceUnityBeautyAPI.setupLocalVideo(surfaceView, Constants.RENDER_MODE_HIDDEN); //faceUnityBeautyAPI.updateCameraConfig(new CameraConfig(MirrorMode.MIRROR_NONE,MirrorMode.MIRROR_NONE)); //mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); + setEnableBeauty(true); //默认开启美颜 + } public void setEnableBeauty(boolean flag){ @@ -279,26 +281,6 @@ public class SWManager extends BaseCacheManager { }); } - /** - * 更新主播视图 - * @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-加入对方主播直播间 diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java index 9a2484077..48a769c5f 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java @@ -1000,6 +1000,7 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic //多人PK接受 @Override public void onLinkDRMicPkApplyOk(UserBean u) { + L.eSw("onLinkDRMicPkApplyOk(UserBean u)"); if (mLiveLinkMicPkPresenter != null) { mLiveLinkMicPkPresenter.onLinkDRMicPkApplyOk(u); } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 953ed3fe1..e52c6e360 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -31,6 +31,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.GsonUtils; import com.facebook.appevents.AppEventsLogger; +import com.google.gson.Gson; import com.lxj.xpopup.XPopup; import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.enums.PopupPosition; @@ -566,7 +567,9 @@ public class LiveAudienceActivity extends LiveActivity { @Override public void onLinkDRMicPkApplyOk(UserBean u) { - + L.eSw("onLinkDRMicPkApplyOk:"+u.getId()); + //多人PK 连麦 + manager.getmLivePlayViewHolder().setDrMicInfo(u); } @Override @@ -1446,7 +1449,7 @@ public class LiveAudienceActivity extends LiveActivity { if (manager.getmLivePlayViewHolder() != null) { manager.getmLivePlayViewHolder().setPkEndview(); manager.setPkStatus(false); - + manager.mLivePlayViewHolder.endPk(); } if (manager != null) { manager.removeDetailView(); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 170ade09c..6d3b6f6af 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -222,27 +222,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl Bus.getOn(this); Intent intent = getIntent(); initFaceManager(); - RCRTCEngine.getInstance().registerStatusReportListener(new IRCRTCStatusReportListener() { - - @Override - public void onConnectionStats(StatusReport statusReport) { - //视频发送信息 - for (Map.Entry entry : statusReport.statusVideoSends.entrySet()) { - StatusBean statusBean = entry.getValue(); - //获取userID - String userId = statusBean.uid; - //获取视频 宽x高@帧率 - String resolution = statusBean.frameWidth + "x" + statusBean.frameHeight + "@" + statusBean.frameRate; - //获取码率 - long bitRate = statusBean.bitRate; - //丢包率 - long lossRate = statusBean.packetLostRate; - //带宽 - String googAvailableSendBandwidth = statusReport.googAvailableSendBandwidth; -// Log.e("网速和内存", "获取视频:" + resolution + " 丢包率:" + lossRate + " 带宽:" + googAvailableSendBandwidth); - } - } - }); leave_img = findViewById(R.id.leave_img); mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); mLiveKsyConfigBean = intent.getParcelableExtra(Constants.LIVE_KSY_CONFIG); @@ -1452,6 +1431,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl //多人PK接受 @Override public void onLinkDRMicPkApplyOk(UserBean u) { + L.eSw("onLinkDRMicPkApplyOk111111"); if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onLinkDRMicPkApplyOk(u); } @@ -1712,7 +1692,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl break; case DISCONNEXT_PK_TIME: if (mLivePushViewHolder != null) { - mLivePushViewHolder.changeToBig(); + //mLivePushViewHolder.changeToBig(); + mLivePushViewHolder.anchorClose(); mLiveRyLinkMicPkPresenter.leaveDRRoom(); } break; diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java index dd9aeb4c0..851145c90 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java @@ -29,6 +29,7 @@ import com.yunbao.common.bean.UserBean; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; @@ -357,6 +358,8 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { */ public void onLinkDRMicPkApplyOk(UserBean u) { + L.eSw("public void onLinkDRMicPkApplyOk(UserBean u) {"); + user.add(u); Log.i("1111", "12222222a" + user.size()); mTRTCCloud1 = LivePushTxViewHolder.mTRTCCloud.createSubCloud(); diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 003fc065d..2f69d8575 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -29,6 +29,7 @@ import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; @@ -99,6 +100,7 @@ import cn.rongcloud.rtc.base.RCRTCMediaType; import cn.rongcloud.rtc.base.RCRTCRoomType; import cn.rongcloud.rtc.base.RCRTCStream; import cn.rongcloud.rtc.base.RTCErrorCode; +import io.agora.beautyapi.faceunity.agora.SWManager; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; @@ -515,9 +517,31 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 */ public void onLinkDRMicPkApplyOk(UserBean u) { - if(livePushRyViewHolder!=null){ - livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()),-1); + L.eSw("onLinkDRMicPkApplyOk(UserBean u) " + u.getUserNiceName()); + int index = 0; + if (livePushRyViewHolder != null) { + livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); } + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", CommonAppConfig.getInstance().getUid()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if(info.length>0){ + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; + } + } + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); + L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); + } + dRjoinOtherRoom(drPkbeans); + } + } + }); } /** @@ -815,79 +839,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } }); - - for (int i = 0; i < inputStreamList.size(); i++) { - Log.e("ry", "退出多人ID" + inputStreamList.get(i).getUserId()); - //退出副房间 - RCRTCEngine.getInstance().leaveOtherRoom(inputStreamList.get(i).getUserId(), true, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "退出多人成功"); - - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "退出多人失败" + rtcErrorCode); - - } - }); - } - - - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); -//视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); -//大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); -//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 -//如不设置宽高值则服务端将使用默认宽高 360 * 640 -//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, -//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 720; - int height = 1280; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //2. 合流画布设置 - //(请参照画布和声音配置示例代码) - //3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高 - ArrayList list = new ArrayList<>(); - config.setCustomLayouts(list); - //user1的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - list.add(videoLayout1); - videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video - videoLayout1.setX(0); //X 坐标 - videoLayout1.setY(0); //Y 坐标 - videoLayout1.setWidth(720); // 视频窗口的宽 - videoLayout1.setHeight(1280); // 视频窗口的高 - //2. 合流画布设置 - if (rcrtcLiveInfo != null) { - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功15"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - - } - - leaveHandler.post(leaveRunnable); - + livePushRyViewHolder.exitChannelDrPk(drPkbeans); + leaveHandler.removeCallbacks(leaveRunnable); } private Handler leaveHandler = new Handler(Looper.getMainLooper()); @@ -895,15 +848,12 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void run() { //恢复全屏画面 - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - params.topMargin = 0; - livePushRyViewHolder.camera.setLayoutParams(params); livePushRyViewHolder.dr_pk_view.setVisibility(View.GONE); - inputStreamList.clear(); - inputStreamList1.clear(); //删除之前其他主播的画面 livePushRyViewHolder.dr1_preview.removeAllViews(); + livePushRyViewHolder.dr2_preview.removeAllViews(); livePushRyViewHolder.dr3_preview.removeAllViews(); + livePushRyViewHolder.dr4_preview.removeAllViews(); livePushRyViewHolder.cameraPreview3.removeAllViews(); leaveHandler.removeCallbacks(leaveRunnable); livePushRyViewHolder.timeTitle.setVisibility(View.GONE); @@ -1027,6 +977,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { LiveNetManager.get(mContext).setBanRandomPK(null); } + /** * 显示申请多人PK的弹窗 */ @@ -1072,22 +1023,27 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess(int code, String msg, String[] info) { - L.eSw("多人PK"+ "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + L.eSw("多人PK" + "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); if (info.length == 0) { return; } JSONObject obj = JSONObject.parseObject(info[0]); - drPkbeans = JSONObject.parseArray(obj.getString("userlist"),DrPkbean.class); - for (int i = 0; i - * 1: inviterAutoMix为true时: - * - * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 - * - * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 - * - * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 - *

- *//* + * 向指定用户发送跨房间连麦请求 + *

+ * 1: inviterAutoMix为true时: + * + * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 + * + * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 + * + * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 + *

+ *//* IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { @Override public void onSuccess() { @@ -1264,57 +1221,217 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { //多人PK接受申请画 加入副房间 - public void dRjoinOtherRoom(String uid, int i) { - Log.e("ry", uid + "洒洒" + i + "VVVV" + i); - mApplyUid = uid; - /*new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - //把多人PK的View显示出来 - if (livePushRyViewHolder.dr_pk_view.getVisibility() == View.GONE) { - livePushRyViewHolder.dr_pk_view.setVisibility(View.VISIBLE); - livePushRyViewHolder.dr1_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr2_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr3_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr4_preview.setVisibility(View.GONE); + public void dRjoinOtherRoom(List drPkbeanList) { + L.eSw("dRjoinOtherRoom:size:" + drPkbeanList.size() + " json " + new Gson().toJson(drPkbeanList)); + if (drPkbeanList.size() == 1) { + String uid = String.valueOf(drPkbeanList.get(0).getId()); + //设置多人PK数据 + LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + if(detailsView2!=null){ + livePushRyViewHolder.dr2_preview.removeView(detailsView2); + } + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(uid); + textPkName2.setText(data.getUserNicename()); + livePushRyViewHolder.dr2_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.GONE); + } + + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); imageGrade1 = detailsView1.findViewById(R.id.image_grade1); textGrade1 = detailsView1.findViewById(R.id.text_grade1); + textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.mPreView.addView(detailsView1); + livePushRyViewHolder.dr1_preview.addView(detailsView1); detailsLinearLayout1.setVisibility(View.VISIBLE); linearGrade1.setVisibility(View.GONE); + + + Log.e("ry", "多人接受成功" + uid); + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); + } else if (drPkbeanList.size() == 2) { + String uid1 = String.valueOf(drPkbeanList.get(0).getId()); + String uid2 = String.valueOf(drPkbeanList.get(1).getId()); + //设置多人PK数据 + LiveNetManager.get(mContext).getLiveInfo(uid1, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + if(detailsView2!=null){ + livePushRyViewHolder.dr2_preview.removeView(detailsView2); + } + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(uid1); + textPkName2.setText(data.getUserNicename()); + livePushRyViewHolder.dr2_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.GONE); + } + + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); + + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); + linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); + imageGrade1 = detailsView1.findViewById(R.id.image_grade1); + textGrade1 = detailsView1.findViewById(R.id.text_grade1); + textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + livePushRyViewHolder.dr1_preview.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.GONE); + + LiveNetManager.get(mContext).getLiveInfo(uid2, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + if(detailsView4!=null){ + livePushRyViewHolder.dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(uid2); + textPkName4.setText(data.getUserNicename()); + livePushRyViewHolder.dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.GONE); + L.eSw("第三个主播的名称 数据加载完成"+detailsLinearLayout4.getVisibility()); + L.eSw("detailsLinearLayout4.getVisibility()"+detailsLinearLayout4.getVisibility()); + } + + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); + } else if (drPkbeanList.size() == 3) { + String uid1 = String.valueOf(drPkbeanList.get(0).getId()); + String uid2 = String.valueOf(drPkbeanList.get(1).getId()); + String uid3 = String.valueOf(drPkbeanList.get(2).getId()); + //设置多人PK数据 + LiveNetManager.get(mContext).getLiveInfo(uid1, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + if(detailsView2!=null){ + livePushRyViewHolder.dr2_preview.removeView(detailsView2); + } + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(uid1); + textPkName2.setText(data.getUserNicename()); + livePushRyViewHolder.dr2_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.GONE); + L.eSw("detailsLinearLayout2.getVisibility()"+detailsLinearLayout2.getVisibility()); + } + + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); + + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); + linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); + imageGrade1 = detailsView1.findViewById(R.id.image_grade1); + textGrade1 = detailsView1.findViewById(R.id.text_grade1); + textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + livePushRyViewHolder.dr1_preview.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.GONE); + + LiveNetManager.get(mContext).getLiveInfo(uid2, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + if(detailsView2!=null){ + livePushRyViewHolder.dr3_preview.removeView(detailsView3); + } + detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); + linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); + textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); + imageGrade3 = detailsView3.findViewById(R.id.image_grade3); + textGrade3 = detailsView3.findViewById(R.id.text_grade3); + imageGrade3.setTag(uid2); + textPkName3.setText(data.getUserNicename()); + livePushRyViewHolder.dr3_preview.addView(detailsView3); + detailsLinearLayout3.setVisibility(View.VISIBLE); + linearGrade3.setVisibility(View.GONE); + L.eSw("detailsLinearLayout3.getVisibility()"+detailsLinearLayout3.getVisibility()); + L.eSw("第三个主播的名称 数据加载完成"); + } + + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); + LiveNetManager.get(mContext).getLiveInfo(uid3, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + if(detailsView4!=null){ + livePushRyViewHolder.dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(uid3); + textPkName4.setText(data.getUserNicename()); + livePushRyViewHolder.dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.GONE); + L.eSw("detailsLinearLayout4.getVisibility()"+detailsLinearLayout4.getVisibility()); + L.eSw("第四个主播的名称 数据加载完成"); + } + + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); + + Log.e("ry", "多人接受成功" + mApplyUid); + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); + } - - //设置多人PK数据 - LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(String.valueOf(uid)); - textPkName2.setText(data.getUserNicename()); - livePushRyViewHolder.dr1_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); - - Log.e("ry", "多人接受成功" + mApplyUid); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - } - });*/ - } + } /** * 多人PK PK主播发过来的已经接受 @@ -2008,6 +2125,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 更新Pk分数 */ public void upDataPkScore(JSONArray pkScores, String uid, int time) { + L.eSw("更新Pk分数 upDataPkScore time:" + time + " " + pkScores); String userID1 = (String) imageGrade1.getTag(); String userID2 = (String) imageGrade2.getTag(); String userID4 = (String) imageGrade4.getTag(); @@ -2025,7 +2143,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); mHandler.sendEmptyMessage(WHAT_PK_TIME2); } - } int pkScoreSize = pkScores.size(); if (pkScoreSize == 3) { diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index 4705298e8..f24cfaa6f 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -312,6 +312,7 @@ public class SocketRyClient { UserBean u = new UserBean(); // u.setUserNiceName(map.getString("uname")); u.setId(map.getString("uid")); + L.eSw("action3 == 2:"+u.getId()); mListener.onLinkDRMicPkApplyOk(u); } else if (action3 == 6) {//开始Pk if (LiveRoomViewHolder.mHandler != null) { @@ -334,7 +335,6 @@ public class SocketRyClient { } else { // LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview(); Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW)); - } //創建了多人房間 } else if (action3 == 3) { diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java index 4dc373b50..a379ef3e7 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java @@ -11,15 +11,25 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.RelativeLayout; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; import com.tencent.live2.V2TXLiveDef; import com.tencent.live2.V2TXLivePlayer; import com.tencent.live2.impl.V2TXLivePlayerImpl; import com.tencent.rtmp.ui.TXCloudVideoView; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.bean.UserBean; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; import com.yunbao.common.utils.ScreenDimenUtil; import com.yunbao.live.R; +import com.yunbao.live.bean.DrPkbean; + +import java.util.ArrayList; +import java.util.List; /** * Created by cxf on 2018/10/10. @@ -48,7 +58,6 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder { public static int landscape; //1h 2s public static Context contexts; - int screenWidth; // 屏幕宽(像素,如:480px) int screenHeight; // 屏幕高(像素,如:800p) @@ -254,6 +263,10 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder { } } + @Override + public void setDrMicInfo(UserBean u) { + } + @Override public void setLiveBeanLandscape(int landscape) { LivePlayKsyViewHolder.landscape =landscape; diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index d9f6c0793..9ec0ac5e7 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -19,13 +19,16 @@ import android.view.ViewGroup; import android.view.ViewParent; import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; +import com.alibaba.fastjson.JSONObject; import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.ui.StyledPlayerView; import com.google.android.exoplayer2.video.VideoSize; +import com.google.gson.Gson; import com.lxj.xpopup.XPopup; import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.interfaces.XPopupCallback; @@ -33,6 +36,7 @@ import com.lzf.easyfloat.EasyFloat; import com.lzy.okserver.OkDownload; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.EnterRoomNewModel; +import com.yunbao.common.bean.UserBean; import com.yunbao.common.dialog.LiveFontSizeSettingDialog; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; @@ -51,6 +55,7 @@ import com.yunbao.common.views.LiveClarityCustomPopup; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.event.LiveAudienceEvent; import org.greenrobot.eventbus.EventBus; @@ -130,6 +135,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { SWAuManager swAuManager; String liveUid; + private LinearLayout dr_pk_view; + private FrameLayout dr1_preview; + private FrameLayout dr2_preview; + private FrameLayout dr3_preview; + private FrameLayout dr4_preview; + public int getLandscape() { return landscape; } @@ -175,6 +186,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { debugView = new TextView(mContext); debugView.setBackgroundColor(Color.WHITE); + + dr_pk_view = (LinearLayout) findViewById(R.id.dr_pk_view); + dr1_preview = (FrameLayout) findViewById(R.id.dr1_preview); + dr2_preview = (FrameLayout) findViewById(R.id.dr2_preview); + dr3_preview = (FrameLayout) findViewById(R.id.dr3_preview); + dr4_preview = (FrameLayout) findViewById(R.id.dr4_preview); + dr_pk_view.setVisibility(View.GONE); } public void initSwEngine(String liveUid) { @@ -188,6 +206,80 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); } + /** + * 开启单人PK + * @param Uid + */ + public void setPkView(String Uid) { + swAuManager.updateMyChannelView((FrameLayout) mLeftContainer, Integer.parseInt(liveUid)); + ry_view.removeAllViews(); + //加入对方主播房间 + swAuManager.setPkContainer1((FrameLayout) mRightContainer); + swAuManager.joinExRoomEx(Integer.parseInt(Uid), CommonAppConfig.SWToken, SWAuManager.getChannelName(Uid)); + } + List drMicUserList = new ArrayList<>(); + +boolean isAdd = true; + + @Override + public void setDrMicInfo(UserBean u) { + L.eSw("setDrMicInfo:"+u.getId()+" drMicUserList:"+new Gson().toJson(drMicUserList)); + for (int i = 0; i drPkbeanList){ + for (int i = 0; i f4 f4->f3 - dr3_preview.removeAllViews(); - swManager.updateDrChannelView(dr3_preview,SWAuManager.getChannelName(drpkUid3),drpkUid3); + //先退出这个主播的直播间,在进入该直播间,(视图问题暂时找不到解决方案) + swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),drpkUid3); + swManager.joinChannelDrEx(dr3_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3)); - dr4_preview.removeAllViews(); frameLayout = dr4_preview; break; } @@ -635,18 +643,23 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX mBigContainer.removeAllViews(); } swManager.joinChannelDrEx(frameLayout,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); - btn_close.setVisibility(View.VISIBLE); dr_pk_view.setVisibility(View.VISIBLE); currentPosition = temp; } + return currentPosition; } + public void anchorClose(){ + swManager.updateMyChannelView((FrameLayout) mBigContainer); //用户主动断开连麦再退出画面 + } public void onLinkMicAnchorClose() { - swManager.updateMyChannelView((FrameLayout) mBigContainer); - LivePushRyViewHolder.btn_close.setVisibility(View.GONE); + //swManager.updateMyChannelView((FrameLayout) mBigContainer); 用户主动断开连麦再退出画面 + //LivePushRyViewHolder.btn_close.setVisibility(View.GONE); } + + public void onLinkDRMicPkApply(UserBean userBean) { if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(userBean); diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index 440030882..0cbe9709e 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -6,6 +6,7 @@ import android.view.ViewGroup; import com.alibaba.fastjson.JSONArray; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.LiveBean; +import com.yunbao.common.bean.UserBean; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.AbsViewHolder; import com.yunbao.live.interfaces.ILiveLinkMicViewHolder; @@ -70,6 +71,8 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public abstract void setPkEndview(); + public abstract void setDrMicInfo(UserBean u); + public abstract void setLiveBeanLandscape(int landscape); public void setLiveBean(LiveBean data) { @@ -79,6 +82,17 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public void setViewUP(int i) { } + public void setViewPkMic(int uid) { + } + + public void setViewPk() { + } + + public void setViewDrMic() { + } + public void setViewDrPk() { + } + public OnMicCallback getOnMicCallback() { return onMicCallback; } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 9554d80c4..57698f5dc 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -73,6 +73,7 @@ import com.yunbao.common.manager.OpenAdManager; import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.MicStatusManager; import com.yunbao.common.utils.RandomUtil; import com.yunbao.common.utils.RouteUtil; @@ -84,6 +85,7 @@ import com.yunbao.common.views.weight.LiveFloatView; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.bean.LiveBuyGuardMsgBean; import com.yunbao.live.bean.LiveChatBean; import com.yunbao.live.bean.LiveDanMuBean; @@ -150,7 +152,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //侧滑布局 // private DrawerLayout drawerLayout; //直播间拆分布局 - private LivePlayRyViewHolder mLivePlayViewHolder; + public LivePlayRyViewHolder mLivePlayViewHolder; //头部布局 public LiveRoomViewHolder mLiveRoomViewHolder; //底部布局 @@ -641,16 +643,15 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } if (mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")) { - - mLivePlayViewHolder.setViewUP(1); - + //mLivePlayViewHolder.setViewUP(1); + mLivePlayViewHolder.setPkView(data.getEnterRoomInfo().getPkinfo().getPkuid()); } if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.pkHandler = false; } if (mLivePlayViewHolder != null && pkInfo.getIntValue("ifpk") == 1 && pkInfo.getString("end_pk_time").equals("0")) {//pk开始了 - mLivePlayViewHolder.setViewUP(2); + mLivePlayViewHolder.setPkView(data.getEnterRoomInfo().getPkinfo().getPkuid()); //pk排名数据 LivePKUserListBean livePKUserListBean = JSON.parseObject(pkInfo.getString("pk_top_users"), LivePKUserListBean.class); @@ -662,7 +663,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (mLiveRoomViewHolder != null && pkInfo != null && pkInfo.containsKey("pkuid") && pkInfo.containsKey("pkuimg") && pkInfo.containsKey("pkuname")) { mLiveRoomViewHolder.setOtherInfo(pkInfo.getString("pkuid"), pkInfo.getString("pkuimg"), pkInfo.getString("pkuname")); } - } }; linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000); @@ -676,7 +676,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.initPkRank(null); } if (mLivePlayViewHolder != null) { - mLivePlayViewHolder.setViewUP(3); + //mLivePlayViewHolder.setViewUP(3); + mLivePlayViewHolder.setPkView(data.getEnterRoomInfo().getPkinfo().getPkuid()); } //pk排名数据 @@ -693,7 +694,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.initPkRank(null); } if (mLivePlayViewHolder != null) { - mLivePlayViewHolder.setViewUP(4); + JSONArray array = pkInfo.getJSONArray("userlist"); + for (int j = 0; j < array.size(); j++) { + UserBean drPkbean = new UserBean(); + JSONObject da = array.getJSONObject(j); + drPkbean.setId(String.valueOf(da.getIntValue("id"))); + mLivePlayViewHolder.setDrMicInfo(drPkbean); + } } upDataPkScore(pkInfo.getJSONArray("userlist"), pkInfo.getIntValue("drpk_time")); @@ -1561,7 +1568,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onLinkDRMicPkApplyOk(UserBean u) { - + L.eSw("onLinkDRMicPkApplyOk(UserBean u)PortraitLiveManager"); + mLivePlayViewHolder.setDrMicInfo(u); } @@ -1627,6 +1635,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } if (mLiveRoomViewHolder != null) { mLivePlayViewHolder.setLiveBeanLandscape(landscape); + mLivePlayViewHolder.endpk(mPkUid); } if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).setPkStatus(false); @@ -2153,6 +2162,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe * @param time */ public void upDataPkScore(JSONArray pkScores, int time) { + if (mLiveRoomViewHolder != null) { String liveId = mLiveBean.getUid(); JSONObject liveModel = null; diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index 5830a365b..7cbf9004a 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -1,6 +1,7 @@ + + + + + + + + + + + + + + + + + + + android:visibility="gone"> - - + /> Date: Mon, 29 Apr 2024 09:30:04 +0800 Subject: [PATCH 08/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=A4=9A=E4=BA=BAPK]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../faceunity/agora/SWAuManager.java | 21 ++ .../yunbao/live/activity/LiveActivity.java | 1 + .../live/presenter/LiveLinkMicPresenter.java | 1 + .../presenter/LiveRyLinkMicPkPresenter.java | 349 ++++++------------ .../yunbao/live/socket/SocketRyClient.java | 5 +- .../live/views/LivePlayRyViewHolder.java | 100 ++--- .../live/views/LivePushRyViewHolder.java | 3 +- .../yunbao/live/views/LiveRoomViewHolder.java | 13 +- .../live/views/PortraitLiveManager.java | 23 +- 9 files changed, 201 insertions(+), 315 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index 86fe52473..c918292b3 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -154,6 +154,26 @@ 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){ + options.publishCameraTrack = false; //控制是否发视频 + options.publishMicrophoneTrack = true; //控制是否发音频 + options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; //设置身份为主播 + }else{ + options.publishCameraTrack = false; //控制是否发视频 + options.publishMicrophoneTrack = false; //控制是否发音频 + options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; //设置身份为观众 + options.audienceLatencyLevel=Constants.AUDIENCE_LATENCY_LEVEL_LOW_LATENCY ;//设置为极速直播观众 + } + mRtcEngine.updateChannelMediaOptions(options); + } + /** * PK-加入对方主播直播间 * @param strUid @@ -272,4 +292,5 @@ public class SWAuManager extends BaseCacheManager { public void setLinkUserContainer(FrameLayout linkUserContainer) { this.linkUserContainer = linkUserContainer; } + } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index ae1212ba2..73e8c3609 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -557,6 +557,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL */ @Override public void onAnchorAcceptLinkMic() { + L.eSw("onAnchorAcceptLinkMic(1)"); if (mLiveLinkMicPresenter != null) { mLiveLinkMicPresenter.onAnchorAcceptLinkMic(); } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPresenter.java index 94e948388..79ecd5f25 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPresenter.java @@ -313,6 +313,7 @@ public class LiveLinkMicPresenter implements View.OnClickListener { * 所有人收到连麦观众发过来的播流地址的回调 */ public void onAudienceSendLinkMicUrl(String uid, String uname, String playUrl) { + L.eSw("onAudienceSendLinkMicUrl,主播同意"); if (TextUtils.isEmpty(uid)) { return; } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 2f69d8575..1d470ddda 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -522,26 +522,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (livePushRyViewHolder != null) { livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); } - HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", CommonAppConfig.getInstance().getUid()).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if(info.length>0){ - JSONObject obj = JSONObject.parseObject(info[0]); - drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - int removeIndex = -1; - for (int i = 0; i < drPkbeans.size(); i++) { - if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - removeIndex = i; - } - } - if (removeIndex != -1) { - drPkbeans.remove(removeIndex); - L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); - } - dRjoinOtherRoom(drPkbeans); - } - } - }); + dRjoinOtherRoom(u); } /** @@ -1076,7 +1057,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } - dRjoinOtherRoom(drPkbeans); + dRjoinOtherRoom(u); /*for (int i = 0; i < users.size(); i++) { JSONObject user = users.getJSONObject(i); @@ -1219,219 +1200,121 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } + public void setMyDrPkDetailsView(){ + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); + linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); + imageGrade1 = detailsView1.findViewById(R.id.image_grade1); + textGrade1 = detailsView1.findViewById(R.id.text_grade1); + textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + livePushRyViewHolder.dr1_preview.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.GONE); + } + + boolean isShow = false; //多人PK接受申请画 加入副房间 - public void dRjoinOtherRoom(List drPkbeanList) { - L.eSw("dRjoinOtherRoom:size:" + drPkbeanList.size() + " json " + new Gson().toJson(drPkbeanList)); - if (drPkbeanList.size() == 1) { - String uid = String.valueOf(drPkbeanList.get(0).getId()); - //设置多人PK数据 - LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - if(detailsView2!=null){ - livePushRyViewHolder.dr2_preview.removeView(detailsView2); - } - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(uid); - textPkName2.setText(data.getUserNicename()); - livePushRyViewHolder.dr2_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); - - detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); - linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); - imageGrade1 = detailsView1.findViewById(R.id.image_grade1); - textGrade1 = detailsView1.findViewById(R.id.text_grade1); - textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.dr1_preview.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.GONE); - - - Log.e("ry", "多人接受成功" + uid); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - } else if (drPkbeanList.size() == 2) { - String uid1 = String.valueOf(drPkbeanList.get(0).getId()); - String uid2 = String.valueOf(drPkbeanList.get(1).getId()); - //设置多人PK数据 - LiveNetManager.get(mContext).getLiveInfo(uid1, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - if(detailsView2!=null){ - livePushRyViewHolder.dr2_preview.removeView(detailsView2); - } - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(uid1); - textPkName2.setText(data.getUserNicename()); - livePushRyViewHolder.dr2_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); - - detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); - linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); - imageGrade1 = detailsView1.findViewById(R.id.image_grade1); - textGrade1 = detailsView1.findViewById(R.id.text_grade1); - textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.dr1_preview.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.GONE); - - LiveNetManager.get(mContext).getLiveInfo(uid2, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - if(detailsView4!=null){ - livePushRyViewHolder.dr4_preview.removeView(detailsView4); - } - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(uid2); - textPkName4.setText(data.getUserNicename()); - livePushRyViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.GONE); - L.eSw("第三个主播的名称 数据加载完成"+detailsLinearLayout4.getVisibility()); - L.eSw("detailsLinearLayout4.getVisibility()"+detailsLinearLayout4.getVisibility()); - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - } else if (drPkbeanList.size() == 3) { - String uid1 = String.valueOf(drPkbeanList.get(0).getId()); - String uid2 = String.valueOf(drPkbeanList.get(1).getId()); - String uid3 = String.valueOf(drPkbeanList.get(2).getId()); - //设置多人PK数据 - LiveNetManager.get(mContext).getLiveInfo(uid1, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - if(detailsView2!=null){ - livePushRyViewHolder.dr2_preview.removeView(detailsView2); - } - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(uid1); - textPkName2.setText(data.getUserNicename()); - livePushRyViewHolder.dr2_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.GONE); - L.eSw("detailsLinearLayout2.getVisibility()"+detailsLinearLayout2.getVisibility()); - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); - - detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); - linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); - imageGrade1 = detailsView1.findViewById(R.id.image_grade1); - textGrade1 = detailsView1.findViewById(R.id.text_grade1); - textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.dr1_preview.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.GONE); - - LiveNetManager.get(mContext).getLiveInfo(uid2, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - if(detailsView2!=null){ - livePushRyViewHolder.dr3_preview.removeView(detailsView3); - } - detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); - linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); - textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); - imageGrade3 = detailsView3.findViewById(R.id.image_grade3); - textGrade3 = detailsView3.findViewById(R.id.text_grade3); - imageGrade3.setTag(uid2); - textPkName3.setText(data.getUserNicename()); - livePushRyViewHolder.dr3_preview.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.VISIBLE); - linearGrade3.setVisibility(View.GONE); - L.eSw("detailsLinearLayout3.getVisibility()"+detailsLinearLayout3.getVisibility()); - L.eSw("第三个主播的名称 数据加载完成"); - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); - LiveNetManager.get(mContext).getLiveInfo(uid3, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - if(detailsView4!=null){ - livePushRyViewHolder.dr4_preview.removeView(detailsView4); - } - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(uid3); - textPkName4.setText(data.getUserNicename()); - livePushRyViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.GONE); - L.eSw("detailsLinearLayout4.getVisibility()"+detailsLinearLayout4.getVisibility()); - L.eSw("第四个主播的名称 数据加载完成"); - } - - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); - - Log.e("ry", "多人接受成功" + mApplyUid); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - - } + public void dRjoinOtherRoom(UserBean u) { + if(!isShow){ + setMyDrPkDetailsView(); + isShow = true; } + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", u.getId()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; + } + } + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); + L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); + } + setDrPkUserInfoView(drPkbeans); + } + } + }); + } + + private void setDrPkUserInfoView(List drPkbeanList) { + for (int j = 0; j () { + /*RCRTCEngine.getInstance().joinOtherRoom(u, new IRCRTCResultDataCallback() { @Override public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); @@ -1622,7 +1505,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void onFailed(RTCErrorCode rtcErrorCode) { Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason()); } - }); + });*/ } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index f24cfaa6f..1eaee5ac2 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -196,6 +196,7 @@ public class SocketRyClient { //用户连麦 case Constants.LIAN_MAI: int actions = map.getIntValue("action"); + L.eSw("用户连麦:actions"+actions); //主播邀请用户连麦消息 if (actions == 1) { EventBus.getDefault().post("inviteMic"); @@ -215,6 +216,8 @@ public class SocketRyClient { EventBus.getDefault().post("endMic"); Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CLOSE).setObject(map.toJavaObject(LinkMicUserBean.class))); } else if (actions == 8) { + //踢下麥 + if (WordUtil.isNewZh()) { ToastUtil.show("您已被移出多人語音連麥"); } else { @@ -449,7 +452,7 @@ public class SocketRyClient { case Constants.SOCKET_BUY_GUARD://购买守护 buyGuardInSameRoom(map); break; - case Constants.SOCKET_LINK_MIC://连麦 + case Constants.SOCKET_LINK_MIC://连麦-old processLinkMic(map); break; case Constants.SOCKET_LINK_MIC_ANCHOR://主播连麦 diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 9ec0ac5e7..0820a719f 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -280,6 +280,29 @@ boolean isAdd = true; swAuManager.updateMyChannelView((FrameLayout) ry_view, Integer.parseInt(liveUid)); } + /** + * 将用户设置成主播,与主播连麦 + */ + private void joinLiveMic() { + L.eSw("joinLiveMic"); + HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm") + .params("roomid", LiveActivity.mLiveUid) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.e("ry", code + "热热热"); + if(code==0){ + swAuManager.setMicAn(true); + } + } + }); + } + + private void endLiveMic() { + L.eSw("endLiveMic"); + swAuManager.setMicAn(false); + } + @Override public void hideCover() { // if (mCover != null) { @@ -767,8 +790,10 @@ boolean isAdd = true; LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { @Override public void run() { - UsertoRY(); - + //UsertoRY(); + //将自己设置成给主播,和主播连麦 + L.eSw("将自己设置成给主播,和主播连麦"); + joinLiveMic(); } }); } @@ -776,75 +801,10 @@ boolean isAdd = true; builder.build().show(); } else if ("endMic".equals(str)) { - if (rcrtcRoom != null) { + L.eSw("endMic.equals(str))"+str); // 开始切换为观众身份 - RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { - - /** - * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 - * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 - */ - @Override - public void onKicked() { - - } - - @Override - public void onSuccess() { - Log.e("ry", "下麦成功"); - // 该用户切换为观众成功,可以以观众身份进行音视频 - //退出rtc播放 - leaveRoom(); - } - - /** - * 当切换失败且不影响当前角色继续音视频时回调 - * @param errorCode 失败错误码 - */ - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "下麦失败" + errorCode); - leaveRoom(); - } - - private void leaveRoom() { - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - userJoinLinkMic = false; - Log.e("ry", "退出多人房间成功"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - if (WordUtil.isNewZh()) { - ToastUtil.show("已成功退出語音連麥"); - } else { - ToastUtil.show("You have successfully exited the voice connection"); - } - ry_view.removeAllViews(); - ry_view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; - onPrepared(); - rcrtcRoom = null; - MicStatusManager.getInstance().clear(); - - resumePlay(); - - if (onMicCallback != null) { - onMicCallback.onMikUpdate(); - } - } - }); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", errorCode + "退出多人房间成功"); - userJoinLinkMic = false; - } - }); - - } - }); - } + //声网-将用户身份切换只观众 + endLiveMic(); } else if ("Debug".equals(str)) { if (EasyFloat.isShow("Debug")) { EasyFloat.dismiss("Debug"); diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 8d676eb4e..fb3ba92c0 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -605,6 +605,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX private String drpkUid3 = ""; public int setAnDrPkRtc(String uid, int position) { + L.eSw("setAnDrPkRtc uid:"+uid+" position"+position); FrameLayout frameLayout = null; int temp= -1; if (swManager != null && !StringUtil.isEmpty(uid)) { @@ -630,7 +631,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX break; case 4: dr3_preview.setVisibility(View.VISIBLE); - //先退出这个主播的直播间,在进入该直播间,(视图问题暂时找不到解决方案) + //先退出这个主播的直播间,在进入该直播间,(视图问题暂时這樣處理) swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),drpkUid3); swManager.joinChannelDrEx(dr3_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3)); diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index a5f9a9fe2..43a81f26d 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -51,6 +51,7 @@ import com.bumptech.glide.load.resource.gif.GifDrawable; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; +import com.google.gson.Gson; import com.lxj.xpopup.XPopup; import com.makeramen.roundedimageview.RoundedImageView; import com.ms.banner.Banner; @@ -124,6 +125,7 @@ import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.LiveRoomCheckLivePresenter; import com.yunbao.common.utils.MicStatusManager; import com.yunbao.common.utils.RouteUtil; @@ -5272,9 +5274,11 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis }; public void upDataPkScore(JSONArray pkScores, int time) { + L.eSw("upDataPkScore(JSONArray pkScores, int time) {"+new Gson().toJson(pkScores)); isShowGif = true; - if (detailsView == null) { - detailsView = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + /*if (detailsView == null) { + L.eSw("upDataPkScore(JSONArray pkScores, int time) {detailsView=null"); + detailsView = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); timeTitle = detailsView.findViewById(R.id.time_title); textTime = detailsView.findViewById(R.id.text_time); linearGrade1 = detailsView.findViewById(R.id.lin_pk1); @@ -5293,7 +5297,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis imageGrade2 = detailsView.findViewById(R.id.image_grade2); imageGrade3 = detailsView.findViewById(R.id.image_grade3); imageGrade4 = detailsView.findViewById(R.id.image_grade4); - linearGrade1.setVisibility(View.GONE); + //暂时关闭 + linearGrade1.setVisibility(View.GONE); linearGrade2.setVisibility(View.GONE); linearGrade3.setVisibility(View.GONE); linearGrade4.setVisibility(View.GONE); @@ -5311,7 +5316,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis detailsView.setLayoutParams(params); } }); - } + }*/ if (time > 0) { mPkTimeCount2 = time; drPKtIME = time; diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 57698f5dc..13a9589dc 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -641,10 +641,21 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } } - - if (mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")) { - //mLivePlayViewHolder.setViewUP(1); - mLivePlayViewHolder.setPkView(data.getEnterRoomInfo().getPkinfo().getPkuid()); + if(mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")){ + JSONArray array = pkInfo.getJSONArray("userlist"); + //判断是否是多人连麦 + if(array!=null){//多人連麥 + if (mLivePlayViewHolder != null) { + for (int j = 0; j < array.size(); j++) { + UserBean drPkbean = new UserBean(); + JSONObject da = array.getJSONObject(j); + drPkbean.setId(String.valueOf(da.getIntValue("id"))); + mLivePlayViewHolder.setDrMicInfo(drPkbean); + } + } + }else{//单人连麦 + mLivePlayViewHolder.setPkView(data.getEnterRoomInfo().getPkinfo().getPkuid()); + } } if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.pkHandler = false; @@ -1478,7 +1489,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onAudienceApplyLinkMic(UserBean u) { - + L.eSw("onAudienceApplyLinkMic(2)"); } @Override @@ -2162,7 +2173,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe * @param time */ public void upDataPkScore(JSONArray pkScores, int time) { - + L.eSw("upDataPkScore"+time); if (mLiveRoomViewHolder != null) { String liveId = mLiveBean.getUid(); JSONObject liveModel = null; From b4adf4c77c42f0fc048e6a85f44afdd480e22dea Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Tue, 30 Apr 2024 18:29:09 +0800 Subject: [PATCH 09/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=A4=9A=E4=BA=BAPK]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/bean/EnterRoomInfoModel.java | 11 + .../yunbao/common/bean/LivePkMicModel.java | 36 +++ .../faceunity/agora/SWAuManager.java | 7 +- .../beautyapi/faceunity/agora/SWManager.java | 13 +- .../live/activity/LiveRyAnchorActivity.java | 1 + .../presenter/LiveLinkMicPkPresenter.java | 5 +- .../presenter/LiveRyLinkMicPkPresenter.java | 229 ++++++++++-------- .../yunbao/live/socket/SocketRyClient.java | 7 +- .../live/views/LivePlayRyViewHolder.java | 78 +++--- .../live/views/LivePushRyViewHolder.java | 4 +- .../yunbao/live/views/LiveRoomViewHolder.java | 4 +- .../live/views/PortraitLiveManager.java | 24 +- .../main/res/layout/view_live_play_ksy.xml | 2 +- 13 files changed, 268 insertions(+), 153 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/bean/LivePkMicModel.java diff --git a/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java b/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java index ec265a735..d32508ad6 100644 --- a/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java +++ b/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java @@ -114,6 +114,17 @@ public class EnterRoomInfoModel extends BaseModel { @SerializedName("gift_wall_lighten_total") private String giftWallLightenTotal; + @SerializedName("connection_info") + private LivePkMicModel connectionInfo; + + public LivePkMicModel getConnectionInfo() { + return connectionInfo; + } + + public void setConnectionInfo(LivePkMicModel connectionInfo) { + this.connectionInfo = connectionInfo; + } + public String getGiftWallLightenNumber() { return giftWallLightenNumber; } diff --git a/common/src/main/java/com/yunbao/common/bean/LivePkMicModel.java b/common/src/main/java/com/yunbao/common/bean/LivePkMicModel.java new file mode 100644 index 000000000..8a152613a --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/LivePkMicModel.java @@ -0,0 +1,36 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +public class LivePkMicModel extends BaseModel { + @SerializedName("pkuid") + private String pkuid; + @SerializedName("pkuname") + private String pkuname; + @SerializedName("pkuimg") + private String pkuimg; + + public String getPkuid() { + return pkuid; + } + + public void setPkuid(String pkuid) { + this.pkuid = pkuid; + } + + public String getPkuname() { + return pkuname; + } + + public void setPkuname(String pkuname) { + this.pkuname = pkuname; + } + + public String getPkuimg() { + return pkuimg; + } + + public void setPkuimg(String pkuimg) { + this.pkuimg = pkuimg; + } +} diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index c918292b3..4869923a3 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -232,7 +232,6 @@ public class SWAuManager extends BaseCacheManager { }); } - /** * 退出对方直播间 * @param uid 自己的ID @@ -246,7 +245,11 @@ public class SWAuManager extends BaseCacheManager { } public static String getChannelName(String liveUid) { - return CommonAppConfig.SWChannelPrefix + liveUid; + if(liveUid.contains("g")){ + return liveUid; + }else{ + return CommonAppConfig.SWChannelPrefix + liveUid; + } } //远程监听 diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 98c2124ab..7a780c229 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -218,7 +218,7 @@ public class SWManager extends BaseCacheManager { surfaceView.setZOrderMediaOverlay(true); frameLayout.addView(surfaceView); - VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN , uid); mRtcEngine.setupLocalVideo(videoCanvas); } @@ -262,7 +262,7 @@ public class SWManager extends BaseCacheManager { SurfaceView surfaceView = new SurfaceView(mContext); surfaceView.setZOrderMediaOverlay(true); pkContainer.addView(surfaceView); - VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid)); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN ,Integer.parseInt(toUid)); mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); } }); @@ -310,6 +310,7 @@ public class SWManager extends BaseCacheManager { rtcConnection.channelId = channelName; //對方主播的頻道 rtcConnection.localUid = tempUid;//自己的ID L.eSw("strUid:" + tempUid + "_token:" + token + "_channelName:" + channelName); + // 用内部通知,刷新多人PK的用户信息 mRtcEngine.joinChannelEx(token, rtcConnection, options, new IRtcEngineEventHandler() { @Override public void onJoinChannelSuccess(String channel, int scUid, int elapsed) { @@ -321,7 +322,7 @@ public class SWManager extends BaseCacheManager { SurfaceView surfaceView = new SurfaceView(mContext); surfaceView.setZOrderMediaOverlay(true); frameLayout.addView(surfaceView); - VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid)); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN ,Integer.parseInt(toUid)); mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); } }); @@ -450,6 +451,10 @@ public class SWManager extends BaseCacheManager { this.linkUserContainer = linkUserContainer; } public static String getChannelName(String liveUid) { - return CommonAppConfig.SWChannelPrefix + liveUid; + if(liveUid.contains("g")){ + return liveUid; + }else{ + return CommonAppConfig.SWChannelPrefix + liveUid; + } } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 6d3b6f6af..c35ee493d 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -406,6 +406,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl public void onSuccess(int code, String msg, String[] info) { if (code == 0) { + LiveRyLinkMicPkPresenter.mApplyUid = CommonAppConfig.getInstance().getUid(); btn_start_dr_pk.setVisibility(View.VISIBLE); // dr_pk_view.setVisibility(View.VISIBLE); final SocketSendBean msg1 = new SocketSendBean() diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java index 851145c90..6c18b6bf8 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java @@ -112,7 +112,7 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { mIsAnchor = isAnchor; mRoot = root; mPkContainer = linkMicViewHolder.getPkContainer(); - mPkTimeString2 =mContext.getString(R.string.live_pk_time_2); + mPkTimeString2 = mContext.getString(R.string.live_pk_time_2); //从本地取数据 String pkTime = CommonAppConfig.getInstance().getAnchorPkTime(); @@ -773,7 +773,8 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { final SocketSendBean msg = new SocketSendBean() .param("_method_", Constants.SOCKET_LIVE_DRPK) .param("action", 2) - .param("uid", CommonAppConfig.getInstance().getUid()); + .param("uid", u.getId()) + .param("pkuid",CommonAppConfig.getInstance().getUid()); msg.create(); V2TIMManager.getInstance().sendC2CTextMessage(msg.mResult.toString(), list.get(i).getId() + "", new V2TIMSendCallback() { @Override diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 1d470ddda..03204fba6 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -1022,42 +1022,68 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { drPkbeans.remove(removeIndex); L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); } - for (int i = 0; i < drPkbeans.size(); i++) { - if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 2).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", drPkbeans.get(i).getId()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - String targetId = "g" + drPkbeans.get(i).getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; } } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); } - }); - // - int index = livePushRyViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); - L.eSw("onLinkDRMicPkApplyOk(UserBean u)-点击接收 " + u.getUserNiceName()); + for (int i = 0; i 0) { @@ -1235,7 +1261,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } if (removeIndex != -1) { drPkbeans.remove(removeIndex); - L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); } setDrPkUserInfoView(drPkbeans); } @@ -1244,74 +1269,84 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } private void setDrPkUserInfoView(List drPkbeanList) { - for (int j = 0; j drMicUserList = new ArrayList<>(); -boolean isAdd = true; + boolean isAdd = true; @Override public void setDrMicInfo(UserBean u) { - L.eSw("setDrMicInfo:"+u.getId()+" drMicUserList:"+new Gson().toJson(drMicUserList)); - for (int i = 0; i 0) { mPkTimeCount2 = time; drPKtIME = time; diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 13a9589dc..0c6667b0c 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -38,6 +38,7 @@ import com.yunbao.common.bean.BannerBean; import com.yunbao.common.bean.CreateSudRoomModel; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.LiveBean; +import com.yunbao.common.bean.LivePkMicModel; import com.yunbao.common.bean.LiveRoomActivityModel; import com.yunbao.common.bean.LiveUserGiftBean; import com.yunbao.common.bean.MsgModel; @@ -644,17 +645,22 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if(mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")){ JSONArray array = pkInfo.getJSONArray("userlist"); //判断是否是多人连麦 - if(array!=null){//多人連麥 + if(array.size()>0){//多人連麥 if (mLivePlayViewHolder != null) { for (int j = 0; j < array.size(); j++) { UserBean drPkbean = new UserBean(); JSONObject da = array.getJSONObject(j); - drPkbean.setId(String.valueOf(da.getIntValue("id"))); - mLivePlayViewHolder.setDrMicInfo(drPkbean); + if(!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))){ + drPkbean.setId(String.valueOf(da.getIntValue("id"))); + mLivePlayViewHolder.setDrMicInfo(drPkbean); + } } } }else{//单人连麦 - mLivePlayViewHolder.setPkView(data.getEnterRoomInfo().getPkinfo().getPkuid()); + LivePkMicModel connection_info = data.getEnterRoomInfo().getConnectionInfo(); + if(!StringUtil.isEmpty(connection_info.getPkuid())){ + mLivePlayViewHolder.setPkView(connection_info.getPkuid()); + } } } if (mLiveRoomViewHolder != null) { @@ -709,8 +715,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe for (int j = 0; j < array.size(); j++) { UserBean drPkbean = new UserBean(); JSONObject da = array.getJSONObject(j); - drPkbean.setId(String.valueOf(da.getIntValue("id"))); - mLivePlayViewHolder.setDrMicInfo(drPkbean); + if(!String.valueOf(da.getIntValue("id")).equals(data.getLiveInfo().getUid())){ + drPkbean.setId(String.valueOf(da.getIntValue("id"))); + mLivePlayViewHolder.setDrMicInfo(drPkbean); + } } } @@ -768,10 +776,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.showPrizePoolLevel(String.valueOf(giftPrizePoolLevel)); } } + //liveHandler.postDelayed(loadTimeoutRunnableGone, 15_000); AppManager.runDebugCode(() -> { - // liveHandler.postDelayed(loadTimeoutRunnableGone, 1_000); + liveHandler.postDelayed(loadTimeoutRunnableGone, 1_000); }); - liveHandler.postDelayed(loadTimeoutRunnableGone, 15_000); if (TextUtils.equals(data.getEnterRoomInfo().getIsconnection(), "1")) { //通知心愿单位置换地方 EventBus.getDefault().post(new LiveAudienceEvent() diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index 7cbf9004a..cdcd20495 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -72,7 +72,7 @@ android:layout_height="270dp" android:layout_marginTop="130dp" android:orientation="horizontal" - android:visibility="visible"> + android:visibility="gone"> Date: Mon, 6 May 2024 08:51:18 +0800 Subject: [PATCH 10/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=A4=9A=E4=BA=BAPK]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../faceunity/agora/SWAuManager.java | 11 +- .../beautyapi/faceunity/agora/SWManager.java | 2 +- .../live/activity/LiveAnchorActivity.java | 5 + .../live/activity/LiveAudienceActivity.java | 7 +- .../live/activity/LiveRyAnchorActivity.java | 5 + .../presenter/LiveRyLinkMicPkPresenter.java | 145 +++++++++++++---- .../live/socket/SocketMessageListener.java | 2 + .../yunbao/live/socket/SocketRyClient.java | 15 ++ .../live/views/LivePlayRyViewHolder.java | 147 +++++++++++++++++- .../live/views/LivePushRyViewHolder.java | 20 +-- .../live/views/PortraitLiveManager.java | 28 +++- .../main/res/layout/view_live_play_ksy.xml | 2 +- 12 files changed, 337 insertions(+), 52 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index 4869923a3..93eca2957 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -192,7 +192,7 @@ public class SWAuManager extends BaseCacheManager { // 创建 ChannelMediaOptions 对象,并进行配置 ChannelMediaOptions options = new ChannelMediaOptions(); // 根据场景将用户角色设置为 AUDIENCE (观众) - options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; + options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; options.autoSubscribeVideo = true; options.autoSubscribeAudio = true; options.publishMicrophoneTrack = false; @@ -213,7 +213,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_FIT,Integer.parseInt(toUid)); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN,Integer.parseInt(toUid)); mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); } }); @@ -244,6 +244,13 @@ public class SWAuManager extends BaseCacheManager { mRtcEngine.leaveChannelEx(rtcConnection); } + /** + * 退出所有的直播间 + */ + public void exitChannelAll(){ + mRtcEngine.leaveChannel(); + } + public static String getChannelName(String liveUid) { if(liveUid.contains("g")){ return liveUid; diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 7a780c229..76d06f7fa 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -300,7 +300,7 @@ public class SWManager extends BaseCacheManager { // 创建 ChannelMediaOptions 对象,并进行配置 ChannelMediaOptions options = new ChannelMediaOptions(); // 根据场景将用户角色设置为 AUDIENCE (观众) - options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; + options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; options.autoSubscribeVideo = true; options.autoSubscribeAudio = true; options.publishMicrophoneTrack = false; diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java index 48a769c5f..0f979153b 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java @@ -997,6 +997,11 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic } } + @Override + public void onLinkDRMicPKToUser(UserBean u) { + + } + //多人PK接受 @Override public void onLinkDRMicPkApplyOk(UserBean u) { diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index e52c6e360..0c4cc52a1 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -565,11 +565,16 @@ public class LiveAudienceActivity extends LiveActivity { } + @Override + public void onLinkDRMicPKToUser(UserBean u) { + //manager.getmLivePlayViewHolder().setDrMicInfo(u); + } + @Override public void onLinkDRMicPkApplyOk(UserBean u) { L.eSw("onLinkDRMicPkApplyOk:"+u.getId()); //多人PK 连麦 - manager.getmLivePlayViewHolder().setDrMicInfo(u); + //manager.getmLivePlayViewHolder().setDrMicInfo(u); } @Override diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index c35ee493d..6a8d9bd51 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -1429,6 +1429,11 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl } } + @Override + public void onLinkDRMicPKToUser(UserBean u) { + + } + //多人PK接受 @Override public void onLinkDRMicPkApplyOk(UserBean u) { diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 03204fba6..32be6313e 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -512,7 +512,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { showDRApplyDialog(u); } - /** * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 */ @@ -522,6 +521,37 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (livePushRyViewHolder != null) { livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); } + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 3) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("type", 3) + .param("uid", u.getId()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + + String targetId = "g" + CommonAppConfig.getInstance().getUid(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); dRjoinOtherRoom(u); } @@ -600,7 +630,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { /*---------------------------------------------------------------- */ final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 2) //回复PK申请 2 - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", bean.getId()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); System.out.println("PK回执 = " + msg1.toString()); Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; @@ -817,6 +847,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void run() { if (btn_close != null) { btn_close.setVisibility(View.GONE); + livePushRyViewHolder.timeTitle.setVisibility(View.GONE); } } }); @@ -1029,28 +1060,20 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (info.length > 0) { JSONObject obj = JSONObject.parseObject(info[0]); drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - int removeIndex = -1; for (int i = 0; i < drPkbeans.size(); i++) { - if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - removeIndex = i; - } - } - if (removeIndex != -1) { - drPkbeans.remove(removeIndex); - } - for (int i = 0; i drPkbeanList) { - L.eSw("setDrPkUserInfoView"+new Gson().toJson(drPkbeanList)); + L.eSw("setDrPkUserInfoView" + new Gson().toJson(drPkbeanList)); mHandler.postDelayed(new Runnable() { @Override public void run() { - for (int j = 0; j 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + List drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (liveUid.equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; + } + } + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); + } + setDrPkView(drPkbeans); + } + } + }); } + public void claerDrPkInfoView() { + if (detailsView1 != null) { + dr1_preview.removeView(detailsView1); + } + if (detailsView2 != null) { + dr2_preview.removeView(detailsView2); + } + if (detailsView3 != null) { + dr3_preview.removeView(detailsView3); + } + if (detailsView4 != null) { + dr4_preview.removeView(detailsView4); + } + } + + public void setDrPkView(List drPkbeanList){ + + if (detailsView1 != null) { + dr1_preview.removeView(detailsView1); + } + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); + linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); + imageGrade1 = detailsView1.findViewById(R.id.image_grade1); + textGrade1 = detailsView1.findViewById(R.id.text_grade1); + textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + dr1_preview.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.GONE); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + for (int j = 0; j < drPkbeanList.size(); j++) { + if (j == 0) { + L.eSw("j == 0:" + j); + //设置多人PK数据 + if (detailsView2 != null) { + dr2_preview.removeView(detailsView2); + } + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(String.valueOf(drPkbeanList.get(0).getId())); + textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); + dr2_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.GONE); + } else if (j == 1) { + L.eSw("j == 1:" + j); + if (detailsView4 != null) { + dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(String.valueOf(drPkbeanList.get(1).getId())); + textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); + dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.GONE); + } else if (j == 2) { + L.eSw("j == 2:" + j); + + if (detailsView4 != null) { + dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(String.valueOf(drPkbeanList.get(2).getId())); + textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); + dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.GONE); + + if (detailsView3 != null) { + dr3_preview.removeView(detailsView3); + } + detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); + linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); + textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); + imageGrade3 = detailsView3.findViewById(R.id.image_grade3); + textGrade3 = detailsView3.findViewById(R.id.text_grade3); + imageGrade3.setTag(String.valueOf(drPkbeanList.get(1).getId())); + textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); + dr3_preview.addView(detailsView3); + detailsLinearLayout3.setVisibility(View.VISIBLE); + linearGrade3.setVisibility(View.GONE); + } + } + } + }, 2000); + } + + + /** * 退出单人pk * * @param pkUid */ public void endpk(String pkUid) { + L.eSw("endpk "+pkUid); mPkContainer.setVisibility(View.GONE); swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), SWAuManager.getChannelName(pkUid)); swAuManager.updateMyChannelView(ry_view, Integer.parseInt(liveUid)); @@ -290,6 +428,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { for (int i = 0; i < drMicUserList.size(); i++) { swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drMicUserList.get(i).getId()); } + drMicUserList =new ArrayList<>(); //將當前主播畫面放大 swAuManager.updateMyChannelView((FrameLayout) ry_view, Integer.parseInt(liveUid)); } @@ -517,6 +656,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mStarted = false; Bus.getOff(this); EventBus.getDefault().unregister(this); + swAuManager.exitChannelAll(); L.e(TAG, "release------->"); } @@ -1276,7 +1416,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); } } - private class ExoPlayerListener implements Player.Listener { String TAG = "播放流"; diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 79cc87cb3..a54f2f6b4 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -589,7 +589,10 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void setAnPkRtc(UserBean u) { if (swManager != null && u != null) { + //将多人pk画面屏蔽 + dr_pk_view.setVisibility(View.GONE); L.eSw("设置对方主播的视图setAnPkRtc" + u); + pkUid1 = u.getId(); mPkContainer.setVisibility(View.VISIBLE); //将自己的渲染视图设置到 leftContainer swManager.updateMyChannelView((FrameLayout) mLeftContainer); @@ -608,7 +611,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX private String drpkUid3 = ""; public int setAnDrPkRtc(String uid, int position) { L.eSw("setAnDrPkRtc uid:"+uid+" position"+position); - FrameLayout frameLayout = null; int temp= -1; if (swManager != null && !StringUtil.isEmpty(uid)) { L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid + "position:" + position); @@ -622,13 +624,17 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } switch (temp) { case 2: - frameLayout = dr2_preview; + swManager.joinChannelDrEx(dr2_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); + swManager.updateMyChannelView(dr1_preview); + mBigContainer.removeAllViews(); + dr3_preview.setVisibility(View.GONE); dr4_preview.setVisibility(View.GONE); break; case 3: drpkUid3 = uid; - frameLayout = dr4_preview; + swManager.joinChannelDrEx(dr4_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); + dr3_preview.setVisibility(View.GONE); dr4_preview.setVisibility(View.VISIBLE); break; case 4: @@ -637,15 +643,9 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),drpkUid3); swManager.joinChannelDrEx(dr3_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3)); - frameLayout = dr4_preview; + swManager.joinChannelDrEx(dr4_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); break; } - - if (temp == 2) { - swManager.updateMyChannelView(dr1_preview); - mBigContainer.removeAllViews(); - } - swManager.joinChannelDrEx(frameLayout,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); dr_pk_view.setVisibility(View.VISIBLE); currentPosition = temp; } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 0c6667b0c..7c5d090bf 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -647,14 +647,20 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //判断是否是多人连麦 if(array.size()>0){//多人連麥 if (mLivePlayViewHolder != null) { + List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { UserBean drPkbean = new UserBean(); + DrPkbean drPkbean1 = new DrPkbean(); JSONObject da = array.getJSONObject(j); if(!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))){ drPkbean.setId(String.valueOf(da.getIntValue("id"))); + drPkbean1.setId(da.getIntValue("id")); + drPkbean1.setUser_nicename(da.getString("user_nicename")); + drPkbeans.add(drPkbean1); mLivePlayViewHolder.setDrMicInfo(drPkbean); } } + mLivePlayViewHolder.setDrPkView(drPkbeans); } }else{//单人连麦 LivePkMicModel connection_info = data.getEnterRoomInfo().getConnectionInfo(); @@ -712,14 +718,20 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } if (mLivePlayViewHolder != null) { JSONArray array = pkInfo.getJSONArray("userlist"); + List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { - UserBean drPkbean = new UserBean(); + UserBean userBean = new UserBean(); + DrPkbean drPkbean = new DrPkbean(); JSONObject da = array.getJSONObject(j); if(!String.valueOf(da.getIntValue("id")).equals(data.getLiveInfo().getUid())){ - drPkbean.setId(String.valueOf(da.getIntValue("id"))); - mLivePlayViewHolder.setDrMicInfo(drPkbean); + userBean.setId(String.valueOf(da.getIntValue("id"))); + drPkbean.setId(da.getIntValue("id")); + drPkbean.setUser_nicename(da.getString("user_nicename")); + drPkbeans.add(drPkbean); + mLivePlayViewHolder.setDrMicInfo(userBean); } } + mLivePlayViewHolder.setDrPkView(drPkbeans); } upDataPkScore(pkInfo.getJSONArray("userlist"), pkInfo.getIntValue("drpk_time")); @@ -1585,10 +1597,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } + @Override + public void onLinkDRMicPKToUser(UserBean u) { + L.eSw("onLinkDRMicPKToUser(UserBean u)PortraitLiveManager"); + mLivePlayViewHolder.setDrMicInfo(u); + + } + @Override public void onLinkDRMicPkApplyOk(UserBean u) { L.eSw("onLinkDRMicPkApplyOk(UserBean u)PortraitLiveManager"); - mLivePlayViewHolder.setDrMicInfo(u); + //mLivePlayViewHolder.setDrMicInfo(u); } @@ -2197,6 +2216,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe pkScores.remove(index); pkScores.add(0, liveModel); mLiveRoomViewHolder.upDataPkScore(pkScores, time); + mLivePlayViewHolder.claerDrPkInfoView(); setPkStatus(true); } //通知心愿单位置换地方 diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index cdcd20495..03fe704b1 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -69,7 +69,7 @@ From 95ded2f77c9c4ce409b1ff3baf91b7c9159c1b24 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Wed, 8 May 2024 10:00:00 +0800 Subject: [PATCH 11/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=A4=9A=E4=BA=BAPK]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/proguard-rules.pro | 2 + .../beautyapi/faceunity/agora/SWManager.java | 14 ++++--- .../live/activity/LiveRyAnchorActivity.java | 1 - .../presenter/LiveRyLinkMicPkPresenter.java | 28 +++++++------ .../com/yunbao/live/socket/SocketClient.java | 2 + .../live/socket/SocketMessageListener.java | 1 + .../yunbao/live/socket/SocketRyClient.java | 30 ++++++++----- .../live/views/LivePlayRyViewHolder.java | 24 ++++++----- .../live/views/LivePushRyViewHolder.java | 42 +++++++++++++++++++ .../yunbao/live/views/LiveRoomViewHolder.java | 1 + .../live/views/PortraitLiveManager.java | 6 +-- .../main/res/layout/view_live_play_ksy.xml | 2 +- 12 files changed, 108 insertions(+), 45 deletions(-) diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 1a522d0c3..bc2809798 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -190,6 +190,8 @@ rx.internal.util.atomic.LinkedQueueNode* consumerNode; -keep class org.greenrobot.eventbus.android.AndroidComponentsImpl* #--------ARouter + +-keep public class com.alibaba.android.arouter.**{*;} -keep public class com.alibaba.android.arouter.routes.**{*;} -keep public class com.alibaba.android.arouter.facade.**{*;} -keep class * implements com.alibaba.android.arouter.facade.template.ISyringe{*;} diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 76d06f7fa..1b7e3ebff 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -153,20 +153,22 @@ public class SWManager extends BaseCacheManager { switch (selectClarity) { case 0: cfg.dimensions = VideoEncoderConfiguration.VD_840x480; + L.eSw("VideoEncoderConfiguration.VD_840x480"); break; case 1: cfg.dimensions = VideoEncoderConfiguration.VD_1280x720; + L.eSw("VideoEncoderConfiguration.VD_1280x720"); break; case 2: cfg.dimensions = VideoEncoderConfiguration.VD_1920x1080; + L.eSw("VideoEncoderConfiguration.VD_1920x1080"); + break; + case 3: + cfg.dimensions = VideoEncoderConfiguration.VD_320x240; + L.eSw("VideoEncoderConfiguration.VD_320x240"); break; } mRtcEngine.setVideoEncoderConfiguration(cfg); - // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 - SurfaceView surfaceView = new SurfaceView(mContext); - anchorContainer.addView(surfaceView); - // 设置视图 - mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); } } @@ -241,7 +243,7 @@ public class SWManager extends BaseCacheManager { // 创建 ChannelMediaOptions 对象,并进行配置 ChannelMediaOptions options = new ChannelMediaOptions(); // 根据场景将用户角色设置为 AUDIENCE (观众) - options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; + options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; options.autoSubscribeVideo = true; options.autoSubscribeAudio = true; options.publishMicrophoneTrack = false; diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 6a8d9bd51..3a4e4c05a 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -1314,7 +1314,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (mLiveAnchorViewHolder != null) { mLiveAnchorViewHolder.setYaoqing(pkUid); } - } /** diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 32be6313e..a91c15a13 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -1041,7 +1041,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } JSONObject obj = JSONObject.parseObject(info[0]); drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - + SWManager.get().setDimensions(3);//加入成功后,将分别率设置为 VD_320x240 //将自己从多人pk列表里剔除 int removeIndex = -1; for (int i = 0; i < drPkbeans.size(); i++) { @@ -1066,12 +1066,12 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { .param("action", 2) .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("type", 2) + .param("msgtype", 2) .param("uid", drPkbeans.get(i).getId()) .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); - + L.eSw("uiduiduiduiduiduiduiduid"+drPkbeans.get(i).getId()); String targetId = String.valueOf(drPkbeans.get(i).getId()); Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); @@ -1093,24 +1093,27 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { ToastUtil.show(errorCode.code + ":" + errorCode.msg); } }); + // int index = livePushRyViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); L.eSw("onLinkDRMicPkApplyOk(UserBean u)-点击接收 1 " + u.getUserNiceName()); L.eSw("發送action = 2"); + } - if(!mApplyUid.equals(String.valueOf(drPkbeans.get(i).getId()))&&!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))){ + + if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) .param("action", 3) .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("type", 3) + .param("msgtype", 3) .param("uid", drPkbeans.get(i).getId()) .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); - - String targetId = "g" + drPkbeans.get(i).getId(); + L.eSw("發送給自己直播間"+drPkbeans.get(i).getId()); + String targetId = "g" + CommonAppConfig.getInstance().getUid(); Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); @@ -1132,18 +1135,20 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } }); } - if(!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))){ + + + if(!mApplyUid.equals(String.valueOf(drPkbeans.get(i).getId()))&&!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))){ final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) .param("action", 3) .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("type", 3) + .param("msgtype", 3) .param("uid", drPkbeans.get(i).getId()) .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); - - String targetId = "g" + CommonAppConfig.getInstance().getUid(); + L.eSw("發送給其他主播直播间"+drPkbeans.get(i).getId()); + String targetId = "g" + drPkbeans.get(i).getId(); Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); @@ -1156,7 +1161,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess(io.rong.imlib.model.Message message) { - } @Override diff --git a/live/src/main/java/com/yunbao/live/socket/SocketClient.java b/live/src/main/java/com/yunbao/live/socket/SocketClient.java index 4647f45d1..852ae096e 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketClient.java @@ -10,6 +10,7 @@ import android.widget.LinearLayout; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; import com.tencent.imsdk.v2.V2TIMCallback; import com.tencent.imsdk.v2.V2TIMManager; import com.yunbao.common.CommonAppConfig; @@ -760,6 +761,7 @@ public class SocketClient { */ private static void processAnchorLinkMicPk(JSONObject map) { int action = map.getIntValue("action"); + L.eSw(new Gson().toJson(map)); switch (action) { case 1://收到对方主播发起PK回调 UserBean u = new UserBean(); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java b/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java index 0463910fd..6ac19c675 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java @@ -257,6 +257,7 @@ public interface SocketMessageListener { */ void onLinkMicPkClose(int i); + /** * 主播与主播PK 对方主播拒绝pk的回调 */ diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index 62b6e3b8b..bc88a548d 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -88,6 +88,7 @@ import java.util.List; import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.base.RTCErrorCode; +import io.agora.beautyapi.faceunity.agora.SWManager; import io.rong.imlib.IRongCoreCallback; import io.rong.imlib.IRongCoreEnum; import io.rong.imlib.chatroom.base.RongChatRoomClient; @@ -315,12 +316,16 @@ public class SocketRyClient { } //收到对方同意多人PK邀请 else if (action3 == 2) { + if("0".equals(map.getString("msgtype"))){ + return; + } UserBean u = new UserBean(); // u.setUserNiceName(map.getString("uname")); u.setId(map.getString("pkuid")); L.eSw("action3 == 2:"+u.getId()); L.eSw("收到对方同意多人PK邀请"); mListener.onLinkDRMicPkApplyOk(u); + SWManager.get().setDimensions(3);//退出直播间,将分别率设置为 VD_840x480 } else if (action3 == 6) {//开始Pk if (LiveRoomViewHolder.mHandler != null) { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); @@ -343,25 +348,28 @@ public class SocketRyClient { // LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview(); Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW)); } + SWManager.get().setDimensions(0);//退出直播间,将分别率设置为 VD_840x480 //創建了多人房間 } else if (action3 == 3) { L.eSw("創建了多人房間action3 == 3"); /* if (LiveAudienceActivity.getmLivePlayViewHolder() != null) { LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); }*/ - if("4".equals(map.getString("msgtype"))){ - return; - } - UserBean u = new UserBean(); + if(livePushRyViewHolder==null){ + if("4".equals(map.getString("msgtype"))){ + return; + } + UserBean u = new UserBean(); // u.setUserNiceName(map.getString("uname")); - u.setId(map.getString("uid")); - if(StringUtil.isEmpty(u.getId())){ - return; + u.setId(map.getString("uid")); + if(StringUtil.isEmpty(u.getId())){ + return; + } + L.eSw("通知用户 action3 == 3:"+u.getId()); + mListener.onLinkDRMicPKToUser(u); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); + isDRPK = 1; } - L.eSw("通知用户 action3 == 3:"+u.getId()); - mListener.onLinkDRMicPKToUser(u); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); - isDRPK = 1; } else if (action3 == 10) { //显示pk分数 if (!map.getString("uid").equals(CommonAppConfig.getInstance().getUid())) { diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 73cd4416e..c1960b6b5 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -252,6 +252,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { ry_view.removeAllViews(); swAuManager.updateMyChannelView((FrameLayout) dr1_preview, Integer.parseInt(liveUid)); swAuManager.joinChannelDrEx(dr2_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); + dr1_preview.setVisibility(View.VISIBLE); dr2_preview.setVisibility(View.VISIBLE); dr3_preview.setVisibility(View.GONE); dr4_preview.setVisibility(View.GONE); @@ -306,11 +307,15 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } public void setDrPkView(List drPkbeanList){ - if (detailsView1 != null) { dr1_preview.removeView(detailsView1); } - detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + + /*new Handler().postDelayed(new Runnable() { + @Override + public void run() { + + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); imageGrade1 = detailsView1.findViewById(R.id.image_grade1); @@ -320,9 +325,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { dr1_preview.addView(detailsView1); detailsLinearLayout1.setVisibility(View.VISIBLE); linearGrade1.setVisibility(View.GONE); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { + for (int j = 0; j < drPkbeanList.size(); j++) { if (j == 0) { L.eSw("j == 0:" + j); @@ -392,7 +395,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } } - }, 2000); + }, 2000);*/ } @@ -407,6 +410,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mPkContainer.setVisibility(View.GONE); swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), SWAuManager.getChannelName(pkUid)); swAuManager.updateMyChannelView(ry_view, Integer.parseInt(liveUid)); + ry_view.setVisibility(View.VISIBLE); mLeftContainer.removeAllViews(); mRightContainer.removeAllViews(); } @@ -942,7 +946,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { @Override public void run() { - //UsertoRY(); + // UsertoRY(); //将自己设置成给主播,和主播连麦 L.eSw("将自己设置成给主播,和主播连麦"); joinLiveMic(); @@ -1068,18 +1072,17 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } - /** * 把观众转换成主播 */ public List userinputStreamList = new ArrayList<>(); - public void UsertoRY() { userinputStreamList.clear(); Log.e("ry", "主播同意了UsertoRY"); if (userJoinLinkMic) {//已经在房间内,不再joinRoom直接去连麦 - subscribeMic(rcrtcRoom); + //subscribeMic(rcrtcRoom); + joinLiveMic(); return; } RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() @@ -1093,7 +1096,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { userJoinLinkMic = true; rcrtcRoom = data; subscribeMic(data); - } @Override diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index a54f2f6b4..6178fa71e 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -88,6 +88,7 @@ import io.agora.beautyapi.faceunity.agora.SWManager; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; import io.rong.message.TextMessage; /** @@ -604,6 +605,47 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX swManager.setPkContainer(mRightContainer); swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); } + HttpClient.getInstance().get("Livepk.setPK", "Livepk.setPK") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("pkuid", u.getId()) + .params("type", "1") + .params("sign", "1") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msgs, String[] info) { + if (code == 0) { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", Constants.SOCKET_LINK_MIC_PK) + .param("action", 4) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", u.getId()) + .param("uid", CommonAppConfig.getInstance().getUid()); + msg1.create(); + + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + Message message1 = Message.obtain("g" + CommonAppConfig.getInstance().getUid(), conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message1, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + } + + } + }); } private int currentPosition = 0; diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 726d171b5..5fdcd3f5d 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -5302,6 +5302,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis linearGrade2.setVisibility(View.GONE); linearGrade3.setVisibility(View.GONE); linearGrade4.setVisibility(View.GONE); + mRoot.removeView(detailsView); mRoot.addView(detailsView); mRoot.post(new Runnable() { @Override diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 7c5d090bf..eacf7ba34 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -660,7 +660,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLivePlayViewHolder.setDrMicInfo(drPkbean); } } - mLivePlayViewHolder.setDrPkView(drPkbeans); + //mLivePlayViewHolder.setDrPkView(drPkbeans); } }else{//单人连麦 LivePkMicModel connection_info = data.getEnterRoomInfo().getConnectionInfo(); @@ -723,7 +723,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe UserBean userBean = new UserBean(); DrPkbean drPkbean = new DrPkbean(); JSONObject da = array.getJSONObject(j); - if(!String.valueOf(da.getIntValue("id")).equals(data.getLiveInfo().getUid())){ + if(!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))){ userBean.setId(String.valueOf(da.getIntValue("id"))); drPkbean.setId(da.getIntValue("id")); drPkbean.setUser_nicename(da.getString("user_nicename")); @@ -731,7 +731,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLivePlayViewHolder.setDrMicInfo(userBean); } } - mLivePlayViewHolder.setDrPkView(drPkbeans); + //mLivePlayViewHolder.setDrPkView(drPkbeans); } upDataPkScore(pkInfo.getJSONArray("userlist"), pkInfo.getIntValue("drpk_time")); diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index 03fe704b1..f7c596dc0 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -69,7 +69,7 @@ From abfd15f75134aae2cbb90af1ed5af65ec71a7bde Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Thu, 9 May 2024 16:01:39 +0800 Subject: [PATCH 12/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=B0=8F=E6=B8=B8=E6=88=8F=E5=A4=9A=E4=BA=BA=E8=BF=9E=E9=BA=A6?= =?UTF-8?q?]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/dialog/CreateSudGamePopup.java | 2 +- .../manager/imrongcloud/GameMicManager.java | 70 ++-- .../com/yunbao/common/utils/RouteUtil.java | 5 +- .../common/views/SudGameListViewHolder.java | 4 +- .../faceunity/agora/SWAuManager.java | 91 ++++- .../live/activity/LiveAudienceActivity.java | 11 + .../yunbao/live/activity/SudGameActivity.java | 361 ++++++++++-------- .../dialog/LiveNewFunctionDialogFragment.java | 1 + .../live/event/LiveOpenSuccessEvent.java | 9 + .../live/views/PortraitLiveManager.java | 10 +- 10 files changed, 353 insertions(+), 211 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/event/LiveOpenSuccessEvent.java diff --git a/common/src/main/java/com/yunbao/common/dialog/CreateSudGamePopup.java b/common/src/main/java/com/yunbao/common/dialog/CreateSudGamePopup.java index d265f74ea..8d080a086 100644 --- a/common/src/main/java/com/yunbao/common/dialog/CreateSudGamePopup.java +++ b/common/src/main/java/com/yunbao/common/dialog/CreateSudGamePopup.java @@ -279,7 +279,7 @@ public class CreateSudGamePopup extends BottomPopupView { public void onSuccess(CreateSudRoomModel data) { if (isHome) { dialog.dismiss(); - RouteUtil.forwardSudGameActivity(new Gson().toJson(data)); + RouteUtil.forwardSudGameActivity(new Gson().toJson(data),true,isHome); } else { Bus.get().post(new LiveSudGamePopupShowOrHideEvent().setType(0).setCreateSudRoomModel(data)); diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameMicManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameMicManager.java index 3273793e8..48d489a7c 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameMicManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameMicManager.java @@ -43,6 +43,9 @@ public class GameMicManager { private RCRTCRoom mRtcRoom = null; private String mRoomID = ""; + public void setmRoomID(String mRoomID) { + this.mRoomID = mRoomID; + } private final IRCRTCRoomEventsListener roomEventsListener = new IRCRTCRoomEventsListener() { /** @@ -183,43 +186,44 @@ public class GameMicManager { public void refreshStreams(List personList) { final List inputStreams = new ArrayList<>(); + if(mRtcRoom!=null){ + for (SudGameUserModel sudGameUserModel : personList) { + List rcrtcRemoteUsers = mRtcRoom.getRemoteUsers(); - for (SudGameUserModel sudGameUserModel : personList) { - List rcrtcRemoteUsers = mRtcRoom.getRemoteUsers(); - - for (RCRTCRemoteUser rcrtcRemoteUser : rcrtcRemoteUsers) { - if (TextUtils.equals(rcrtcRemoteUser.getUserId(), String.valueOf(sudGameUserModel.getId()))) { - for (RCRTCInputStream rcrtcInputStream : rcrtcRemoteUser.getStreams()) { - rcrtcInputStream.mute(sudGameUserModel.getMicStatus() == 3); + for (RCRTCRemoteUser rcrtcRemoteUser : rcrtcRemoteUsers) { + if (TextUtils.equals(rcrtcRemoteUser.getUserId(), String.valueOf(sudGameUserModel.getId()))) { + for (RCRTCInputStream rcrtcInputStream : rcrtcRemoteUser.getStreams()) { + rcrtcInputStream.mute(sudGameUserModel.getMicStatus() == 3); + } + inputStreams.addAll(rcrtcRemoteUser.getStreams()); } - inputStreams.addAll(rcrtcRemoteUser.getStreams()); } } + if (inputStreams.size() == 0) { + return; + } + mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + + + try { + getView().onSubscribeSuccess(inputStreams); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + try { + getView().onSubscribeFailed(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + }); } - if (inputStreams.size() == 0) { - return; - } - mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - - - try { - getView().onSubscribeSuccess(inputStreams); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - try { - getView().onSubscribeFailed(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - }); } public void refreshStreams(String userID, boolean mute, int position) { @@ -242,8 +246,6 @@ public class GameMicManager { mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { @Override public void onSuccess() { - - try { getView().onSubscribeSuccess(userID, mute, position); } catch (IllegalStateException e) { diff --git a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java index 281357214..a30f5f676 100644 --- a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java @@ -49,6 +49,7 @@ public class RouteUtil { public static final String PATH_SELECT_AVATAR="/main/UserAvatarSelectActivity"; public static final String PATH_BattlePassActivity="/main/BattlePassActivity"; public static final String PATH_SudGameActivity="/live/SudGameActivity"; + public static final String PATH_COMMUNITY_Activity="/main/MainHomeCommunityActivity"; @@ -61,9 +62,11 @@ public class RouteUtil { .withString(Constants.TO_UID, uid) .navigation(); } - public static void forwardSudGameActivity(String CreateSudRoom) { + public static void forwardSudGameActivity(String CreateSudRoom,boolean isAn,boolean isHome) { ARouter.getInstance().build(PATH_SudGameActivity) .withString("CreateSudRoom", CreateSudRoom) + .withBoolean("CreateIsAn", isAn) + .withBoolean("CreateIsHome", isHome) .navigation(); } diff --git a/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java b/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java index c87f93e08..7c390f6d2 100644 --- a/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java +++ b/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java @@ -106,7 +106,7 @@ public class SudGameListViewHolder extends RecyclerView.ViewHolder { createSudRoomModel.setSudGameName(model.getSudGameName()); if (isHome) { if (TextUtils.equals(model.getLiveUid(), "0")) { - RouteUtil.forwardSudGameActivity(new Gson().toJson(createSudRoomModel)); + RouteUtil.forwardSudGameActivity(new Gson().toJson(createSudRoomModel),false,isHome); } else { String yes = "是"; @@ -156,7 +156,7 @@ public class SudGameListViewHolder extends RecyclerView.ViewHolder { @Override public void onCancel() { - RouteUtil.forwardSudGameActivity(new Gson().toJson(createSudRoomModel)); + RouteUtil.forwardSudGameActivity(new Gson().toJson(createSudRoomModel),false,isHome); } })).show(); diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index 93eca2957..7d46c50b9 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -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; } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 0c4cc52a1..6f035614f 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -126,6 +126,7 @@ import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience; import com.yunbao.live.dialog.SignDialogFragment; import com.yunbao.live.event.LinkMicTxAccEvent; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.event.LiveOpenSuccessEvent; import com.yunbao.live.http.ImHttpUtil; import com.yunbao.live.views.LiveRoomPlayViewHolder; import com.yunbao.live.views.LiveRoomViewHolder; @@ -746,6 +747,14 @@ public class LiveAudienceActivity extends LiveActivity { manager.onLinkMicTxAccEvent(e); } + /** + * 腾讯sdk连麦时候切换低延时流 + */ + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLinkMicTxAccEvent(LiveOpenSuccessEvent e) { + manager.loadTimeoutRunnableGone(); + } + /** * 腾讯sdk时候主播连麦回调 * @@ -1072,6 +1081,7 @@ public class LiveAudienceActivity extends LiveActivity { if (manager != null && manager.getsudGameMin()) { ToastUtil.show(WordUtil.isNewZh() ? "您已在游戏房间中" : "You are already in the game room"); } else { + //直播间来的 new XPopup.Builder(mContext) .enableDrag(false) // .dismissOnTouchOutside(false) @@ -1874,6 +1884,7 @@ public class LiveAudienceActivity extends LiveActivity { if (manager != null && manager.getsudGameMin()) { ToastUtil.show(WordUtil.isNewZh() ? "您已在游戏房间中" : "You are already in the game room"); } else { + //直播间来的 new XPopup.Builder(mContext) .enableDrag(false) // .dismissOnTouchOutside(false) diff --git a/live/src/main/java/com/yunbao/live/activity/SudGameActivity.java b/live/src/main/java/com/yunbao/live/activity/SudGameActivity.java index 7c4122ed9..4a4fe96f1 100644 --- a/live/src/main/java/com/yunbao/live/activity/SudGameActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/SudGameActivity.java @@ -5,6 +5,7 @@ import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.text.TextUtils; +import android.util.Log; import android.view.View; import android.widget.FrameLayout; import android.widget.ImageView; @@ -17,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.alibaba.android.arouter.facade.annotation.Route; import com.google.gson.Gson; import com.lxj.xpopup.XPopup; +import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.R; import com.yunbao.common.activity.AbsActivity; @@ -65,6 +67,10 @@ import cn.rongcloud.rtc.api.RCRTCRemoteUser; import cn.rongcloud.rtc.api.RCRTCRoom; import cn.rongcloud.rtc.api.stream.RCRTCInputStream; import cn.rongcloud.rtc.base.RTCErrorCode; +import io.agora.beautyapi.faceunity.agora.SWAuManager; +import io.rong.imlib.IRongCoreCallback; +import io.rong.imlib.IRongCoreEnum; +import io.rong.imlib.chatroom.base.RongChatRoomClient; @Route(path = RouteUtil.PATH_SudGameActivity) public class SudGameActivity extends AbsActivity implements GameMicManager.MeetingCallback { @@ -85,6 +91,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti private ProcessResultUtil mProcessResultUtil; private List muteUser = new ArrayList<>(); private boolean imOff; + private boolean isSw = true; @Override protected int getLayoutId() { @@ -103,108 +110,136 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti private void initDate() { - LiveNetManager.get(mContext) - .getCustomSidebarInfo("1", new HttpCallback>() { - @Override - public void onSuccess(List data) { - for (CustomSidebarInfoModel datum : data) { - if (datum.getType().equals("6")) { - customSidebarChildModels = datum.getChild(); - return; - } - } + LiveNetManager.get(mContext).getCustomSidebarInfo("1", new HttpCallback>() { + @Override + public void onSuccess(List data) { + for (CustomSidebarInfoModel datum : data) { + if (datum.getType().equals("6")) { + customSidebarChildModels = datum.getChild(); + return; } + } + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); // 设置禁用麦克风采集 - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); + //RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); gameCloseWheat.setVisibility(View.INVISIBLE); - mProcessResultUtil = new ProcessResultUtil(this); - LiveNetManager.get(mContext) - .getRoomMicStatus(new HttpCallback() { - @Override - public void onSuccess(RoomMicStatusModel data) { - gameMicManager = new GameMicManager(); - gameMicManager.attachView(SudGameActivity.this); - gameMicManager.config(SudGameActivity.this); - //语音 - if (TextUtils.equals(data.getMicStatus(), "1")) { - imOff = true; - gameSeat.setVisibility(View.VISIBLE); - userList.setVisibility(View.VISIBLE); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - if (!mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) { - ToastUtil.show("拒绝权限将无法使用上麦功能"); - mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() { - @Override - public void run() { + LiveNetManager.get(mContext).getRoomMicStatus(new HttpCallback() { + @Override + public void onSuccess(RoomMicStatusModel data) { + gameMicManager = new GameMicManager(); + gameMicManager.attachView(SudGameActivity.this); + gameMicManager.config(SudGameActivity.this); + //初始化声网引擎 + SWAuManager.get().initRtcEngineAudio(mContext); + //语音 + if (TextUtils.equals(data.getMicStatus(), "1")) { + imOff = true; + gameSeat.setVisibility(View.VISIBLE); + userList.setVisibility(View.VISIBLE); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + if (!mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) { + ToastUtil.show("拒绝权限将无法使用上麦功能"); + mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() { + @Override + public void run() { - } - }); } - } - }, 1500); - } else { - imOff = false; - gameSeat.setVisibility(View.GONE); - userList.setVisibility(View.GONE); + }); + } } - if (TextUtils.equals(data.getImStatus(), "1")) { - findViewById(R.id.game_review_input).setVisibility(View.VISIBLE); - chatList.setVisibility(View.VISIBLE); - } else { - findViewById(R.id.game_review_input).setVisibility(View.GONE); - chatList.setVisibility(View.GONE); - } - gameMicManager.joinRoom(mLiveUid, imOff); - } - - @Override - public void onError(String error) { - imOff = false; - //文字 - findViewById(R.id.game_review_input).setVisibility(View.GONE); - chatList.setVisibility(View.GONE); - //语音 - gameCloseWheat.setVisibility(View.GONE); - gameSeat.setVisibility(View.GONE); - userList.setVisibility(View.GONE); - } - }); - + }, 1500); + } else { + imOff = false; + gameSeat.setVisibility(View.GONE); + userList.setVisibility(View.GONE); + } + if (TextUtils.equals(data.getImStatus(), "1")) { + findViewById(R.id.game_review_input).setVisibility(View.VISIBLE); + chatList.setVisibility(View.VISIBLE); + } else { + findViewById(R.id.game_review_input).setVisibility(View.GONE); + chatList.setVisibility(View.GONE); + } + gameMicManager.setmRoomID(mLiveUid); + if (isSw) { + SWAuManager.get().joinAudioRoom("v" + mLiveUid, CommonAppConfig.SWToken, Integer.parseInt(CommonAppConfig.getInstance().getUid())); + onJoinRoomSuccess(null); + onJoinSuccess(); + } else { + gameMicManager.joinRoom(mLiveUid, imOff); + } + } + @Override + public void onError(String error) { + imOff = false; + //文字 + findViewById(R.id.game_review_input).setVisibility(View.GONE); + chatList.setVisibility(View.GONE); + //语音 + gameCloseWheat.setVisibility(View.GONE); + gameSeat.setVisibility(View.GONE); + userList.setVisibility(View.GONE); + } + }); } + + private void onJoinSuccess() { + RongChatRoomClient.getInstance().joinChatRoom("v" + mLiveUid, -1, new IRongCoreCallback.OperationCallback() { + @Override + public void onSuccess() { + Log.i("tx", "加入成功"); + gameMicManager.enterRoom(); + } + + @Override + public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) { + Log.i("tx", "加入" + "失败" + coreErrorCode); + if (WordUtil.isNewZh()) { + ToastUtil.show("網絡不佳無法連接,請重新進入"); + } else { + ToastUtil.show("The network is not connected, please re-enter"); + } + } + }); + } + + @Override protected void onDestroy() { - LiveNetManager.get(mContext) - .leaveMic(mLiveUid, new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { + LiveNetManager.get(mContext).leaveMic(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { - } + } - @Override - public void onError(String error) { - - } - }); + @Override + public void onError(String error) { + } + }); + if(isSw){ + SWAuManager.get().exitChannelAll(); + } if (gameMicManager != null) { gameMicManager.leaveRoom(); gameMicManager.detachView(); } + Bus.getOff(this); super.onDestroy(); @@ -225,8 +260,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti chatList = findViewById(R.id.chat_list); userList = findViewById(R.id.user_list); //聊天栏 - FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) - chatList.getLayoutParams(); + FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) chatList.getLayoutParams(); params1.topMargin = DpUtil.dp2px(65); chatList.setLayoutParams(params1); @@ -245,7 +279,13 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti @Override public void unMute(String userID, int position) { if (!TextUtils.equals(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()), userID)) { - gameMicManager.refreshStreams(userID, false, position); + if (isSw) { + //靜音 + SWAuManager.get().setMicAudio(Integer.parseInt(userID), false); + onSubscribeSuccess(userID, false, position); + } else { + gameMicManager.refreshStreams(userID, false, position); + } } else { ToastUtil.show(WordUtil.isNewZh() ? "無法對本人靜音" : "Unable to mute myself"); } @@ -256,11 +296,16 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti public void mute(String userID, int position) { muteUser.add(userID); if (!TextUtils.equals(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()), userID)) { - gameMicManager.refreshStreams(userID, true, position); + if (isSw) { + //开启声音 + SWAuManager.get().setMicAudio(Integer.parseInt(userID), true); + onSubscribeSuccess(userID, true, position); + } else { + gameMicManager.refreshStreams(userID, true, position); + } } else { ToastUtil.show(WordUtil.isNewZh() ? "無法對本人靜音" : "Unable to mute myself"); } - } @Override @@ -292,9 +337,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti @Override public void onViewClicks() { - new XPopup.Builder(mContext) - .enableDrag(false) - .asCustom(new LiveSudGameHistoryPopup(mContext, customSidebarChildModels)).show(); + new XPopup.Builder(mContext).enableDrag(false).asCustom(new LiveSudGameHistoryPopup(mContext, customSidebarChildModels)).show(); } }); @@ -306,16 +349,27 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti if (publishDefault) { disable = true; // 设置禁用麦克风采集 - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); + if (isSw) { + //下麥 + SWAuManager.get().setMicAn(false); + onUnPublishStreamsSuccess(); + } else { + RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); // ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); - gameMicManager.unPublishStreams(); + gameMicManager.unPublishStreams(); + } } else { if (sudGameUserListAdapter.isMicMax()) { ToastUtil.show(WordUtil.isNewZh() ? "上麥人數最大7人" : "The maximum number of people on the microphone is 7"); } else { - gameMicManager.publishDefaultAVStream(); + //上麦 + if (isSw) { + SWAuManager.get().setMicAn(true); + onPublishSuccess(); + } else { + gameMicManager.publishDefaultAVStream(); + } } - } } else { mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() { @@ -326,8 +380,6 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti }); } } - - } }); ViewClicksAntiShake.clicksAntiShake(gameCloseWheat, new ViewClicksAntiShake.ViewClicksCallBack() { @@ -341,38 +393,44 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti if (disable) { disable = false; // 设置禁用麦克风采集 - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); + if (isSw) { + SWAuManager.get().setMicAn(true); + } else { + RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); + } ImgLoader.display(mContext, R.mipmap.icon_game_open_wheat, gameCloseWheat); - LiveNetManager.get(mContext) - .onMic(mLiveUid, new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { + LiveNetManager.get(mContext).onMic(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { - } + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); ToastUtil.show(WordUtil.isNewZh() ? "麥克風已開啟" : "Microphone turned on"); } else { disable = true; // 设置禁用麦克风采集 - RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); + if(isSw){ + SWAuManager.get().setMicAn(false); + }else{ + RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); + } ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); - LiveNetManager.get(mContext) - .offMic(mLiveUid, new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { + LiveNetManager.get(mContext).offMic(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { - } + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); ToastUtil.show(WordUtil.isNewZh() ? "麥克風已關閉" : "Microphone turned off"); } } @@ -387,15 +445,12 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.game_review_input), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { - new XPopup.Builder(mContext) - .enableDrag(false) - .asCustom(new SudGameInputPopupWindow(mContext, new SudGameInputPopupWindow.SudGameInputCallBack() { - @Override - public void sendMessage(String textMessage) { - gameMicManager.sendMessage(textMessage); - } - })) - .show(); + new XPopup.Builder(mContext).enableDrag(false).asCustom(new SudGameInputPopupWindow(mContext, new SudGameInputPopupWindow.SudGameInputCallBack() { + @Override + public void sendMessage(String textMessage) { + gameMicManager.sendMessage(textMessage); + } + })).show(); } }); @@ -406,9 +461,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti gameContainer.removeAllViews(); } else { // 把游戏View添加到容器内 gameContainer.addView(view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); - } - } }); // 加载游戏,参数定义可查看BaseGameViewModel.switchGame()方法注释 @@ -483,30 +536,27 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfIn(false, event.getSeatIndex(), true, 1); break; case SudMGPMGState.MG_COMMON_SELF_CLICK_START_BTN: - LiveNetManager.get(mContext).gameStartCheckRemainingBalance(mCreateSudRoomModel.getSudGameId(), - mCreateSudRoomModel.getSudGameRoomId(), new - HttpCallback() { - @Override - public void onSuccess(CheckRemainingBalance data) { - if (data.getStatus() == 1) { - gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfPlaying(true); - } else { + LiveNetManager.get(mContext).gameStartCheckRemainingBalance(mCreateSudRoomModel.getSudGameId(), mCreateSudRoomModel.getSudGameRoomId(), new HttpCallback() { + @Override + public void onSuccess(CheckRemainingBalance data) { + if (data.getStatus() == 1) { + gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfPlaying(true); + } else { - } + } - } + } - @Override - public void onError(String error) { - ToastUtil.show(error); - } - }); + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); break; case SudMGPMGState.MG_COMMON_GAME_STATE: LiveNetManager.get(mContext).deductMoney(mCreateSudRoomModel.getSudGameRoomId()); break; } - } @Override @@ -514,7 +564,6 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti LiveNetManager.get(mContext).getRoomMicData(mLiveUid, new HttpCallback>() { @Override public void onSuccess(List data) { - gameMicManager.refreshStreams(data); sudGameUserListAdapter.refreshSudGameUserList(data, muteUser); } @@ -548,18 +597,17 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti } }); - LiveNetManager.get(mContext) - .joinMic(mLiveUid, new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { + LiveNetManager.get(mContext).joinMic(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { - } + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); } @Override @@ -628,18 +676,17 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti gameCloseWheat.setVisibility(View.INVISIBLE); } }); - LiveNetManager.get(mContext) - .leaveMic(mLiveUid, new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { + LiveNetManager.get(mContext).leaveMic(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { - } + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java index b7f4bc908..1991bc7f4 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java @@ -215,6 +215,7 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements public void onSuccess(List data) { for (CustomSidebarInfoModel datum : data) { if (datum.getType().equals("6")) { + //直播间来的 new XPopup.Builder(mContext) .enableDrag(false) .moveUpToKeyboard(false) diff --git a/live/src/main/java/com/yunbao/live/event/LiveOpenSuccessEvent.java b/live/src/main/java/com/yunbao/live/event/LiveOpenSuccessEvent.java new file mode 100644 index 000000000..5d558a064 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/event/LiveOpenSuccessEvent.java @@ -0,0 +1,9 @@ +package com.yunbao.live.event; + +/** + * Created by cxf on 2019/3/25. + */ + +public class LiveOpenSuccessEvent { + +} diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index eacf7ba34..a6cc00a76 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -102,6 +102,7 @@ import com.yunbao.live.dialog.BlowkissDialog; import com.yunbao.live.dialog.NewUserDialog; import com.yunbao.live.event.LinkMicTxAccEvent; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.event.LiveOpenSuccessEvent; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; @@ -442,7 +443,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveLinkMicPresenter.setSocketClient(mSocketClient); } enterRoomNew(); - + Bus.get().post(new LiveOpenSuccessEvent()); } catch (Exception e) { e.printStackTrace(); } @@ -835,6 +836,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } + + public void loadTimeoutRunnableGone(){ + if(liveHandler!=null){ + liveHandler.postDelayed(loadTimeoutRunnableGone, 1_000); + } + } + public void removeLiveEnd() { if (mLiveEndViewHolder != null) { mLiveEndViewHolder.removeFromParent(); From 73414f33494973b1d1b85091266fd4836eb024c0 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 11 May 2024 18:29:46 +0800 Subject: [PATCH 13/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E8=87=AA=E5=8B=95PK,=E7=9B=B4=E6=8E=A5PK]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/live/activity/LiveActivity.java | 2 +- .../live/event/LivePKRightUserInfoEvent.java | 44 ++++++++++++++++++ .../presenter/LiveRyLinkMicPkPresenter.java | 27 ++++++++--- .../yunbao/live/socket/SocketRyClient.java | 45 +++++++++++++++++-- .../live/views/LivePlayRyViewHolder.java | 11 ++++- .../live/views/LivePushRyViewHolder.java | 6 ++- .../yunbao/live/views/LiveRoomViewHolder.java | 6 +++ .../src/main/res/layout/view_live_push_ry.xml | 41 ++++++++--------- 8 files changed, 150 insertions(+), 32 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/event/LivePKRightUserInfoEvent.java diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index 73e8c3609..579a75bc6 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -719,7 +719,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL @Override public void onLinkMicPkApply(UserBean u, String stream, int forwhat) { //主播直播间实现此逻辑 - + L.eSw("onLinkMicPkApply----------------------------------------------"); } /** diff --git a/live/src/main/java/com/yunbao/live/event/LivePKRightUserInfoEvent.java b/live/src/main/java/com/yunbao/live/event/LivePKRightUserInfoEvent.java new file mode 100644 index 000000000..152c895e5 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/event/LivePKRightUserInfoEvent.java @@ -0,0 +1,44 @@ +package com.yunbao.live.event; + +/** + * Created by cxf on 2019/3/25. + */ + +public class LivePKRightUserInfoEvent { + String uid; + String uHead; + String uName; + + public LivePKRightUserInfoEvent() { + } + + public LivePKRightUserInfoEvent(String uid, String uHead, String uName) { + this.uid = uid; + this.uHead = uHead; + this.uName = uName; + } + + public String getUid() { + return uid; + } + + public void setUid(String uid) { + this.uid = uid; + } + + public String getuHead() { + return uHead; + } + + public void setuHead(String uHead) { + this.uHead = uHead; + } + + public String getuName() { + return uName; + } + + public void setuName(String uName) { + this.uName = uName; + } +} diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index a91c15a13..eba1534b6 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -66,6 +66,8 @@ import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.bean.LivePKUserListBean; import com.yunbao.live.custom.ProgressTextView; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.event.LiveOpenSuccessEvent; +import com.yunbao.live.event.LivePKRightUserInfoEvent; import com.yunbao.live.interfaces.ILiveLinkMicViewHolder; import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketRyLinkMicPkUtil; @@ -617,6 +619,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } private void isPK(UserBean bean) { + EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar())); ScreenDimenUtil util = ScreenDimenUtil.getInstance(); int mScreenWdith = util.getScreenWdith(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); @@ -1330,11 +1333,15 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); livePushRyViewHolder.dr1_preview.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout1.setVisibility(View.GONE); linearGrade1.setVisibility(View.GONE); } + public void setPkUserInfoView(UserBean userBean){ + + } + //多人PK接受申请画 加入副房间 public void dRjoinOtherRoom(UserBean u) { setMyDrPkDetailsView(); @@ -1380,7 +1387,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { imageGrade2.setTag(String.valueOf(drPkbeanList.get(0).getId())); textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); livePushRyViewHolder.dr2_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.GONE); linearGrade2.setVisibility(View.GONE); } else if (j == 1) { L.eSw("j == 1:" + j); @@ -1396,7 +1403,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { imageGrade4.setTag(String.valueOf(drPkbeanList.get(1).getId())); textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); livePushRyViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.GONE); linearGrade4.setVisibility(View.GONE); } else if (j == 2) { L.eSw("j == 2:" + j); @@ -1413,7 +1420,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { imageGrade4.setTag(String.valueOf(drPkbeanList.get(2).getId())); textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); livePushRyViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.GONE); linearGrade4.setVisibility(View.GONE); if (detailsView3 != null) { @@ -1428,7 +1435,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { imageGrade3.setTag(String.valueOf(drPkbeanList.get(1).getId())); textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); livePushRyViewHolder.dr3_preview.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.VISIBLE); + detailsLinearLayout3.setVisibility(View.GONE); linearGrade3.setVisibility(View.GONE); @@ -2155,6 +2162,10 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } int pkScoreSize = pkScores.size(); if (pkScoreSize == 3) { + detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.VISIBLE); linearGrade2.setVisibility(View.VISIBLE); linearGrade4.setVisibility(View.VISIBLE); @@ -2230,6 +2241,12 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } else { String userID3 = (String) imageGrade3.getTag(); + + detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.VISIBLE); + detailsLinearLayout3.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.VISIBLE); linearGrade2.setVisibility(View.VISIBLE); linearGrade3.setVisibility(View.VISIBLE); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index bc88a548d..1d92087a8 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -2,6 +2,7 @@ package com.yunbao.live.socket; import static com.blankj.utilcode.util.SnackbarUtils.dismiss; import static com.blankj.utilcode.util.ViewUtils.runOnUiThread; +import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import static com.yunbao.common.Constants.SOCKET_LIVE_MSG_TO_USER; import static com.yunbao.common.Constants.isAnchor; import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK; @@ -89,9 +90,13 @@ import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.SWManager; +import io.rong.imlib.IRongCallback; import io.rong.imlib.IRongCoreCallback; import io.rong.imlib.IRongCoreEnum; +import io.rong.imlib.RongIMClient; import io.rong.imlib.chatroom.base.RongChatRoomClient; +import io.rong.imlib.model.Conversation; +import io.rong.message.TextMessage; public class SocketRyClient { @@ -1283,7 +1288,8 @@ public class SocketRyClient { u.setId(map.getString("uid")); u.setUserNiceName(map.getString("pkname")); u.setAvatar(map.getString("pkhead")); - mListener.onLinkMicPkApply(u, map.getString("stream"), 1); + u.setRandomPk("11".equals(map.getString("msgtype"))); + mListener.onLinkMicPkApply(u, map.getString("stream"), "11".equals(map.getString("msgtype"))?2:1); break; case 2://收到对方主播PK回调 L.eSw("收到对方主播PK回调"); @@ -1293,6 +1299,8 @@ public class SocketRyClient { if (livePushRyViewHolder != null) { UserBean userBean = new UserBean(); userBean.setId(map.getString("uid")); + userBean.setAvatar(map.getString("pkhead")); + userBean.setUserNiceName(map.getString("pkname")); livePushRyViewHolder.setAnPkRtc(userBean); } break; @@ -1339,7 +1347,38 @@ public class SocketRyClient { } break; case 10://系统发起PK回调 - JSONObject msg1 = new JSONObject(); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 2) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 2) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(map.getString("uid"), conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + + + /*JSONObject msg1 = new JSONObject(); msg1.put("type", "autoLivePK"); msg1.put("uid", CommonAppConfig.getInstance().getUid()); msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); @@ -1377,7 +1416,7 @@ public class SocketRyClient { ToastUtil.show("invite " + map.getString("uid") + " lose :" + rtcErrorCode); } } - }); + });*/ break; } } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index c1960b6b5..dc6695a97 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -1,6 +1,7 @@ package com.yunbao.live.views; import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; +import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import android.Manifest; import android.app.Activity; @@ -58,6 +59,7 @@ import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.socket.SocketSendBean; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -93,6 +95,10 @@ import cn.rongcloud.rtc.base.RCRTCStreamType; import cn.rongcloud.rtc.base.RTCErrorCode; import cn.rongcloud.rtc.core.RendererCommon; import io.agora.beautyapi.faceunity.agora.SWAuManager; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.message.TextMessage; public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @@ -1066,6 +1072,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { //将当前主播画面换个画布展示 String pkUid = (String) event.getObject(); setPkView(pkUid); + } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_PK_END) { String pkUid = (String) event.getObject(); //endpk(pkUid); @@ -1085,7 +1092,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { joinLiveMic(); return; } - RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() + /*RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO).setLiveRole(RCRTCLiveRole.AUDIENCE).build(); RCRTCEngine.getInstance().joinRoom(LiveActivity.mLiveUid, roomConfig, new IRCRTCResultDataCallback() { @@ -1120,7 +1127,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } - }); + });*/ } diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 6178fa71e..7cc43d910 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -589,6 +589,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } public void setAnPkRtc(UserBean u) { + EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar())); if (swManager != null && u != null) { //将多人pk画面屏蔽 dr_pk_view.setVisibility(View.GONE); @@ -617,8 +618,9 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX final SocketSendBean msg1 = new SocketSendBean() .param("_method_", Constants.SOCKET_LINK_MIC_PK) .param("action", 4) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) .param("pkuid", u.getId()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("uid", CommonAppConfig.getInstance().getUid()); msg1.create(); @@ -646,6 +648,8 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } }); + + mLiveRyLinkMicPkPresenter.setPkUserInfoView(u); } private int currentPosition = 0; diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 5fdcd3f5d..7e7039dd7 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -181,6 +181,7 @@ import com.yunbao.live.dialog.ReceiveRendPacketPopup; import com.yunbao.live.dialog.ResultRendPacketPopup; import com.yunbao.live.event.LiveAnchorEvent; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.event.LivePKRightUserInfoEvent; import com.yunbao.live.presenter.LiveDanmuPresenter; import com.yunbao.live.presenter.LiveEnterRoomAnimPresenter; import com.yunbao.live.presenter.LiveGiftAnimPresenter; @@ -3037,6 +3038,11 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public boolean pkHandler = true; + @Subscribe(threadMode = ThreadMode.MAIN) + public void setOtherInfo(LivePKRightUserInfoEvent livePKRightUserInfoEvent){ + setOtherInfo(livePKRightUserInfoEvent.getUid(),livePKRightUserInfoEvent.getuHead(),livePKRightUserInfoEvent.getuName()); + } + //左上角显示对方主播头像及昵称 public void setOtherInfo(String touids, String url, String name) { if (!pkHandler) { diff --git a/live/src/main/res/layout/view_live_push_ry.xml b/live/src/main/res/layout/view_live_push_ry.xml index 86fe88ebf..bb814174d 100644 --- a/live/src/main/res/layout/view_live_push_ry.xml +++ b/live/src/main/res/layout/view_live_push_ry.xml @@ -114,12 +114,32 @@ android:layout_height="match_parent" /> + + + + + + - - - - - Date: Mon, 13 May 2024 17:31:55 +0800 Subject: [PATCH 14/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E8=87=AA=E5=8B=95PK,=E7=9B=B4=E6=8E=A5PK]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/live/activity/LiveActivity.java | 2 +- .../live/activity/LiveRyAnchorActivity.java | 103 +++++++----------- .../live/adapter/FreePkRecyclerAdapter.java | 3 +- .../presenter/LiveRyLinkMicPkPresenter.java | 16 ++- .../live/socket/SocketLinkMicPkUtil.java | 3 +- .../yunbao/live/socket/SocketRyClient.java | 36 +++++- .../live/views/LivePushRyViewHolder.java | 2 +- .../yunbao/live/views/LiveRoomViewHolder.java | 1 - 8 files changed, 89 insertions(+), 77 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index 579a75bc6..51dd79c30 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -728,7 +728,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL @Override public void onLinkMicPkStart(final String pkUid, final String pkhead, final String pkname, String isLadders) { if (mContext instanceof LiveAudienceActivity) return; - Log.e("ry", "pkUid = " + pkUid + ", pkhead = " + pkhead + ", pkname = " + pkname + ", isLadders = " + isLadders); + L.eSw( "pkUid = " + pkUid + ", pkhead = " + pkhead + ", pkname = " + pkname + ", isLadders = " + isLadders); if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); pr = new pkRunnable(pkUid, pkhead, pkname, isLadders); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 3a4e4c05a..76c3fb7ba 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -193,7 +193,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (RandomPkManager.getInstance().isRankModel()) { msg1.put("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); } - linkMicAnchorApply(pkUid, pkUid, msg1.toString()); + linkMicAnchorApply(pkUid, pkUid, true); } @Override @@ -1203,7 +1203,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl */ public void linkMicAnchorApply(String pkUid, String stream) { JSONObject msg1 = buildLinkMicJSON(); - linkMicAnchorApply(pkUid, stream, msg1.toString()); + linkMicAnchorApply(pkUid, stream, false); } public JSONObject buildLinkMicJSON() { @@ -1215,7 +1215,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl return msg1; } - public void linkMicAnchorApply(final String pkUid, String stream, String extra) { + public void linkMicAnchorApply(final String pkUid, String stream, boolean extra) { LiveHttpUtil.livePkCheckLive(pkUid, stream, mStream, new HttpCallback() { @Override @@ -1224,71 +1224,46 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl JSONObject obj = JSON.parseObject(info[0]); if (obj != null) { if (obj.getString("ispk").equals("0")) { - - // TODO: 2024/4/11 发送IM消息 - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 1) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", pkUid) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain("g" + pkUid, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("tx", "发送成功"); - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "发送失败" + errorCode.getMessage()); - - } - }); - - /*IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - // ToastUtil.show("邀请 " + pkUid + " 发送成功"); - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - //todo 安卓端状态码说明文档:https://docs.rongcloud.cn/v4/views/rtc/call/code/android.html - Log.e("ry", rtcErrorCode + "aaaaaa" + CommonAppConfig.getInstance().getUid() + "VDSSSS" + pkUid); - if (WordUtil.isNewZh()) { - ToastUtil.show("邀请 " + pkUid + " 发送失败 :" + rtcErrorCode); - } else { - ToastUtil.show("invite " + pkUid + " failed:" + rtcErrorCode); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 1) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", pkUid) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + //判断是否是随机PK + if(extra){ + msg1.param("random_pk", "1"); + msg1.param("msgtype","11"); + if (RandomPkManager.getInstance().isRankModel()) { + msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); } } - });*/ + msg1.create(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain("g" + pkUid, conversationType, messageContent); + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("tx", "发送成功"); + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "发送失败" + errorCode.getMessage()); + + } + }); } else { ToastUtil.show("主播正在PK,稍後再試"); if (RandomPkManager.getInstance().isRandomModel()) { diff --git a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java index 1cf09e983..3f2a0cbf6 100644 --- a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java @@ -143,8 +143,7 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { } mOnItemClickListener.onItemClick(bean, -1); ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), - ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() - ); + false); return; } if (mDrPkNum <= 0) { diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index eba1534b6..059a2f2b2 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -632,8 +632,19 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { LiveRyAnchorActivity.isDRPK = 1; /*---------------------------------------------------------------- */ - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 2) //回复PK申请 2 - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", bean.getId()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 2) //回复PK申请 2 + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", bean.getId()) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + if (RandomPkManager.getInstance().isRankModel()) { + L.eSw("排位赛"); + msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + } + msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); msg1.create(); System.out.println("PK回执 = " + msg1.toString()); Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; @@ -1071,6 +1082,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { .param("pkuid", CommonAppConfig.getInstance().getUid()) .param("msgtype", 2) .param("uid", drPkbeans.get(i).getId()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketLinkMicPkUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketLinkMicPkUtil.java index 8ec8ae0ca..867e0c7c1 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketLinkMicPkUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketLinkMicPkUtil.java @@ -66,7 +66,8 @@ public class SocketLinkMicPkUtil { .param("uid", CommonAppConfig.getInstance().getUid()) .param("pkuid", CommonAppConfig.getInstance().getUid()) .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("name", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg.create(); V2TIMManager.getInstance().sendC2CTextMessage(msg.mResult.toString(), pkUid, new V2TIMSendCallback() { @Override diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index 1d92087a8..c5b55e527 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -2,6 +2,7 @@ package com.yunbao.live.socket; import static com.blankj.utilcode.util.SnackbarUtils.dismiss; import static com.blankj.utilcode.util.ViewUtils.runOnUiThread; +import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import static com.yunbao.common.Constants.SOCKET_LIVE_MSG_TO_USER; import static com.yunbao.common.Constants.isAnchor; @@ -29,6 +30,7 @@ import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.FansModel; import com.yunbao.common.bean.GuardMaturityDateRemindModel; import com.yunbao.common.bean.LinkMicUserBean; +import com.yunbao.common.bean.LiveInfoModel; import com.yunbao.common.bean.LiveUserGiftBean; import com.yunbao.common.bean.MsgModel; import com.yunbao.common.bean.PkRankBean; @@ -49,6 +51,7 @@ import com.yunbao.common.event.SendBlindGiftEvent; import com.yunbao.common.event.SendMoneyLongEndEvent; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.MicUserManager; import com.yunbao.common.manager.MicedUserManager; @@ -1294,13 +1297,13 @@ public class SocketRyClient { case 2://收到对方主播PK回调 L.eSw("收到对方主播PK回调"); RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); - mListener.onLinkMicToPk(map.getString("uid"), map.getString("pkhead"), map.getString("pkname")); - mListener.onLinkMicPkStart(map.getString("uid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); + mListener.onLinkMicToPk(map.getString("uid"), map.getString("uhead"), map.getString("uhead")); + mListener.onLinkMicPkStart(map.getString("uid"), map.getString("uhead"), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); if (livePushRyViewHolder != null) { UserBean userBean = new UserBean(); userBean.setId(map.getString("uid")); - userBean.setAvatar(map.getString("pkhead")); - userBean.setUserNiceName(map.getString("pkname")); + userBean.setAvatar(map.getString("uhead")); + userBean.setUserNiceName(map.getString("uname")); livePushRyViewHolder.setAnPkRtc(userBean); } break; @@ -1347,12 +1350,13 @@ public class SocketRyClient { } break; case 10://系统发起PK回调 - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) .param("action", 2) .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) .param("pkuid", CommonAppConfig.getInstance().getUid()) .param("msgtype", 2) .param("uid", CommonAppConfig.getInstance().getUid()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); @@ -1377,6 +1381,28 @@ public class SocketRyClient { } }); + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + + LiveNetManager.get(mContext).getLiveInfo(map.getString("uid"), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + mListener.onLinkMicToPk(map.getString("uid"), data.getAvatar(), map.getString("uhead")); + mListener.onLinkMicPkStart(map.getString("uid"), data.getAvatar(), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); + if (livePushRyViewHolder != null) { + UserBean userBean = new UserBean(); + userBean.setId(map.getString("uid")); + userBean.setAvatar(data.getAvatar()); + userBean.setUserNiceName(map.getString("uname")); + livePushRyViewHolder.setAnPkRtc(userBean); + } + } + + @Override + public void onError(String error) { + + } + } + ); /*JSONObject msg1 = new JSONObject(); msg1.put("type", "autoLivePK"); diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 7cc43d910..4a8b5871c 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -301,7 +301,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX JSONObject map = JSONObject.parseObject(extra); userBean1.setId(map.getString("uid")); userBean1.setUserNiceName(map.getString("pkname")); - userBean1.setAvatar(map.getString("pkhead")); + userBean1.setAvatar(map.getString("uhead")); } else { userBean1.setId(inviterRoomId); userBean1.setUserNiceName("null"); diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 7e7039dd7..cbe457cc0 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -2575,7 +2575,6 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis initPkRankView(bean); if (!StringUtil.isEmpty(bean.getClickUrl())) { - pkRankVf.setOnClickListener(v -> { MobclickAgent.onEvent(mContext, "live_room_sky", "天梯赛按钮"); Bundle bundle = new Bundle(); From cb376aa83a1b664111928f89b9259a4beb3cea7c Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Tue, 14 May 2024 18:29:28 +0800 Subject: [PATCH 15/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presenter/LiveRyLinkMicPkPresenter.java | 51 +++---------------- .../live/views/LivePushRyViewHolder.java | 1 - .../live/views/PortraitLiveManager.java | 1 + live/src/main/res/layout/view_live_room.xml | 3 +- 4 files changed, 10 insertions(+), 46 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 059a2f2b2..8357e9d30 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -647,9 +647,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); msg1.create(); System.out.println("PK回执 = " + msg1.toString()); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain("g" + bean.getId(), conversationType, messageContent); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain( bean.getId(), conversationType, messageContent); RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override @@ -772,6 +772,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { isPK(u); } else { if (mPkWaitCount < 0) { + if(rtcRoom==null){ + return; + } rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { @Override @@ -1902,6 +1905,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 主播与主播PK 所有人收到PK开始的回调 */ public void onLinkMicPkStart(String pkUid, int i) { + L.eSw("onLinkMicPkStart pkUid "+pkUid+" "+i); Log.d("tag", i + "mPkTimeCount2"); mIsPk = true; hideSendPkWait(); @@ -1910,7 +1914,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mPkUid = pkUid; mApplyUid = null; mApplyStream = null; - + isDRPK=1; if (mLiveLinkMicPkViewHolder == null) { mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); mLiveLinkMicPkViewHolder.addToParent(); @@ -1923,7 +1927,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(pkUid)); mLiveLinkMicPkViewHolder.showTime(); mPkTimeCount = 100; - nextPkTimeCountDown(2); + nextPkTimeCountDown(2);//时间倒计时 if (mIsAnchor) { ((LiveRyAnchorActivity) mContext).setPkBtnVisible(false); mPkTimeCount = PK_TIME_MAX; @@ -2000,45 +2004,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } }); -// inputStreamList.clear(); - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); - //视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); -//大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); -//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 -//如不设置宽高值则服务端将使用默认宽高 360 * 640 -//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, -//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 720; - int height = 1280; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //1. 设置自适应合流布局模式 - config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); - //2. 合流画布设置 - if (rcrtcLiveInfo != null) { - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功16"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } runOnUiThread(new Runnable() { public void run() { diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 4a8b5871c..373a64543 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -648,7 +648,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } }); - mLiveRyLinkMicPkPresenter.setPkUserInfoView(u); } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index a6cc00a76..a882f5de1 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -666,6 +666,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe }else{//单人连麦 LivePkMicModel connection_info = data.getEnterRoomInfo().getConnectionInfo(); if(!StringUtil.isEmpty(connection_info.getPkuid())){ + mPkUid = connection_info.getPkuid(); mLivePlayViewHolder.setPkView(connection_info.getPkuid()); } } diff --git a/live/src/main/res/layout/view_live_room.xml b/live/src/main/res/layout/view_live_room.xml index 13d42703d..50469cc42 100644 --- a/live/src/main/res/layout/view_live_room.xml +++ b/live/src/main/res/layout/view_live_room.xml @@ -744,9 +744,8 @@ layout="@layout/view_red_packet" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_below="@+id/live_rank_pk" android:layout_marginStart="12dp" - android:layout_marginTop="15dp" + android:layout_marginTop="100dp" android:visibility="gone" /> Date: Wed, 15 May 2024 15:55:31 +0800 Subject: [PATCH 16/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/common/Constants.java | 2 + .../src/main/res/layout/view_flaot_live.xml | 6 + common/src/main/res/values-zh-rHK/strings.xml | 1 + common/src/main/res/values-zh-rTW/strings.xml | 1 + common/src/main/res/values-zh/strings.xml | 1 + common/src/main/res/values/strings.xml | 1 + .../faceunity/agora}/LiveFloatView.java | 171 +++++++++++------- .../faceunity/agora/SWAuManager.java | 5 +- .../live/activity/LiveAnchorActivity.java | 2 +- .../live/views/LiveAudienceViewHolder.java | 2 + .../live/views/LivePlayRyViewHolder.java | 35 ++-- .../live/views/PortraitLiveManager.java | 7 +- .../yunbao/main/activity/MainActivity.java | 6 +- 13 files changed, 156 insertions(+), 84 deletions(-) rename {common/src/main/java/com/yunbao/common/views/weight => lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora}/LiveFloatView.java (59%) diff --git a/common/src/main/java/com/yunbao/common/Constants.java b/common/src/main/java/com/yunbao/common/Constants.java index a0ea5df91..4a3e42403 100644 --- a/common/src/main/java/com/yunbao/common/Constants.java +++ b/common/src/main/java/com/yunbao/common/Constants.java @@ -268,6 +268,8 @@ public class Constants { public static final int LIVE_SDK_KSY = 0;//金山推流 public static final int LIVE_SDK_TX = 1;//腾讯推流 + public static final int LIVE_SDK_SW = 2;//声网 + public static final int LINK_MIC_TYPE_NORMAL = 0;//观众与主播连麦 public static final int LINK_MIC_TYPE_ANCHOR = 1;//主播与主播连麦 diff --git a/common/src/main/res/layout/view_flaot_live.xml b/common/src/main/res/layout/view_flaot_live.xml index 5b1d2d4db..715547e35 100644 --- a/common/src/main/res/layout/view_flaot_live.xml +++ b/common/src/main/res/layout/view_flaot_live.xml @@ -25,6 +25,12 @@ android:id="@+id/video_view" android:layout_width="match_parent" android:layout_height="match_parent" /> + + + diff --git a/common/src/main/res/values-zh-rHK/strings.xml b/common/src/main/res/values-zh-rHK/strings.xml index 423420996..6122bf711 100644 --- a/common/src/main/res/values-zh-rHK/strings.xml +++ b/common/src/main/res/values-zh-rHK/strings.xml @@ -1499,4 +1499,5 @@ 2.用戶關注主播並參與活動,將在倒計時五分鐘結束後瓜分活動金豆; 3.此活動的最終解釋權歸PDLIVE所有。 短劇 + 主播正在PK,稍後再試 diff --git a/common/src/main/res/values-zh-rTW/strings.xml b/common/src/main/res/values-zh-rTW/strings.xml index fc5fa7cc7..97460c705 100644 --- a/common/src/main/res/values-zh-rTW/strings.xml +++ b/common/src/main/res/values-zh-rTW/strings.xml @@ -1498,4 +1498,5 @@ 2.用戶關注主播並參與活動,將在倒計時五分鐘結束後瓜分活動金豆; 3.此活動的最終解釋權歸PDLIVE所有。 短劇 + 主播正在PK,稍後再試 diff --git a/common/src/main/res/values-zh/strings.xml b/common/src/main/res/values-zh/strings.xml index b328ddb56..0765a70d7 100644 --- a/common/src/main/res/values-zh/strings.xml +++ b/common/src/main/res/values-zh/strings.xml @@ -1495,5 +1495,6 @@ 2.用戶關注主播並參與活動,將在倒計時五分鐘結束後瓜分活動金豆; 3.此活動的最終解釋權歸PDLIVE所有。 短劇 + 主播正在PK,稍後再試 diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 1a36a41c6..f7d9f1a4f 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1504,4 +1504,5 @@ Limited ride And limited avatar frame 2.Users who follow the anchor and participate in the activity will divide the gold beans of the activity after the countdown of five minutes ends; 3.The final interpretation of this activity belongs to PDLIVE. Theater + The anchor is in PK, please try again later diff --git a/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java similarity index 59% rename from common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java rename to lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java index 0f9efc7de..e09f22338 100644 --- a/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java @@ -1,4 +1,4 @@ -package com.yunbao.common.views.weight; +package io.agora.beautyapi.faceunity.agora; import android.app.Activity; import android.os.Bundle; @@ -7,6 +7,7 @@ import android.text.TextUtils; import android.util.Log; import android.view.Gravity; import android.view.View; +import android.widget.FrameLayout; import android.widget.RelativeLayout; import androidx.cardview.widget.CardView; @@ -19,6 +20,8 @@ import com.lzf.easyfloat.interfaces.OnInvokeView; import com.tencent.rtmp.ITXLivePlayListener; import com.tencent.rtmp.TXLivePlayer; import com.tencent.rtmp.ui.TXCloudVideoView; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.Constants; import com.yunbao.common.R; import com.yunbao.common.bean.LiveBean; import com.yunbao.common.dialog.HintDialog; @@ -26,10 +29,12 @@ import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.views.floatingview.APPEasyFloat; import com.yunbao.common.views.floatingview.FloatingMagnetView; import com.yunbao.common.views.floatingview.MagnetViewListener; +import com.yunbao.common.views.weight.ViewClicksAntiShake; import kotlin.Unit; import kotlin.jvm.functions.Function1; @@ -50,12 +55,14 @@ public class LiveFloatView implements Function1 { private FloatCallbacks.Builder builder; private String TAG = "LiveFloatView"; private TXLivePlayer mPlayer; + private FrameLayout videoFrameLayout; + private TXCloudVideoView videoView; + private SWAuManager swAuManager; public static LiveFloatView getInstance() { if (instance == null) { instance = new LiveFloatView(); } - return instance; } @@ -79,39 +86,53 @@ public class LiveFloatView implements Function1 { cardParams.height = DpUtil.dp2px(224); cardParams.width = DpUtil.dp2px(126); } - TXCloudVideoView videoView = magnetView.findViewById(R.id.video_view); - mPlayer = new TXLivePlayer(mContext); - mPlayer.setPlayerView(videoView); - mPlayer.startPlay(url, TXLivePlayer.PLAY_TYPE_LIVE_FLV); - mPlayer.setPlayListener(new ITXLivePlayListener() { - @Override - public void onPlayEvent(int event, Bundle param) { - float videoWidth = param.getInt("EVT_PARAM1", 0); - float videoHeight = param.getInt("EVT_PARAM2", 0); - Log.e("视频流有", "videoWidth:" + videoWidth + " videoHeight:" + videoHeight); - if (mLiveBean.getLandscape() != 1){ - if (videoWidth > 720) { - cardParams.height = DpUtil.dp2px(190); - cardParams.width = DpUtil.dp2px(255); - } else { - cardParams.height = DpUtil.dp2px(224); - cardParams.width = DpUtil.dp2px(126); + if(mLiveSDK == Constants.LIVE_SDK_SW){ + L.eSw("mLiveSDK == Constants.LIVE_S2222222222222222"); + videoFrameLayout = magnetView.findViewById(R.id.videoFrameLayout); + swAuManager = SWAuManager.get(); + swAuManager.setAudienceContainer(videoFrameLayout); + swAuManager.initRtcEngine( mContext); + swAuManager.setupRemoteVideo(Integer.parseInt(mLiveBean.getUid())); + //进入主播房间 + swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(mLiveBean.getUid())); + }else{ + videoView = magnetView.findViewById(R.id.video_view); + mPlayer = new TXLivePlayer(mContext); + mPlayer.setPlayerView(videoView); + mPlayer.startPlay(url, TXLivePlayer.PLAY_TYPE_LIVE_FLV); + mPlayer.setPlayListener(new ITXLivePlayListener() { + @Override + public void onPlayEvent(int event, Bundle param) { + float videoWidth = param.getInt("EVT_PARAM1", 0); + float videoHeight = param.getInt("EVT_PARAM2", 0); + Log.e("视频流有", "videoWidth:" + videoWidth + " videoHeight:" + videoHeight); + if (mLiveBean.getLandscape() != 1){ + if (videoWidth > 720) { + cardParams.height = DpUtil.dp2px(190); + cardParams.width = DpUtil.dp2px(255); + } else { + cardParams.height = DpUtil.dp2px(224); + cardParams.width = DpUtil.dp2px(126); + } + layout.setLayoutParams(cardParams); } - layout.setLayoutParams(cardParams); } - } + @Override + public void onNetStatus(Bundle bundle) { - @Override - public void onNetStatus(Bundle bundle) { + } + }); + } - - } - }); ViewClicksAntiShake.clicksAntiShake(magnetView.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { - mPlayer.stopPlay(true); + if(mLiveSDK == Constants.LIVE_SDK_SW){ + SWAuManager.get().exitChannelAll(); + }else{ + mPlayer.stopPlay(true); + } APPEasyFloat.getInstance().dismiss(mContext); if (IMLoginManager.get(mContext).isHint2() && !((FragmentActivity) mContext).getSupportFragmentManager().isDestroyed()) { HintDialog fragment = new HintDialog(); @@ -122,13 +143,20 @@ public class LiveFloatView implements Function1 { } } }); - ViewClicksAntiShake.clicksAntiShake(videoView, () -> { - mPlayer.stopPlay(true); - APPEasyFloat.getInstance().dismiss(mContext); - new Handler().post(liveCheck); + if(mLiveSDK == Constants.LIVE_SDK_SW){ + ViewClicksAntiShake.clicksAntiShake(videoFrameLayout, () -> { + mPlayer.stopPlay(true); + APPEasyFloat.getInstance().dismiss(mContext); + new Handler().post(liveCheck); + }); + }else{ + ViewClicksAntiShake.clicksAntiShake(videoView, () -> { + mPlayer.stopPlay(true); + APPEasyFloat.getInstance().dismiss(mContext); + new Handler().post(liveCheck); + }); + } - - }); } @Override @@ -164,7 +192,7 @@ public class LiveFloatView implements Function1 { public LiveFloatView cacheLiveData(LiveBean mLiveBean, int mLiveType, int mLiveSDK, int mLiveTypeVal) { this.mLiveBean = mLiveBean; this.mLiveType = mLiveType; - this.mLiveSDK = mLiveSDK; + this.mLiveSDK = Constants.LIVE_SDK_SW; this.mLiveTypeVal = mLiveTypeVal; return instance; } @@ -202,7 +230,8 @@ public class LiveFloatView implements Function1 { @Override public void invoke(View view) { - TXCloudVideoView videoView = view.findViewById(R.id.video_view); + videoFrameLayout = view.findViewById(R.id.videoFrameLayout); + L.eSw("invoke(View view) invoke(View view) invoke(View view) invoke(View view) "); CardView layout = view.findViewById(R.id.layout); RelativeLayout.LayoutParams cardParams = (RelativeLayout.LayoutParams) layout.getLayoutParams(); if (mLiveBean.getLandscape() == 1) { @@ -213,39 +242,54 @@ public class LiveFloatView implements Function1 { cardParams.width = DpUtil.dp2px(126); } layout.setLayoutParams(cardParams); - mPlayer = new TXLivePlayer(mContext); - mPlayer.setPlayerView(videoView); - mPlayer.startPlay(url, TXLivePlayer.PLAY_TYPE_LIVE_FLV); - mPlayer.setPlayListener(new ITXLivePlayListener() { - @Override - public void onPlayEvent(int event, Bundle param) { - float videoWidth = param.getInt("EVT_PARAM1", 0); - float videoHeight = param.getInt("EVT_PARAM2", 0); - Log.e("视频流有", "videoWidth:" + videoWidth + " videoHeight:" + videoHeight); - if (mLiveBean.getLandscape() != 1){ - if (videoWidth > 720) { - cardParams.height = DpUtil.dp2px(190); - cardParams.width = DpUtil.dp2px(255); - } else { - cardParams.height = DpUtil.dp2px(224); - cardParams.width = DpUtil.dp2px(126); + if(mLiveSDK == Constants.LIVE_SDK_SW){ + L.eSw("mLiveSDK == Constants.LIVE_SDK_SW mLive1111111"); + swAuManager = SWAuManager.get(); + swAuManager.setAudienceContainer(videoFrameLayout); + swAuManager.initRtcEngine( mContext); + swAuManager.setupRemoteVideo(Integer.parseInt(mLiveBean.getUid())); + //进入主播房间 + swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(mLiveBean.getUid())); + }else{ + TXCloudVideoView videoView = view.findViewById(R.id.video_view); + mPlayer = new TXLivePlayer(mContext); + mPlayer.setPlayerView(videoView); + mPlayer.startPlay(url, TXLivePlayer.PLAY_TYPE_LIVE_FLV); + mPlayer.setPlayListener(new ITXLivePlayListener() { + @Override + public void onPlayEvent(int event, Bundle param) { + float videoWidth = param.getInt("EVT_PARAM1", 0); + float videoHeight = param.getInt("EVT_PARAM2", 0); + Log.e("视频流有", "videoWidth:" + videoWidth + " videoHeight:" + videoHeight); + if (mLiveBean.getLandscape() != 1){ + if (videoWidth > 720) { + cardParams.height = DpUtil.dp2px(190); + cardParams.width = DpUtil.dp2px(255); + } else { + cardParams.height = DpUtil.dp2px(224); + cardParams.width = DpUtil.dp2px(126); + } + layout.setLayoutParams(cardParams); } - layout.setLayoutParams(cardParams); + } - } - - @Override - public void onNetStatus(Bundle bundle) { - - } - }); + @Override + public void onNetStatus(Bundle bundle) { + } + }); + } ViewClicksAntiShake.clicksAntiShake(view.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { - mPlayer.stopPlay(true); + if(mLiveSDK == Constants.LIVE_SDK_SW){ + SWAuManager.get().exitChannelAll(); + }else{ + mPlayer.stopPlay(true); + } + EasyFloat.dismiss("LiveFloatView", true); if (IMLoginManager.get(mContext).isHint2() && !((FragmentActivity) mContext).getSupportFragmentManager().isDestroyed()) { HintDialog fragment = new HintDialog(); @@ -257,8 +301,11 @@ public class LiveFloatView implements Function1 { } }); ViewClicksAntiShake.clicksAntiShake(view, () -> { - - mPlayer.stopPlay(true); + if(mLiveSDK == Constants.LIVE_SDK_SW){ + SWAuManager.get().exitChannelAll(); + }else{ + mPlayer.stopPlay(true); + } new Handler().post(liveCheck); diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index 7d46c50b9..26ceb75c6 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -309,7 +309,10 @@ public class SWAuManager extends BaseCacheManager { * 退出所有的直播间 */ public void exitChannelAll() { - mRtcEngine.leaveChannel(); + L.eSw("exitChannelAll exitChannelAll exitChannelAll"); + if(mRtcEngine!=null){ + mRtcEngine.leaveChannel(); + } } public static String getChannelName(String liveUid) { diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java index 0f979153b..282a8dac0 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java @@ -885,7 +885,7 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic } }); } else { - ToastUtil.show("主播正在PK,稍後再試"); + ToastUtil.show(getString(R.string.pking_over)); } } } diff --git a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java index 08eccaa73..0a3d60e56 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java @@ -68,6 +68,7 @@ import java.util.List; import java.util.Locale; import java.util.Random; +import io.agora.beautyapi.faceunity.agora.SWAuManager; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; @@ -791,6 +792,7 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { * 退出直播间 */ private void close() { + SWAuManager.get().exitChannelAll(); handler.removeCallbacks(runnable); handler1.removeCallbacks(runnable1); ((LiveAudienceActivity) mContext).onBackPressed(); diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index dc6695a97..37fd85f13 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -226,7 +226,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { * @param Uid */ public void setPkView(String Uid) { - L.eSw("setPkView Uid "+Uid); + L.eSw("setPkView Uid " + Uid); mPkContainer.setVisibility(View.VISIBLE); swAuManager.updateMyChannelView((FrameLayout) mLeftContainer, Integer.parseInt(liveUid)); ry_view.removeAllViews(); @@ -242,13 +242,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Override public void setDrMicInfo(UserBean u) { isAdd = true; - L.eSw("setDrMicInfo:-----------------" + u.getId()+" drMicUserList"+new Gson().toJson(drMicUserList)); + L.eSw("setDrMicInfo:-----------------" + u.getId() + " drMicUserList" + new Gson().toJson(drMicUserList)); for (int i = 0; i < drMicUserList.size(); i++) { - if (u.getId().equals(drMicUserList.get(i).getId())||u.getId().equals(liveUid)) { + if (u.getId().equals(drMicUserList.get(i).getId()) || u.getId().equals(liveUid)) { isAdd = false; } } - L.eSw("setDrMicInfo:---------------isAdd--"+isAdd ); + L.eSw("setDrMicInfo:---------------isAdd--" + isAdd); //加载多人PK(连麦)主播视图 if (isAdd) { dr_pk_view.setVisibility(View.VISIBLE); @@ -281,7 +281,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void onSuccess(int code, String msg, String[] info) { if (info.length > 0) { JSONObject obj = JSONObject.parseObject(info[0]); - List drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + List drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); int removeIndex = -1; for (int i = 0; i < drPkbeans.size(); i++) { if (liveUid.equals(String.valueOf(drPkbeans.get(i).getId()))) { @@ -312,7 +312,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } - public void setDrPkView(List drPkbeanList){ + public void setDrPkView(List drPkbeanList) { if (detailsView1 != null) { dr1_preview.removeView(detailsView1); } @@ -405,14 +405,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } - /** * 退出单人pk * * @param pkUid */ public void endpk(String pkUid) { - L.eSw("endpk "+pkUid); + L.eSw("endpk " + pkUid); mPkContainer.setVisibility(View.GONE); swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), SWAuManager.getChannelName(pkUid)); swAuManager.updateMyChannelView(ry_view, Integer.parseInt(liveUid)); @@ -438,7 +437,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { for (int i = 0; i < drMicUserList.size(); i++) { swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drMicUserList.get(i).getId()); } - drMicUserList =new ArrayList<>(); + drMicUserList = new ArrayList<>(); //將當前主播畫面放大 swAuManager.updateMyChannelView((FrameLayout) ry_view, Integer.parseInt(liveUid)); } @@ -666,7 +665,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mStarted = false; Bus.getOff(this); EventBus.getDefault().unregister(this); - swAuManager.exitChannelAll(); + //swAuManager.exitChannelAll(); L.e(TAG, "release------->"); } @@ -919,15 +918,26 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.requestLayout(); } + boolean isShow = false; @Subscribe(threadMode = ThreadMode.MAIN) public void onUpdata(String str) { if ("UsertoRY".equals(str)) { - DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback() { + //todo 新增dis监听 + if (isShow) { + return; + } + isShow = true; + DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback2() { + @Override + public void onCancelClick() { + isShow = false; + } + @Override public void onConfirmClick(Dialog dialog, String content) { UsertoRY(); - dialog = null; + isShow = false; } }); @@ -1425,6 +1435,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); } } + private class ExoPlayerListener implements Player.Listener { String TAG = "播放流"; diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index a882f5de1..1ac6894bc 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -82,7 +82,6 @@ import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.common.utils.formatBigNum; -import com.yunbao.common.views.weight.LiveFloatView; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; @@ -122,6 +121,8 @@ import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback; import cn.rongcloud.rtc.base.RTCErrorCode; +import io.agora.beautyapi.faceunity.agora.LiveFloatView; +import io.agora.beautyapi.faceunity.agora.SWAuManager; import io.rong.imlib.IRongCallback; import io.rong.imlib.IRongCoreCallback; import io.rong.imlib.IRongCoreEnum; @@ -326,7 +327,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public void run() { loading.setVisibility(View.GONE); enterRoomLeaveHandler.post(enterRoomLeaveRunnable); - ToastUtil.show(mContext.getString(R.string.net_error) + " :500");//异常下播,等待加载时间过了后弹出 + //ToastUtil.show(mContext.getString(R.string.net_error) + " :500");//异常下播,等待加载时间过了后弹出 } }; @@ -940,7 +941,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.removeFromParent(); mLiveRoomViewHolder.countDownTimerTrickery = null; } - mLiveAudienceViewHolder = null; mLivePlayViewHolder = null; mLiveRoomViewHolder = null; @@ -1940,6 +1940,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (!isEnterRoom) { return; } + SWAuManager.get().exitChannelAll(); LiveNetManager.get(mContext) .leaveRoomNew(leaveStream, leaveGroupId, new com.yunbao.common.http.base.HttpCallback() { @Override diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index df83f8672..eb8874263 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -13,8 +13,6 @@ import android.app.PendingIntent; import android.content.ClipData; import android.content.Context; import android.content.Intent; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -57,7 +55,6 @@ import com.yunbao.common.Constants; import com.yunbao.common.activity.AbsActivity; import com.yunbao.common.activity.WebViewActivity; import com.yunbao.common.adapter.ViewPagerAdapter; -import com.yunbao.common.bean.AnchorRecommendItemModel; import com.yunbao.common.bean.AnchorRecommendModel; import com.yunbao.common.bean.AnchorStartLiveBean; import com.yunbao.common.bean.ChatRemarksBean; @@ -98,7 +95,6 @@ import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.GiftCacheUtil; import com.yunbao.common.utils.GoogleUtils; -import com.yunbao.common.utils.L; import com.yunbao.common.utils.LiveRoomCheckLivePresenter; import com.yunbao.common.utils.LocationUtil; import com.yunbao.common.utils.ProcessResultUtil; @@ -110,7 +106,6 @@ import com.yunbao.common.utils.WordUtil; import com.yunbao.common.views.APKUpdateCustomPopup; import com.yunbao.common.views.AbsMainViewHolder; import com.yunbao.common.views.floatingview.APPEasyFloat; -import com.yunbao.common.views.weight.LiveFloatView; import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.utils.LiveStorge; import com.yunbao.main.R; @@ -148,6 +143,7 @@ import java.util.concurrent.TimeUnit; import cn.rongcloud.rtc.api.RCRTCConfig; import cn.rongcloud.rtc.api.RCRTCEngine; +import io.agora.beautyapi.faceunity.agora.LiveFloatView; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.rong.imkit.config.RongConfigCenter; From 6a4ac352032fc8798eb2e2b4291553ac7d8b2b5c Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 18 May 2024 14:36:35 +0800 Subject: [PATCH 17/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?AB=E9=9D=A2]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 10 +- .../java/com/yunbao/common/Constants.java | 4 +- .../common/activity/WebViewActivity.java | 4 +- .../common/bean/AiAutomaticSpeechModel.java | 14 + .../yunbao/common/bean/CheckLiveModel.java | 10 + .../yunbao/common/bean/EnterRoomNewModel.java | 1 + .../common/event/SendBlindGiftEvent.java | 29 + .../com/yunbao/common/http/LiveHttpUtil.java | 12 +- .../imrongcloud/RongcloudIMManager.java | 91 +- .../com/yunbao/common/utils/AppManager.java | 9 + .../com/yunbao/common/utils/DialogUitl.java | 9 + .../utils/JavascriptInterfaceUtils.java | 4 +- .../utils/LiveRoomCheckLivePresenter.java | 15 +- .../com/yunbao/common/utils/RouteUtil.java | 24 +- .../common/views/SudGameListViewHolder.java | 4 +- .../faceunity/agora/LiveFloatView.java | 2 +- live/src/main/AndroidManifest.xml | 5 + .../yunbao/live/activity/LiveActivity.java | 128 +- .../live/activity/LiveAnchorActivity.java | 5 +- .../live/activity/LiveAudienceActivity.java | 469 ++-- .../live/activity/LiveRyAnchorActivity.java | 191 +- .../live/activity/LiveSwAnchorActivity.java | 1939 ++++++++++++++ .../live/activity/LiveTRTCAnchorActivity.java | 2 +- .../live/activity/PDLIiveChatActivity.java | 4 +- .../live/activity/WebViewActivityMedal.java | 4 +- .../live/activity/ZhuangBanActivity.java | 4 +- .../adapter/AnchorUserMicInfoAdapter.java | 4 +- .../live/adapter/FreePkRecyclerAdapter.java | 25 +- .../live/adapter/LiveFunctionAdapter.java | 5 +- .../com/yunbao/live/bean/LiveChatBean.java | 10 + .../live/dialog/FreePkDialogFragment.java | 6 + .../live/dialog/LiveBeautyDialogFragment.java | 2 - .../dialog/LiveFunctionDialogFragment.java | 5 +- .../live/dialog/LiveGameDialogFragment.java | 10 +- .../live/dialog/LiveHDDialogFragment.java | 8 +- .../live/dialog/LiveInputDialogFragment.java | 4 +- .../dialog/LiveLinkMicListDialogFragment.java | 26 +- .../dialog/LiveNewFunctionDialogFragment.java | 67 +- .../dialog/LiveNewGuardBuyDialogFragment.java | 4 +- .../dialog/LiveNewWishListDialogFragment.java | 13 +- .../dialog/LiveOldUserDialogFragment.java | 2 +- .../live/dialog/LiveUserDialogFragment.java | 6 +- .../dialog/LiveUserMoreDialogFragment.java | 4 +- .../dialog/LiveWishListDialogFragment.java | 5 +- .../live/dialog/RandomPkDialogFragment.java | 6 +- .../yunbao/live/event/LiveAudienceEvent.java | 3 +- .../live/presenter/LiveGiftAnimPresenter.java | 2 +- .../presenter/LiveRyLinkMicPkPresenter.java | 1390 ++++++---- .../presenter/LiveSwLinkMicPkPresenter.java | 2324 +++++++++++++++++ .../yunbao/live/socket/SocketRyChatUtil.java | 51 +- .../yunbao/live/socket/SocketRyClient.java | 422 +-- .../live/socket/SocketRyLinkMicPkUtil.java | 6 +- .../yunbao/live/socket/SocketSwClient.java | 1441 ++++++++++ .../live/socket/SocketSwLinkMicPkUtil.java | 210 ++ .../live/utils/LiveRoomVoteManager.java | 6 +- .../live/views/LiveAudienceViewHolder.java | 1 - .../yunbao/live/views/LiveEndViewHolder.java | 22 +- .../live/views/LiveNewReadyRyViewHolder.java | 56 +- .../live/views/LiveNewReadySwViewHolder.java | 963 +++++++ .../live/views/LivePlayKsyViewHolder.java | 41 +- .../yunbao/live/views/LivePlayListener.java | 2 +- .../live/views/LivePlayRyViewHolder.java | 746 +++--- .../live/views/LivePlaySwViewHolder.java | 1504 +++++++++++ .../live/views/LivePlayTxViewHolder.java | 30 + .../views/LivePlayTxViewHolder_backup.java | 476 ---- .../live/views/LivePushRyViewHolder.java | 524 ++-- .../live/views/LivePushSwViewHolder.java | 731 ++++++ .../live/views/LiveReadyRyViewHolder.java | 24 +- .../live/views/LiveReadyViewHolder.java | 2 +- .../live/views/LiveRoomPlayViewHolder.java | 12 + .../yunbao/live/views/LiveRoomViewHolder.java | 44 +- .../live/views/LiveRyAnchorViewHolder.java | 21 +- .../live/views/PortraitLiveManager.java | 211 +- .../yunbao/live/views/SidebarViewHoler.java | 4 +- .../main/res/layout/view_live_play_ksy.xml | 101 +- .../src/main/res/layout/view_live_play_sw.xml | 169 ++ .../src/main/res/layout/view_live_push_ry.xml | 94 +- .../src/main/res/layout/view_live_push_sw.xml | 235 ++ .../yunbao/main/activity/EntryActivity.java | 4 +- .../main/activity/LiveClassActivity.java | 4 +- .../yunbao/main/activity/LoginActivity.java | 4 +- .../yunbao/main/activity/MainActivity.java | 12 +- .../main/activity/MyWebViewActivity.java | 4 +- .../main/activity/MyWebViewActivity2.java | 4 +- .../main/activity/RegisterActivity.java | 4 +- .../yunbao/main/activity/SearchActivity.java | 4 +- .../main/activity/WeekWebViewActivity.java | 4 +- .../main/activity/ZhuangBanActivity.java | 4 +- .../yunbao/main/adapter/SearchAdapter.java | 4 +- .../dialog/AnchorStartLiveNotifyDialog.java | 4 +- .../main/dialog/MainStartDialogFragment.java | 25 +- .../yunbao/main/dialog/OneLoginDialog.java | 6 +- .../fragment/MainHomeCommunityFragment.java | 4 +- .../views/AbsMainListChildViewHolder.java | 8 +- .../main/views/MainHomeLiveViewHolder.java | 8 +- .../main/views/MainMessageViewHolder.java | 4 +- .../main/views/UserHomeViewHolder2.java | 4 +- 97 files changed, 12448 insertions(+), 2740 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java create mode 100644 live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java create mode 100644 live/src/main/java/com/yunbao/live/socket/SocketSwClient.java create mode 100644 live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java create mode 100644 live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java create mode 100644 live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java delete mode 100644 live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java create mode 100644 live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java create mode 100644 live/src/main/res/layout/view_live_play_sw.xml create mode 100644 live/src/main/res/layout/view_live_push_sw.xml diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 737efced5..cb28e9277 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -50,7 +50,7 @@ import com.yunbao.common.utils.GoogleUtils; import com.yunbao.common.utils.L; import com.yunbao.common.utils.SpUtil; import com.yunbao.live.socket.SocketReceiveBean; -import com.yunbao.live.socket.SocketRyClient; +import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.utils.LiveImDeletUtil; import com.yunbao.live.views.PortraitLiveManager; import com.yunbao.live.views.RecommendLiveRoomProvider; @@ -209,8 +209,8 @@ public class AppContext extends CommonAppContext { if (content.getContent().contains("_method_")) { msg.obj = content.getContent(); //观众页面 - if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { - SocketRyClient.mSocketHandler.sendMessage(msg); + if (SocketSwClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { + SocketSwClient.mSocketHandler.sendMessage(msg); } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); JSONObject map = received.getMsg().getJSONObject(0); @@ -222,8 +222,8 @@ public class AppContext extends CommonAppContext { Bus.get().post(sudGameSocketImEvent); } //主播页面 - if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.sendMessage(msg); + if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.sendMessage(msg); } } else if (message.getConversationType() == Conversation.ConversationType.PRIVATE) {//私聊信息 diff --git a/common/src/main/java/com/yunbao/common/Constants.java b/common/src/main/java/com/yunbao/common/Constants.java index 4a3e42403..0893cd5ea 100644 --- a/common/src/main/java/com/yunbao/common/Constants.java +++ b/common/src/main/java/com/yunbao/common/Constants.java @@ -267,13 +267,15 @@ public class Constants { public static final String LIVE_PK_RANDOM_START="RankingStartRandomPK"; public static final int LIVE_SDK_KSY = 0;//金山推流 public static final int LIVE_SDK_TX = 1;//腾讯推流 - public static final int LIVE_SDK_SW = 2;//声网 + public static final String LIVE_SDK_IS_SW = "liveSdkIsSw"; //是否是聲網 public static final int LINK_MIC_TYPE_NORMAL = 0;//观众与主播连麦 public static final int LINK_MIC_TYPE_ANCHOR = 1;//主播与主播连麦 + public static final String SOCKET_LIVE_ANCHOR_PK_DIALOG="GuildCompetitionNotice";//公会赛弹窗 + //视频举报获取位置 public static int xIndex = 0; public static int yindex = 0; diff --git a/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java b/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java index aeec0100e..32ab753c1 100644 --- a/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java +++ b/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java @@ -424,7 +424,7 @@ public class WebViewActivity extends AbsActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -440,7 +440,7 @@ public class WebViewActivity extends AbsActivity { } EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal))); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } finish(); } diff --git a/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java b/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java index 140e86000..e9b4d0f06 100644 --- a/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java +++ b/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java @@ -1,5 +1,6 @@ package com.yunbao.common.bean; +import com.alibaba.fastjson.annotation.JSONField; import com.google.gson.annotations.SerializedName; /** @@ -24,6 +25,9 @@ public class AiAutomaticSpeechModel extends BaseModel { //气泡背景 @SerializedName("system_bubble") private String systemBubble; + @SerializedName("icon_en") + @JSONField(name = "icon_en") + private String iconEn; public String getNameColor() { return nameColor; @@ -47,6 +51,16 @@ public class AiAutomaticSpeechModel extends BaseModel { return content; } + + public String getIconEn() { + return iconEn; + } + + public AiAutomaticSpeechModel setIconEn(String iconEn) { + this.iconEn = iconEn; + return this; + } + public AiAutomaticSpeechModel setContent(String content) { this.content = content; return this; diff --git a/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java b/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java index ccb6274c8..2d7d00c3e 100644 --- a/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java +++ b/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java @@ -13,6 +13,16 @@ public class CheckLiveModel extends BaseModel { private String typeMsg; @SerializedName("live_sdk") private String liveSdk; + @SerializedName("is_shengwang") + private String isShengwang; + + public String getIsShengwang() { + return isShengwang; + } + + public void setIsShengwang(String isShengwang) { + this.isShengwang = isShengwang; + } public static CheckLiveModel objectFromData(String str) { diff --git a/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java b/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java index 7ecda8f0f..bc915a619 100644 --- a/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java +++ b/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java @@ -41,6 +41,7 @@ public class EnterRoomNewModel extends BaseModel { private SudGameDateModel sudGameDateModel; @SerializedName("quick_gift_remaining_quantity") private int quickGiftRemainingQuantity;//剩余的小PD礼物数量 + @SerializedName("if_viewing_duration_complete") private int ifViewingDurationComplete;//通过观看时间获取小PD礼物的次数 @SerializedName("sendMoneyLongStatus") diff --git a/common/src/main/java/com/yunbao/common/event/SendBlindGiftEvent.java b/common/src/main/java/com/yunbao/common/event/SendBlindGiftEvent.java index 9c99fab9b..b02143652 100644 --- a/common/src/main/java/com/yunbao/common/event/SendBlindGiftEvent.java +++ b/common/src/main/java/com/yunbao/common/event/SendBlindGiftEvent.java @@ -115,6 +115,35 @@ public class SendBlindGiftEvent extends BaseModel { private String liveGiftNotify; @SerializedName("userNiceName") private String userNiceName; + @SerializedName("special_gift") + private int specialGift; + @SerializedName("special_gift_name") + private String specialGiftName; + @SerializedName("special_gift_name_en") + private String specialGiftNameEn; + public int getSpecialGift() { + return specialGift; + } + + public void setSpecialGift(int specialGift) { + this.specialGift = specialGift; + } + + public String getSpecialGiftName() { + return specialGiftName; + } + + public void setSpecialGiftName(String specialGiftName) { + this.specialGiftName = specialGiftName; + } + + public String getSpecialGiftNameEn() { + return specialGiftNameEn; + } + + public void setSpecialGiftNameEn(String specialGiftNameEn) { + this.specialGiftNameEn = specialGiftNameEn; + } public String getUserNiceName() { return userNiceName; diff --git a/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java b/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java index cc37ea45f..3f3ad5128 100644 --- a/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java +++ b/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java @@ -764,7 +764,7 @@ public class LiveHttpUtil { * @param file 封面图片文件 * @param callback */ - public static void newcreateRoom(String title, int liveClassId, int type, int typeVal, File file, int clarityType, HttpCallback callback) { + public static void newcreateRoom(String title, int liveClassId, int type, int typeVal, File file, int clarityType,boolean isSw, HttpCallback callback) { PostRequest request = HttpClient.getInstance().post("Live.createRoom2", LiveHttpConsts.CREATE_ROOM) .params("title", title) @@ -773,6 +773,7 @@ public class LiveHttpUtil { .params("landscape", "2") .params("class_type", "0") .params("type_val", typeVal) + .params("is_shengwang",isSw?1:0) .params("clarityType", clarityType); if (file != null) { request.params("file", file); @@ -817,6 +818,15 @@ public class LiveHttpUtil { .execute(callback); } + /** + * 获取是否是声网开播 + * @param callback + */ + public static void getIsSw(HttpCallback callback) { + HttpClient.getInstance().get("Tx.setRtcFirm", "Tx.setRtcFirm") + .execute(callback); + } + /** * 腾讯sdk 跟主播连麦时,获取主播的低延时流 */ diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java index dec1d5638..1a7d1b023 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java @@ -15,9 +15,13 @@ import com.bumptech.glide.request.RequestOptions; import com.iflytek.cloud.SpeechConstant; import com.iflytek.cloud.SpeechUtility; import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.R; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.event.RongIMConnectionStatusEvent; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.AppManager; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; import org.greenrobot.eventbus.EventBus; @@ -25,6 +29,7 @@ import io.rong.imkit.GlideKitImageEngine; import io.rong.imkit.IMCenter; import io.rong.imkit.RongIM; import io.rong.imkit.config.RongConfigCenter; +import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Message; @@ -112,12 +117,31 @@ public class RongcloudIMManager { } + public static void connectIM(Context context) { + connectIM(context, new RongIMClient.ConnectCallback() { + @Override + public void onSuccess(String t) { + + } + + @Override + public void onError(RongIMClient.ConnectionErrorCode e) { + + } + + @Override + public void onDatabaseOpened(RongIMClient.DatabaseOpenStatus code) { + + } + }); + } + /** * 连接融云服务器 * * @param context */ - public static void connectIM(Context context) { + public static void connectIM(Context context, RongIMClient.ConnectCallback callback) { MessageIMManager.get(context).addImRongCloudObserver(); MessageIMManager.get(context).getSystemMessages(); IMLoginModel userInfo = IMLoginManager.get(context).getUserInfo(); @@ -129,6 +153,7 @@ public class RongcloudIMManager { RongIM.connect(IMToken, 0, new RongIMClient.ConnectCallback() { @Override public void onSuccess(String s) { + callback.onSuccess(s); //连接成功,如果 onDatabaseOpened() 时没有页面跳转,也可在此时进行跳转。 Log.e(CLASSNAME, "onSuccess:" + s); isReady = true; @@ -138,6 +163,7 @@ public class RongcloudIMManager { @Override public void onError(RongIMClient.ConnectionErrorCode connectionErrorCode) { + callback.onError(connectionErrorCode); if (connectionErrorCode.equals(RongIMClient.ConnectionErrorCode.RC_CONN_TOKEN_EXPIRE)) { //从 APP 服务请求新 token,获取到新 token 后重新 connect() Log.e(CLASSNAME, "onError:(从 APP 服务请求新 token)" + RongIMClient.ConnectionErrorCode.RC_CONN_TOKEN_EXPIRE); @@ -152,6 +178,7 @@ public class RongcloudIMManager { @Override public void onDatabaseOpened(RongIMClient.DatabaseOpenStatus databaseOpenStatus) { + callback.onDatabaseOpened(databaseOpenStatus); if (RongIMClient.DatabaseOpenStatus.DATABASE_OPEN_SUCCESS.equals(databaseOpenStatus)) { //本地数据库打开,跳转到会话列表页面 Log.e(CLASSNAME, "onDatabaseOpened:(本地数据库打开)" + databaseOpenStatus); @@ -225,4 +252,66 @@ public class RongcloudIMManager { } + /** + * 发送消息失败重连次数,超过3就重新登录 + */ + private static int reconnectIndex = 0; + + public static void sendMessage(final Message message, final String pushContent, final String pushData, final IRongCallback.ISendMessageCallback callback) { + + RongIMClient.getInstance().sendMessage(message, pushContent, pushData, new IRongCallback.ISendMessageCallback() { + + @Override + public void onAttached(Message message) { + if (callback != null) { + callback.onAttached(message); + } + } + + @Override + public void onSuccess(Message message) { + reconnectIndex = 0; + if (callback != null) { + callback.onSuccess(message); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + if (reconnectIndex > 2) { + reconnectIndex = 0; + ToastUtil.show(WordUtil.getNewString(R.string.login_invalid)); + EventBus.getDefault().post(new RongIMConnectionStatusEvent()); + return; + } + if (errorCode.code == 33000) { + reconnectIndex++; + connectIM(AppManager.getInstance().getMainActivity(), new RongIMClient.ConnectCallback() { + @Override + public void onSuccess(String t) { + sendMessage(message, pushContent, pushData, callback); + } + + @Override + public void onError(RongIMClient.ConnectionErrorCode e) { + sendMessage(message, pushContent, pushData, callback); + } + + @Override + public void onDatabaseOpened(RongIMClient.DatabaseOpenStatus code) { + if (RongIMClient.DatabaseOpenStatus.DATABASE_OPEN_ERROR.equals(code)) { + sendMessage(message, pushContent, pushData, callback); + } + + } + }); + } else { + if (callback != null) { + callback.onError(message, errorCode); + } + } + } + }); + } + } diff --git a/common/src/main/java/com/yunbao/common/utils/AppManager.java b/common/src/main/java/com/yunbao/common/utils/AppManager.java index 5bda4db57..44891e250 100644 --- a/common/src/main/java/com/yunbao/common/utils/AppManager.java +++ b/common/src/main/java/com/yunbao/common/utils/AppManager.java @@ -34,6 +34,15 @@ public class AppManager { activityStack.add(activity); } + public Activity getMainActivity() { + for (Activity activity : activityStack) { + if (activity.getClass().getSimpleName().contains("MainActivity")) { + return activity; + } + } + return null; + } + /** * 移除Activity */ diff --git a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java index adf6ced3c..d7e7582ca 100644 --- a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java +++ b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java @@ -358,6 +358,7 @@ public class DialogUitl { private boolean mCancelable; private boolean mBackgroundDimEnabled;//显示区域以外是否使用黑色半透明背景 private boolean mInput;//是否是输入框的 + private boolean isShowCancelButton=true; private String mHint; private int mInputType; private int mLength; @@ -454,6 +455,11 @@ public class DialogUitl { return this; } + public Builder setShowCancelButton(boolean showCancelButton) { + isShowCancelButton = showCancelButton; + return this; + } + public Dialog build() { final Dialog dialog = new Dialog(mContext, mBackgroundDimEnabled ? R.style.dialog : R.style.dialog2); if (mView != 0) { @@ -498,6 +504,9 @@ public class DialogUitl { if (!TextUtils.isEmpty(mCancelString)) { btnCancel.setText(mCancelString); } + if(!isShowCancelButton){ + btnCancel.setVisibility(View.GONE); + } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java b/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java index b4ca839b5..e4c61f85c 100644 --- a/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java @@ -285,7 +285,7 @@ public class JavascriptInterfaceUtils { liveBean.setGiftId(giftId); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (!"".endsWith(Constants.mStream)) { @@ -295,7 +295,7 @@ public class JavascriptInterfaceUtils { } EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal)).setLiveEnd(true)); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } androidGoBack(); } diff --git a/common/src/main/java/com/yunbao/common/utils/LiveRoomCheckLivePresenter.java b/common/src/main/java/com/yunbao/common/utils/LiveRoomCheckLivePresenter.java index 25796bdab..6c7d2d6f3 100644 --- a/common/src/main/java/com/yunbao/common/utils/LiveRoomCheckLivePresenter.java +++ b/common/src/main/java/com/yunbao/common/utils/LiveRoomCheckLivePresenter.java @@ -33,6 +33,7 @@ public class LiveRoomCheckLivePresenter { private LiveBean mLiveBean; private ActionListener mActionListener; private int mLiveSdk; + private boolean isSw; //搜索页面不提示密码 public static boolean isRoom = false; @@ -50,7 +51,7 @@ public class LiveRoomCheckLivePresenter { @Override public void forwardNormalRoom(CheckLiveModel model) { if (actionListener != null) { - actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk()); + actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk(),model.getIsShengwang().equals("1")); } } @@ -74,7 +75,7 @@ public class LiveRoomCheckLivePresenter { if (model.getTypeMsg().equalsIgnoreCase(password)) { dialog.dismiss(); if (actionListener != null) { - actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk()); + actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk(),model.getIsShengwang().equals("1")); } } else { ToastUtil.show(mContext.getString(R.string.live_password_error)); @@ -93,7 +94,7 @@ public class LiveRoomCheckLivePresenter { public void onSuccess(int code, String msg, String[] info) { if (code == 0) { if (actionListener != null) { - actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk()); + actionListener.onLiveRoomChanged(liveUid, stream, model.getType(), model.getTypeVal(), model.getLiveSdk(),model.getIsShengwang().equals("1")); } } else { ToastUtil.show(msg); @@ -139,6 +140,7 @@ public class LiveRoomCheckLivePresenter { mLiveTypeMsg = obj.getString("type_msg"); if (CommonAppConfig.LIVE_SDK_CHANGED) { mLiveSdk = obj.getIntValue("live_sdk"); + isSw= obj.getString("is_shengwang").equals("1"); } else { mLiveSdk = CommonAppConfig.LIVE_SDK_USED; } @@ -263,17 +265,16 @@ public class LiveRoomCheckLivePresenter { */ private void enterLiveRoom() { if (mActionListener != null) { - mActionListener.onLiveRoomChanged(mLiveBean, mLiveType, mLiveTypeVal, mLiveSdk); + mActionListener.onLiveRoomChanged(mLiveBean, mLiveType, mLiveTypeVal, mLiveSdk,isSw); } } - public interface ActionListener { - void onLiveRoomChanged(LiveBean liveBean, int liveType, int liveTypeVal, int liveSdk); + void onLiveRoomChanged(LiveBean liveBean, int liveType, int liveTypeVal, int liveSdk,boolean isSw); } public interface NewActionListener { - void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk); + void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw); void onCheckError(String contextError); } diff --git a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java index a30f5f676..cc449286f 100644 --- a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java @@ -46,23 +46,25 @@ public class RouteUtil { public static final String PATH_RED_PACKET_LIST = "/main/RedPacketListActivity"; public static final String PATH_RED_PACKET_INFO = "/main/RedPacketInfoActivity"; public static final String PATH_RED_PACKET_USER = "/main/RedPacketUsersActivity"; - public static final String PATH_SELECT_AVATAR="/main/UserAvatarSelectActivity"; - public static final String PATH_BattlePassActivity="/main/BattlePassActivity"; - public static final String PATH_SudGameActivity="/live/SudGameActivity"; + public static final String PATH_SELECT_AVATAR = "/main/UserAvatarSelectActivity"; + public static final String PATH_BattlePassActivity = "/main/BattlePassActivity"; + public static final String PATH_SudGameActivity = "/live/SudGameActivity"; - public static final String PATH_COMMUNITY_Activity="/main/MainHomeCommunityActivity"; + public static final String PATH_COMMUNITY_Activity = "/main/MainHomeCommunityActivity"; public static void forwardCommunityActivity() { ARouter.getInstance().build(PATH_COMMUNITY_Activity) .navigation(); } + public static void forwardFansActivity(String uid) { ARouter.getInstance().build(PATH_FANSACTIVITY) .withString(Constants.TO_UID, uid) .navigation(); } - public static void forwardSudGameActivity(String CreateSudRoom,boolean isAn,boolean isHome) { + + public static void forwardSudGameActivity(String CreateSudRoom, boolean isAn, boolean isHome) { ARouter.getInstance().build(PATH_SudGameActivity) .withString("CreateSudRoom", CreateSudRoom) .withBoolean("CreateIsAn", isAn) @@ -218,7 +220,7 @@ public class RouteUtil { * 跳转到充值页面 */ public static void forwardMyCoin(Context context) { - String url = CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=zhifu&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken()+ "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + String url = CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=zhifu&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); ARouter.getInstance().build(PATH_COIN).withString("url", url).navigation(); } @@ -250,7 +252,7 @@ public class RouteUtil { /** * 打开直播页面 */ - public static void forwardLiveAudienceActivity(LiveBean mLiveBean, int mLiveType, int mLiveSDK, int mLiveTypeVal) { + public static void forwardLiveAudienceActivity(LiveBean mLiveBean, int mLiveType, int mLiveSDK, int mLiveTypeVal, boolean isSw) { if (MicStatusManager.getInstance().isMic(mLiveBean.getUid())) { MicStatusManager.getInstance().showDownMicDialog(CommonAppContext.activityWeakReference.get()); return; @@ -260,7 +262,9 @@ public class RouteUtil { .withParcelable(Constants.LIVE_BEAN, mLiveBean) .withInt(Constants.LIVE_TYPE, mLiveType) .withInt(Constants.LIVE_SDK, mLiveSDK) + .withBoolean(Constants.LIVE_SDK_IS_SW, isSw) .withInt(Constants.LIVE_TYPE_VAL, mLiveTypeVal); + if (mLiveBean.getParams() != null) { for (String key : mLiveBean.getParams().keySet()) { postcard.withString(key, mLiveBean.getParams().get(key)); @@ -269,14 +273,14 @@ public class RouteUtil { postcard.navigation(); } - public static void forwardGiftWallActivity(String mStream, String mAnchorName, String mLiveUid, String mAvatarUrl, int isAttention,boolean isLive) { + public static void forwardGiftWallActivity(String mStream, String mAnchorName, String mLiveUid, String mAvatarUrl, int isAttention, boolean isLive) { ARouter.getInstance().build(PATH_GIFT_WALL) .withString(Constants.LIVE_UID, mLiveUid) .withString(Constants.STREAM, mStream) .withString("mAnchorName", mAnchorName) .withString("mAvatarUrl", mAvatarUrl) .withInt("isAttention", isAttention) - .withBoolean("isLive",isLive) + .withBoolean("isLive", isLive) .navigation(); } @@ -354,7 +358,7 @@ public class RouteUtil { /** * 战令 */ - public static void forwardBattlePass(){ + public static void forwardBattlePass() { ARouter.getInstance().build(PATH_BattlePassActivity) .navigation(); } diff --git a/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java b/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java index 7c390f6d2..0eff03c05 100644 --- a/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java +++ b/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java @@ -131,8 +131,8 @@ public class SudGameListViewHolder extends RecyclerView.ViewHolder { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(itemView.getContext(), liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); new Handler().postDelayed(new Runnable() { @Override public void run() { diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java index e09f22338..7a336a381 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java @@ -336,7 +336,7 @@ public class LiveFloatView implements Function1 { public void onSuccess(int code, String msg, String[] info) { if (code == 0) { - RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal); + RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal,mLiveSDK == Constants.LIVE_SDK_SW); } else { //判断是否有直播悬浮窗,有直接关闭 diff --git a/live/src/main/AndroidManifest.xml b/live/src/main/AndroidManifest.xml index 1af89a691..2f80c2ebd 100644 --- a/live/src/main/AndroidManifest.xml +++ b/live/src/main/AndroidManifest.xml @@ -97,10 +97,15 @@ + + + diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index 51dd79c30..0cf2630cc 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -83,10 +83,12 @@ import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; import com.yunbao.live.presenter.LiveLinkMicPkPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; +import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; import com.yunbao.live.socket.SocketClient; import com.yunbao.live.socket.SocketMessageListener; import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; +import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.utils.LoadDian9TuUtil; import com.yunbao.live.views.AbsLiveViewHolder; import com.yunbao.live.views.LiveAddImpressViewHolder; @@ -125,9 +127,13 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL protected LiveEndViewHolder mLiveEndViewHolder; protected LiveLinkMicPresenter mLiveLinkMicPresenter;//观众与主播连麦逻辑 protected LiveLinkMicAnchorPresenter mLiveLinkMicAnchorPresenter;//主播与主播连麦逻辑 - protected LiveLinkMicPkPresenter mLiveLinkMicPkPresenter;//主播与主播PK逻辑 - public static LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter;//主播与主播PK逻辑 + protected LiveLinkMicPkPresenter mLiveLinkMicPkPresenter;//主播与主播PK逻辑 腾讯 + public static LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter;//主播与主播PK逻辑 融云 + + public static LiveSwLinkMicPkPresenter mLiveSwLinkMicPkPresenter;//主播与主播PK逻辑 声网 public SocketClient mSocketClient; + public SocketSwClient mSocketSwClient; + public SocketRyClient mSocketRyClient; protected LiveBean mLiveBean; @@ -160,6 +166,8 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL protected List mAudienceList = new ArrayList<>(); protected LiveMicAnchorDialogFragment.OnMicListener micListener = null; + public boolean isSw; + @Override protected void main() { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); @@ -393,18 +401,29 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); } - + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); + } } @Override public void onEndPk(long leftUid, long rightUid, long left, long right, LivePKUserListBean bean) { if (mLiveRyLinkMicPkPresenter != null) { + L.eSw("onEndPk 结束PK mLiveRyLinkMicPkPresenter"); if (mLiveUid.equals(leftUid + "")) { mLiveRyLinkMicPkPresenter.onPkProgressEnd(left, right, bean); } else { mLiveRyLinkMicPkPresenter.onPkProgressEnd(right, left, bean); } } + if (mLiveSwLinkMicPkPresenter != null) { + L.eSw("onEndPk 结束PK mLiveSwLinkMicPkPresenter"); + if (mLiveUid.equals(leftUid + "")) { + mLiveSwLinkMicPkPresenter.onPkProgressEnd(left, right, bean); + } else { + mLiveSwLinkMicPkPresenter.onPkProgressEnd(right, left, bean); + } + } } /** @@ -669,6 +688,10 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onLinkMicPkClose(1); } + + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkClose(1); + } // } @@ -728,12 +751,20 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL @Override public void onLinkMicPkStart(final String pkUid, final String pkhead, final String pkname, String isLadders) { if (mContext instanceof LiveAudienceActivity) return; - L.eSw( "pkUid = " + pkUid + ", pkhead = " + pkhead + ", pkname = " + pkname + ", isLadders = " + isLadders); - if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); - pr = new pkRunnable(pkUid, pkhead, pkname, isLadders); - mHandler.postDelayed(pr, 4000);//3秒后执行Runnable中的run方法 + L.eSw("pkUid = " + pkUid + ", pkhead = " + pkhead + ", pkname = " + pkname + ", isLadders = " + isLadders); + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); + pr = new pkRunnable(pkUid, pkhead, pkname, isLadders); + mHandler.postDelayed(pr, 4000);//3秒后执行Runnable中的run方法 + } + } else { + if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { + mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); + pr = new pkRunnable(pkUid, pkhead, pkname, isLadders); + mHandler.postDelayed(pr, 4000);//3秒后执行Runnable中的run方法 + } } } @@ -774,6 +805,8 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL mLiveRyLinkMicPkPresenter.onLinkMicPkClose(i); } else if (mLiveLinkMicPkPresenter != null) { mLiveLinkMicPkPresenter.onLinkMicPkClose(i); + } else if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkClose(i); } } @@ -812,6 +845,9 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL } else if (mLiveLinkMicPkPresenter != null) { mLiveLinkMicPkPresenter.onLinkMicPkEnd(winUid); mLiveRoomViewHolder.setDelOtherInfo(); + } else if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkEnd(winUid); + mLiveRoomViewHolder.setDelOtherInfo(); } } @@ -1336,32 +1372,31 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL if (outRankHideFirst) { //获取隐身的用户的ID - LiveNetManager.get(mContext) - .getNobleRankHideUserList(new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(NobleRankHideUserListModel data) { - outRankHide = data.getInRankHide(); - LiveUserMoreDialogFragment fragment = new LiveUserMoreDialogFragment(); - fragment.setLiveGuardInfo(mLiveGuardInfo); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.STREAM, mStream); - bundle.putString("By", i + ""); - bundle.putBoolean("only", isOnly); - bundle.putBoolean("noble", noble); - bundle.putString("outRankHide", GsonUtils.toJson(outRankHide)); - bundle.putBoolean("showBuyView", !showBuyView); - fragment.setArguments(bundle); - fragment.show(getSupportFragmentManager(), "LiveUserMoreDialogFragment"); - outRankHideFirst = false; - } + LiveNetManager.get(mContext).getNobleRankHideUserList(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(NobleRankHideUserListModel data) { + outRankHide = data.getInRankHide(); + LiveUserMoreDialogFragment fragment = new LiveUserMoreDialogFragment(); + fragment.setLiveGuardInfo(mLiveGuardInfo); + Bundle bundle = new Bundle(); + bundle.putString(Constants.LIVE_UID, mLiveUid); + bundle.putString(Constants.STREAM, mStream); + bundle.putString("By", i + ""); + bundle.putBoolean("only", isOnly); + bundle.putBoolean("noble", noble); + bundle.putString("outRankHide", GsonUtils.toJson(outRankHide)); + bundle.putBoolean("showBuyView", !showBuyView); + fragment.setArguments(bundle); + fragment.show(getSupportFragmentManager(), "LiveUserMoreDialogFragment"); + outRankHideFirst = false; + } - @Override - public void onError(String error) { - Log.e("LiveUserMoreDialog", error); - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); + @Override + public void onError(String error) { + Log.e("LiveUserMoreDialog", error); + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); } else { LiveUserMoreDialogFragment fragment = new LiveUserMoreDialogFragment(); fragment.setLiveGuardInfo(mLiveGuardInfo); @@ -1672,27 +1707,26 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL micListener = fragment.getMicListener(); fragment.setMicQueueList(mMicQueueList); fragment.setAudienceList(mAudienceList); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveMicAnchorDialogFragment"); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveMicAnchorDialogFragment"); } /** * 获取连麦列表 */ public void showMicList(String uid, LiveRoomViewHolder mLiveRoomViewHolder) { - LiveNetManager.get(mContext) - .getDRMicUserList(uid, new com.yunbao.common.http.base.HttpCallback>() { - @Override - public void onSuccess(List data) { - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.updataMicList(data); - } - } + LiveNetManager.get(mContext).getDRMicUserList(uid, new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List data) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.updataMicList(data); + } + } - @Override - public void onError(String error) { - System.out.println("live.getDrLm error = " + error); - } - }); + @Override + public void onError(String error) { + System.out.println("live.getDrLm error = " + error); + } + }); } @Override diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java index 282a8dac0..e8b571e2c 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java @@ -282,7 +282,7 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"); - ZhuangBanActivity.forward(mContext, url, false,0); + ZhuangBanActivity.forward(mContext, url, false, 0); break; case Constants.LIVE_FUNC_LINK_MIC://连麦 openLinkMicAnchorWindow(); @@ -632,6 +632,9 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic // } else { // SocketRyChatUtil.closeLive(mLiveUid, mSocketRyClient); //断开socket + if (mSocketSwClient != null) { + mSocketSwClient.disConnect(); + } if (mSocketRyClient != null) { mSocketRyClient.disConnect(); } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 6f035614f..5b27c1498 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -31,7 +31,6 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.GsonUtils; import com.facebook.appevents.AppEventsLogger; -import com.google.gson.Gson; import com.lxj.xpopup.XPopup; import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.enums.PopupPosition; @@ -188,6 +187,7 @@ public class LiveAudienceActivity extends LiveActivity { private boolean liveIndex = true; private boolean isPk = false; private boolean isRadPacetModle = false; + public boolean isSw; @Override public T findViewById(@IdRes int id) { @@ -209,6 +209,7 @@ public class LiveAudienceActivity extends LiveActivity { mProcessResultUtil = new ProcessResultUtil(this); Intent intent = getIntent(); mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); + isSw = intent.getBooleanExtra(Constants.LIVE_SDK_IS_SW, false); L.e(TAG, "直播sdk----->" + (mLiveSDK == Constants.LIVE_SDK_KSY ? "金山云" : "腾讯云")); mLiveType = intent.getIntExtra(Constants.LIVE_TYPE, Constants.LIVE_TYPE_NORMAL); mLiveTypeVal = intent.getIntExtra(Constants.LIVE_TYPE_VAL, 0); @@ -300,38 +301,36 @@ public class LiveAudienceActivity extends LiveActivity { Log.e(TAG, "mCurrentItem:" + mCurrentItem); if (mCurrentItem == itemModelList.size() - 1) { if (isRadPacetModle) {//从红包专区进去的走红包专区列表 - MainNetManager.get(mContext) - .getRedPacket(new com.yunbao.common.http.base.HttpCallback>() { - @Override - public void onSuccess(List data) { - if (TextUtils.equals(data.get(0).getUid(), mLiveBean.getUid())) { - data.remove(0); - } - itemModelList.addAll(data); - mPagerAdapter.notifyDataSetChanged(); - } + MainNetManager.get(mContext).getRedPacket(new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List data) { + if (TextUtils.equals(data.get(0).getUid(), mLiveBean.getUid())) { + data.remove(0); + } + itemModelList.addAll(data); + mPagerAdapter.notifyDataSetChanged(); + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); } else { - MainNetManager.get(mContext) - .anchorRecommendType("30", new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(AnchorRecommendModel data) { - if (TextUtils.equals(data.getList().get(0).getUid(), mLiveBean.getUid())) { - data.getList().remove(0); - } - itemModelList.addAll(data.getList()); - mPagerAdapter.notifyDataSetChanged(); - } + MainNetManager.get(mContext).anchorRecommendType("30", new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(AnchorRecommendModel data) { + if (TextUtils.equals(data.getList().get(0).getUid(), mLiveBean.getUid())) { + data.getList().remove(0); + } + itemModelList.addAll(data.getList()); + mPagerAdapter.notifyDataSetChanged(); + } - @Override - public void onError(String error) { - } - }); + @Override + public void onError(String error) { + } + }); } } } @@ -404,7 +403,7 @@ public class LiveAudienceActivity extends LiveActivity { mHandler.removeCallbacks(pr); pr = null; } - manager.onAdd(mLiveBean, mLiveType, mLiveTypeVal, mLiveSDK); + manager.onAdd(mLiveBean, mLiveType, mLiveTypeVal, mLiveSDK, isSw); //加载完页面后再后台静默下载礼物svga downloadAllGift(); @@ -413,7 +412,7 @@ public class LiveAudienceActivity extends LiveActivity { } else { new LiveRoomCheckLivePresenter(mContext, data.getUid(), data.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw) { liveIndex = false; try { mLiveSDK = Integer.parseInt(liveSdk); @@ -441,7 +440,7 @@ public class LiveAudienceActivity extends LiveActivity { } mViewGroup.addView(manager.getRootView()); - manager.onAdd(mLiveBean, liveType, mLiveTypeVal, mLiveSDK); + manager.onAdd(mLiveBean, liveType, mLiveTypeVal, mLiveSDK, isSw); //加载完页面后再后台静默下载礼物svga downloadAllGift(); over(); @@ -483,12 +482,7 @@ public class LiveAudienceActivity extends LiveActivity { if (TextUtils.isEmpty(mLiveUid) || TextUtils.isEmpty(mStream)) { return; } - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) - .setmLiveUid(mLiveUid) - .setmStream(mStream) - .setPk(isPk) - .setLiveGuardInfo(mLiveGuardInfo)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP).setmLiveUid(mLiveUid).setmStream(mStream).setPk(isPk).setLiveGuardInfo(mLiveGuardInfo)); }); } @@ -496,13 +490,7 @@ public class LiveAudienceActivity extends LiveActivity { if (TextUtils.isEmpty(mLiveUid) || TextUtils.isEmpty(mStream)) { return; } - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) - .setmLiveUid(mLiveUid) - .setmStream(mStream) - .setPk(isPk) - .setLiveGuardInfo(mLiveGuardInfo) - .setmWishGiftId(giftId)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP).setmLiveUid(mLiveUid).setmStream(mStream).setPk(isPk).setLiveGuardInfo(mLiveGuardInfo).setmWishGiftId(giftId)); } public void openGiftWindow(String giftId, String for_by) { @@ -511,14 +499,7 @@ public class LiveAudienceActivity extends LiveActivity { } new Handler(Looper.getMainLooper()).post(() -> { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) - .setmLiveUid(mLiveUid) - .setmStream(mStream) - .setPk(isPk) - .setLiveGuardInfo(mLiveGuardInfo) - .setmWishGiftId(giftId) - .setUname("1"));//setUname==by + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP).setmLiveUid(mLiveUid).setmStream(mStream).setPk(isPk).setLiveGuardInfo(mLiveGuardInfo).setmWishGiftId(giftId).setUname("1"));//setUname==by }); } @@ -573,7 +554,7 @@ public class LiveAudienceActivity extends LiveActivity { @Override public void onLinkDRMicPkApplyOk(UserBean u) { - L.eSw("onLinkDRMicPkApplyOk:"+u.getId()); + L.eSw("onLinkDRMicPkApplyOk:" + u.getId()); //多人PK 连麦 //manager.getmLivePlayViewHolder().setDrMicInfo(u); } @@ -591,39 +572,33 @@ public class LiveAudienceActivity extends LiveActivity { @Override public void onBackPressed() { if (manager != null && manager.getsudGameMin()) { - new XPopup.Builder(mContext) - .asCustom(new HintCustomPopup(mContext, - mContext.getString(com.yunbao.common.R.string.dialog_tip), - mContext.getString(com.yunbao.common.R.string.the_live_room)) - .setLiveOpenOk(mContext.getString(com.yunbao.common.R.string.confirm)) - .setLiveOpenCancel(mContext.getString(com.yunbao.common.R.string.cancel)) - .setCallBack(new HintCustomPopup.HintCustomCallBack() { - @Override - public void onSure() { - MobclickAgent.onEvent(mContext, "live_room_close", "退出直播间"); - OpenAdManager.getInstance().dismiss(); - try { - manager.onBackPressed(); - if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { - manager.micIngTypeOne(mLiveBean, mLiveType, mLiveTypeVal); - } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { - manager.micIngTypeTwo(mLiveBean, mLiveType, mLiveTypeVal); - } else { - manager.onRemove(true); + new XPopup.Builder(mContext).asCustom(new HintCustomPopup(mContext, mContext.getString(com.yunbao.common.R.string.dialog_tip), mContext.getString(com.yunbao.common.R.string.the_live_room)).setLiveOpenOk(mContext.getString(com.yunbao.common.R.string.confirm)).setLiveOpenCancel(mContext.getString(com.yunbao.common.R.string.cancel)).setCallBack(new HintCustomPopup.HintCustomCallBack() { + @Override + public void onSure() { + MobclickAgent.onEvent(mContext, "live_room_close", "退出直播间"); + OpenAdManager.getInstance().dismiss(); + try { + manager.onBackPressed(); + if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { + manager.micIngTypeOne(mLiveBean, mLiveType, mLiveTypeVal); + } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { + manager.micIngTypeTwo(mLiveBean, mLiveType, mLiveTypeVal); + } else { + manager.onRemove(true); - } - Bus.get().post(new HideShowEvent().setClose(true)); - } catch (Exception e) { - e.printStackTrace(); - } - } + } + Bus.get().post(new HideShowEvent().setClose(true)); + } catch (Exception e) { + e.printStackTrace(); + } + } - @Override - public void onCancel() { + @Override + public void onCancel() { - } - })).show(); + } + })).show(); } else { MobclickAgent.onEvent(mContext, "live_room_close", "退出直播间"); OpenAdManager.getInstance().dismiss(); @@ -646,8 +621,7 @@ public class LiveAudienceActivity extends LiveActivity { } public void end() { - if (manager != null) - manager.end(); + if (manager != null) manager.end(); } /** @@ -702,24 +676,21 @@ public class LiveAudienceActivity extends LiveActivity { * 计时收费更新主播映票数 */ public void roomChargeUpdateVotes() { - if (manager != null) - manager.sendUpdateVotesMessage(); + if (manager != null) manager.sendUpdateVotesMessage(); } /** * 暂停播放 */ public void pausePlay() { - if (manager != null) - manager.pausePlay(); + if (manager != null) manager.pausePlay(); } /** * 恢复播放 */ public void resumePlay() { - if (manager != null) - manager.resumePlay(); + if (manager != null) manager.resumePlay(); } public CountDownTimer getCountDownTimer() { @@ -730,8 +701,7 @@ public class LiveAudienceActivity extends LiveActivity { * 充值成功 */ public void onChargeSuccess() { - if (manager != null) - manager.onChargeSuccess(); + if (manager != null) manager.onChargeSuccess(); } public void setCoinNotEnough(boolean coinNotEnough) { @@ -835,12 +805,11 @@ public class LiveAudienceActivity extends LiveActivity { mStream = liveBean.getStream(); mAncherName = liveBean.getUserNiceName(); mAncherIcon = liveBean.getAvatar(); - manager.onAdd(liveBean, mLiveType, mLiveTypeVal, mLiveSDK); + //暂时 true + manager.onAdd(liveBean, mLiveType, mLiveTypeVal, mLiveSDK, isSw); } } } - - } @Override @@ -855,14 +824,12 @@ public class LiveAudienceActivity extends LiveActivity { if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.setFansGroup("0"); } - is_fans = "2"; } } GiftCacheUtil.getInstance().restart(); if (manager.isEnterRoom()) { - new Handler(Looper.getMainLooper()).postDelayed(() -> OpenAdManager.getInstance().show(OpenAdManager.TYPE_LIVE, - LiveGuardInfo.isGuard(mLiveGuardInfo)), 400); + new Handler(Looper.getMainLooper()).postDelayed(() -> OpenAdManager.getInstance().show(OpenAdManager.TYPE_LIVE, LiveGuardInfo.isGuard(mLiveGuardInfo)), 400); } } @@ -874,8 +841,7 @@ public class LiveAudienceActivity extends LiveActivity { private void adjustFullScreen(Configuration config) { final WindowInsetsControllerCompat insetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView()); - if (insetsController == null) - return; + if (insetsController == null) return; if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { insetsController.hide(WindowInsetsCompat.Type.systemBars()); } else { @@ -949,7 +915,7 @@ public class LiveAudienceActivity extends LiveActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw) { if (liveBean == null) { return; } @@ -974,18 +940,15 @@ public class LiveAudienceActivity extends LiveActivity { public void informationTransfer(CustomDrawerPopupEvent event) { //跳转贵族 if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.noble))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.NOBLE)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.NOBLE)); //跳转守护 } else if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.guard_guard))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GUARD)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GUARD)); manager.onGuardRed(); //跳转粉丝团 } else if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.fan_club))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.FAN_CLUB)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.FAN_CLUB)); } } @@ -1011,69 +974,53 @@ public class LiveAudienceActivity extends LiveActivity { @Override public void evenTheWheat() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI)); } @Override public void effectsSetting() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.EFFECTS_SETTINGS)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.EFFECTS_SETTINGS)); } @Override public void slideSetting() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SLIDE_SETTINGS)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SLIDE_SETTINGS)); } @Override public void floatSetting() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.FLOAT_SETTING)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.FLOAT_SETTING)); } @Override public void systemNotice() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.NOTICE)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.NOTICE)); } @Override public void changeVideo() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO)); } @Override public void online() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.ONLINE)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.ONLINE)); } @Override public void reportLayout() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.REPORT)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.REPORT)); } @Override public void share() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_SHARE)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.LIVE_SHARE)); } @Override public void changeFontSize() { - Bus.get().post(new LiveAudienceEvent() - .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.FONT_SIZE)); + Bus.get().post(new LiveAudienceEvent().setBean(mLiveBean).setType(LiveAudienceEvent.LiveAudienceType.FONT_SIZE)); } @Override @@ -1082,23 +1029,17 @@ public class LiveAudienceActivity extends LiveActivity { ToastUtil.show(WordUtil.isNewZh() ? "您已在游戏房间中" : "You are already in the game room"); } else { //直播间来的 - new XPopup.Builder(mContext) - .enableDrag(false) + new XPopup.Builder(mContext).enableDrag(false) // .dismissOnTouchOutside(false) // .dismissOnBackPressed(false) - .moveUpToKeyboard(false) - .asCustom(new SudGameListPopup(mContext, interactionID, child, mLiveUid)) + .moveUpToKeyboard(false).asCustom(new SudGameListPopup(mContext, interactionID, child, mLiveUid)) .show(); } } }); - new XPopup.Builder(mContext) - .hasShadowBg(false) - .isDestroyOnDismiss(true) - .isLightStatusBar(false) - .popupPosition(PopupPosition.Right)//右边 + new XPopup.Builder(mContext).hasShadowBg(false).isDestroyOnDismiss(true).isLightStatusBar(false).popupPosition(PopupPosition.Right)//右边 .hasStatusBarShadow(true) //启用状态栏阴影 .setPopupCallback(new XPopupCallback() { @Override @@ -1144,9 +1085,7 @@ public class LiveAudienceActivity extends LiveActivity { public void onClickOutside(BasePopupView popupView) { } - }) - .asCustom(customDrawerPopupView) - .show(); + }).asCustom(customDrawerPopupView).show(); } break; @@ -1196,15 +1135,9 @@ public class LiveAudienceActivity extends LiveActivity { //粉絲團粉絲團 //不是粉絲 if (LiveAudienceActivity.is_fans == null || "2".equals(LiveAudienceActivity.is_fans)) { - bundle.putString(Constants.URL, - (CommonAppConfig.HOST + "/h5/live/joinFansClub.html" + - "?uid=" + userInfo.getId() + - "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid) + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0)); + bundle.putString(Constants.URL, (CommonAppConfig.HOST + "/h5/live/joinFansClub.html" + "?uid=" + userInfo.getId() + "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid) + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0)); } else { - bundle.putString(Constants.URL, - (CommonAppConfig.HOST + "/h5/live/fansClub.html" + - "?uid=" + userInfo.getId() + - "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid) + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0)); + bundle.putString(Constants.URL, (CommonAppConfig.HOST + "/h5/live/fansClub.html" + "?uid=" + userInfo.getId() + "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid) + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0)); } bundle.putString("liveUid", mLiveUid); bundle.putString("anchorName", mAncherName); @@ -1214,25 +1147,18 @@ public class LiveAudienceActivity extends LiveActivity { break; case GUARD: if (event.getObject() == null) { - openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity); + openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); } else { openNewBuyGuardWindow(true); } break; case LIVE_WKS://周星榜 - String weeklyStarUrl = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" - + userInfo.getId() + - "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + String weeklyStarUrl = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" + userInfo.getId() + "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); ZhuangBanActivity.forward(mContext, weeklyStarUrl, false, 1); break; case NOBLE: Constants.isTitle = true; - String nobleUrl = CommonAppConfig.HOST + "/h5/Noble/index.html?nickname=" + userInfo.getUserNicename() - + "&usernobId=" + userInfo.getNobleId() - + "&token=" + userInfo.getToken() - + "&anchorUid=" + mLiveBean.getUid() - + "&ancherName=" + mLiveBean.getUserNiceName() - + "&uid=" + userInfo.getId() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + String nobleUrl = CommonAppConfig.HOST + "/h5/Noble/index.html?nickname=" + userInfo.getUserNicename() + "&usernobId=" + userInfo.getNobleId() + "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveBean.getUid() + "&ancherName=" + mLiveBean.getUserNiceName() + "&uid=" + userInfo.getId() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); ZhuangBanActivity.forward(mContext, nobleUrl, false, 1); break; case LIAN_MAI: @@ -1246,25 +1172,23 @@ public class LiveAudienceActivity extends LiveActivity { manager.micIngTypeTwo(event.getBean(), event.getLiveType(), event.getLiveTypeVal()); } else { //获取房间连麦状态 - HttpClient.getInstance().get("live.getDrLm", "live.getDrLm") - .params("uid", mLiveUid, true) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - LiveMicUserDialogFragment fragment = new LiveMicUserDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.STREAM, mStream); - bundle.putString("By", "1"); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveUserMoreDialogFragment"); - LiveMicUserDialogFragment.activity = ((LiveAudienceActivity) mContext); - } else { - ToastUtil.show(mContext.getString(R.string.no_mic_opn)); - } - } - }); + HttpClient.getInstance().get("live.getDrLm", "live.getDrLm").params("uid", mLiveUid, true).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + LiveMicUserDialogFragment fragment = new LiveMicUserDialogFragment(); + Bundle bundle = new Bundle(); + bundle.putString(Constants.LIVE_UID, mLiveUid); + bundle.putString(Constants.STREAM, mStream); + bundle.putString("By", "1"); + fragment.setArguments(bundle); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveUserMoreDialogFragment"); + LiveMicUserDialogFragment.activity = ((LiveAudienceActivity) mContext); + } else { + ToastUtil.show(mContext.getString(R.string.no_mic_opn)); + } + } + }); } break; case EFFECTS_SETTINGS: @@ -1285,31 +1209,20 @@ public class LiveAudienceActivity extends LiveActivity { } break; case OPEN_PARAMETERS: - mDanmuPrice = TextUtils.equals(event.getParametersModel().getmDanmuPrice(), mDanmuPrice) ? - mDanmuPrice : event.getParametersModel().getmDanmuPrice(); - mSocketUserType = TextUtils.equals(String.valueOf(mSocketUserType), String.valueOf(event.getParametersModel().getmSocketUserType())) ? - mSocketUserType : event.getParametersModel().getmSocketUserType(); - mChatLevel = TextUtils.equals(String.valueOf(mChatLevel), String.valueOf(event.getParametersModel().getmChatLevel())) ? - mChatLevel : event.getParametersModel().getmChatLevel(); - mDanMuLevel = TextUtils.equals(String.valueOf(mDanMuLevel), String.valueOf(event.getParametersModel().getmDanMuLevel())) ? - mDanMuLevel : event.getParametersModel().getmDanMuLevel(); - mLiveType = TextUtils.equals(String.valueOf(mLiveType), String.valueOf(event.getParametersModel().getmLiveType())) ? - mLiveType : event.getParametersModel().getmLiveType(); - mLiveTypeVal = TextUtils.equals(String.valueOf(mLiveTypeVal), String.valueOf(event.getParametersModel().getmLiveTypeVal())) ? - mLiveTypeVal : event.getParametersModel().getmLiveTypeVal(); - mLiveGuardInfo = event.getParametersModel().getmLiveGuardInfo() == null ? - mLiveGuardInfo : event.getParametersModel().getmLiveGuardInfo(); - liveBg = TextUtils.equals(String.valueOf(liveBg), String.valueOf(event.getParametersModel().getLiveBg())) ? - liveBg : event.getParametersModel().getLiveBg(); - is_fans = TextUtils.equals(String.valueOf(is_fans), String.valueOf(event.getParametersModel().getIs_fans())) ? - is_fans : event.getParametersModel().getIs_fans(); - fansNum = TextUtils.equals(String.valueOf(fansNum), String.valueOf(event.getParametersModel().getFansNum())) ? - fansNum : event.getParametersModel().getFansNum(); + mDanmuPrice = TextUtils.equals(event.getParametersModel().getmDanmuPrice(), mDanmuPrice) ? mDanmuPrice : event.getParametersModel().getmDanmuPrice(); + mSocketUserType = TextUtils.equals(String.valueOf(mSocketUserType), String.valueOf(event.getParametersModel().getmSocketUserType())) ? mSocketUserType : event.getParametersModel().getmSocketUserType(); + mChatLevel = TextUtils.equals(String.valueOf(mChatLevel), String.valueOf(event.getParametersModel().getmChatLevel())) ? mChatLevel : event.getParametersModel().getmChatLevel(); + mDanMuLevel = TextUtils.equals(String.valueOf(mDanMuLevel), String.valueOf(event.getParametersModel().getmDanMuLevel())) ? mDanMuLevel : event.getParametersModel().getmDanMuLevel(); + mLiveType = TextUtils.equals(String.valueOf(mLiveType), String.valueOf(event.getParametersModel().getmLiveType())) ? mLiveType : event.getParametersModel().getmLiveType(); + mLiveTypeVal = TextUtils.equals(String.valueOf(mLiveTypeVal), String.valueOf(event.getParametersModel().getmLiveTypeVal())) ? mLiveTypeVal : event.getParametersModel().getmLiveTypeVal(); + mLiveGuardInfo = event.getParametersModel().getmLiveGuardInfo() == null ? mLiveGuardInfo : event.getParametersModel().getmLiveGuardInfo(); + liveBg = TextUtils.equals(String.valueOf(liveBg), String.valueOf(event.getParametersModel().getLiveBg())) ? liveBg : event.getParametersModel().getLiveBg(); + is_fans = TextUtils.equals(String.valueOf(is_fans), String.valueOf(event.getParametersModel().getIs_fans())) ? is_fans : event.getParametersModel().getIs_fans(); + fansNum = TextUtils.equals(String.valueOf(fansNum), String.valueOf(event.getParametersModel().getFansNum())) ? fansNum : event.getParametersModel().getFansNum(); break; case ACTIVITY_CENTER://活动中心 String url = CommonAppConfig.HOST + "/h5/live/hallOfFame/index.html?g=Appapi&m=Turntable&a=tricky"; - url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" - + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); Log.i("tag", url); Intent intent = new Intent(mContext, ZhuangBanActivity.class); intent.putExtra("url", url); @@ -1331,10 +1244,7 @@ public class LiveAudienceActivity extends LiveActivity { break; case POPULAR: url = CommonAppConfig.HOST + "/h5/activity/PopularityTask/index.html"; - url += "?anchorUid=" + mLiveUid - + "&stream=" + mStream - + "&uid=" + CommonAppConfig.getInstance().getUid() - + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + url += "?anchorUid=" + mLiveUid + "&stream=" + mStream + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment(); bundle.putString("url", url); bundle.putInt("show_type", 0); @@ -1407,16 +1317,13 @@ public class LiveAudienceActivity extends LiveActivity { } if (micListener != null) { micListener.updateMicList(mMicQueueList); - DialogUitl.showSimpleDialog(mContext, - String.format(mContext.getString(R.string.live_mic_user_apply), ((LinkMicUserBean) event.getObject()).getUserNicename()), - new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - openMicWindow(2); - dialog.dismiss(); - } - } - ); + DialogUitl.showSimpleDialog(mContext, String.format(mContext.getString(R.string.live_mic_user_apply), ((LinkMicUserBean) event.getObject()).getUserNicename()), new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + openMicWindow(2); + dialog.dismiss(); + } + }); } break; case LINK_MIC_CANCEL: @@ -1485,12 +1392,7 @@ public class LiveAudienceActivity extends LiveActivity { showMsgRed(-1); break; case LIVE_SHARE: - new SharePopDialog(mContext) - .setUid(CommonAppConfig.getInstance().getUid()) - .setAnchorId(event.getBean().getUid()) - .setAnchorName(event.getBean().getUserNiceName()) - .setAnchorAvatar(event.getBean().getAvatar()) - .showDialog(); + new SharePopDialog(mContext).setUid(CommonAppConfig.getInstance().getUid()).setAnchorId(event.getBean().getUid()).setAnchorName(event.getBean().getUserNiceName()).setAnchorAvatar(event.getBean().getAvatar()).showDialog(); break; case WISH_LIST_PROGRESS: if (manager != null) { @@ -1631,22 +1533,14 @@ public class LiveAudienceActivity extends LiveActivity { if (type.equals(bean.getType())) { switch (type) { case "1": - startActivity(new Intent(mContext, SystemMessageActivity.class) - .putExtra("type", bean.getType()) - .putExtra("uid", "") - .putExtra("title", bean.getTitle()) - .putExtra("headImg", "")); + startActivity(new Intent(mContext, SystemMessageActivity.class).putExtra("type", bean.getType()).putExtra("uid", "").putExtra("title", bean.getTitle()).putExtra("headImg", "")); break; case "3": AppEventsLogger.newLogger(mContext).logEvent("FB_customer_service"); if (bean.getLink() != null && !"".equals(bean.getLink())) { WebViewActivity.forward(mContext, bean.getLink(), true); } else { - startActivity(new Intent(mContext, SystemMessageActivity.class) - .putExtra("type", bean.getType()) - .putExtra("uid", "") - .putExtra("title", "") - .putExtra("headImg", "")); + startActivity(new Intent(mContext, SystemMessageActivity.class).putExtra("type", bean.getType()).putExtra("uid", "").putExtra("title", "").putExtra("headImg", "")); } break; @@ -1676,23 +1570,22 @@ public class LiveAudienceActivity extends LiveActivity { map.put("num", "9"); map.put("live_recommend", "sidebar"); //推荐位 - MainNetManager.get(mContext) - .anchorRecommend(map, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(AnchorRecommendModel anchorRecommendModel) { - list.clear(); - slideInfoModels.clear(); - List models = anchorRecommendModel.getList(); + MainNetManager.get(mContext).anchorRecommend(map, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(AnchorRecommendModel anchorRecommendModel) { + list.clear(); + slideInfoModels.clear(); + List models = anchorRecommendModel.getList(); - list.addAll(models); - slideInfoModels = anchorRecommendModel.getSlide(); - } + list.addAll(models); + slideInfoModels = anchorRecommendModel.getSlide(); + } - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - } - }); + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); } @@ -1765,11 +1658,7 @@ public class LiveAudienceActivity extends LiveActivity { case 0: if (liveSudGamePopupXPopup == null) { liveSudGamePopupXPopup = new LiveSudGamePopup(mContext, event.getCreateSudRoomModel()); - new XPopup.Builder(mContext) - .enableDrag(false) - .dismissOnTouchOutside(false) - .dismissOnBackPressed(false) - .asCustom(liveSudGamePopupXPopup).show(); + new XPopup.Builder(mContext).enableDrag(false).dismissOnTouchOutside(false).dismissOnBackPressed(false).asCustom(liveSudGamePopupXPopup).show(); } else { if (liveSudGamePopupXPopup != null) { liveSudGamePopupXPopup.dialog.show(); @@ -1865,17 +1754,14 @@ public class LiveAudienceActivity extends LiveActivity { if (!TextUtils.isEmpty(event.getRightsInterests())) { //跳转贵族 if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.noble))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.NOBLE)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.NOBLE)); //跳转守护 } else if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.guard_guard))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GUARD)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GUARD)); manager.onGuardRed(); //跳转粉丝团 } else if (TextUtils.equals(event.getRightsInterests(), getString(com.yunbao.common.R.string.fan_club))) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.FAN_CLUB)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.FAN_CLUB)); } } //互动游戏 @@ -1885,12 +1771,10 @@ public class LiveAudienceActivity extends LiveActivity { ToastUtil.show(WordUtil.isNewZh() ? "您已在游戏房间中" : "You are already in the game room"); } else { //直播间来的 - new XPopup.Builder(mContext) - .enableDrag(false) + new XPopup.Builder(mContext).enableDrag(false) // .dismissOnTouchOutside(false) // .dismissOnBackPressed(false) - .moveUpToKeyboard(false) - .asCustom(new SudGameListPopup(mContext, event.getInteractionID(), event.getChild(), mLiveUid)) + .moveUpToKeyboard(false).asCustom(new SudGameListPopup(mContext, event.getInteractionID(), event.getChild(), mLiveUid)) .show(); } @@ -1948,9 +1832,7 @@ public class LiveAudienceActivity extends LiveActivity { new Handler().postDelayed(new Runnable() { @Override public void run() { - new XPopup.Builder(mContext) - .asCustom(new DragonExpirePopup(mContext, mLiveUid, maturityDateRemindModel, mStream)) - .show(); + new XPopup.Builder(mContext).asCustom(new DragonExpirePopup(mContext, mLiveUid, maturityDateRemindModel, mStream)).show(); } }, 3000); @@ -1997,34 +1879,33 @@ public class LiveAudienceActivity extends LiveActivity { private void checkMsgRed() { - LiveNetManager.get(mContext) - .getContactMsg(1, new com.yunbao.common.http.base.HttpCallback>() { - @Override - public void onSuccess(List data) { - Log.i(TAG, "onSuccess: " + data.size()); - for (LiveUserMailBoxModel datum : data) { - Log.i(TAG, "for data : " + datum); - } - setData(data); + LiveNetManager.get(mContext).getContactMsg(1, new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List data) { + Log.i(TAG, "onSuccess: " + data.size()); + for (LiveUserMailBoxModel datum : data) { + Log.i(TAG, "for data : " + datum); + } + setData(data); + } + + @Override + public void onError(String error) { + Log.e(TAG, "onError: " + error); + setData(new ArrayList<>()); + } + + void setData(List data) { + for (LiveUserMailBoxModel model : data) { + if (model.getIsRead() == 0) { + showMsgRed(0); + return; } - - @Override - public void onError(String error) { - Log.e(TAG, "onError: " + error); - setData(new ArrayList<>()); - } - - void setData(List data) { - for (LiveUserMailBoxModel model : data) { - if (model.getIsRead() == 0) { - showMsgRed(0); - return; - } - } + } - showMsgRed(-1); - } - }); + showMsgRed(-1); + } + }); } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 76c3fb7ba..f92e9fe4a 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -3,7 +3,6 @@ package com.yunbao.live.activity; import static com.blankj.utilcode.util.SnackbarUtils.dismiss; import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_DISABLE; import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_ENABLE; -import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK_RANDOM; import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_dr_pk_nub; @@ -71,6 +70,7 @@ import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.MicUserManager; import com.yunbao.common.manager.MicedUserManager; import com.yunbao.common.manager.RandomPkManager; +import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.BitmapUtil; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DateFormatUtil; @@ -102,11 +102,12 @@ import com.yunbao.live.interfaces.LiveFunctionClickListener; import com.yunbao.live.interfaces.LivePushListener; import com.yunbao.live.music.LiveMusicDialogFragment; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; -import com.yunbao.live.presenter.LiveLinkMicPkPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; +import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; +import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.views.LiveEndViewHolder; import com.yunbao.live.views.LiveMusicViewHolder; @@ -193,7 +194,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (RandomPkManager.getInstance().isRankModel()) { msg1.put("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); } - linkMicAnchorApply(pkUid, pkUid, true); + linkMicAnchorApply(pkUid, pkUid, msg1.toString()); } @Override @@ -222,6 +223,27 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl Bus.getOn(this); Intent intent = getIntent(); initFaceManager(); + RCRTCEngine.getInstance().registerStatusReportListener(new IRCRTCStatusReportListener() { + + @Override + public void onConnectionStats(StatusReport statusReport) { + //视频发送信息 + for (Map.Entry entry : statusReport.statusVideoSends.entrySet()) { + StatusBean statusBean = entry.getValue(); + //获取userID + String userId = statusBean.uid; + //获取视频 宽x高@帧率 + String resolution = statusBean.frameWidth + "x" + statusBean.frameHeight + "@" + statusBean.frameRate; + //获取码率 + long bitRate = statusBean.bitRate; + //丢包率 + long lossRate = statusBean.packetLostRate; + //带宽 + String googAvailableSendBandwidth = statusReport.googAvailableSendBandwidth; +// Log.e("网速和内存", "获取视频:" + resolution + " 丢包率:" + lossRate + " 带宽:" + googAvailableSendBandwidth); + } + } + }); leave_img = findViewById(R.id.leave_img); mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); mLiveKsyConfigBean = intent.getParcelableExtra(Constants.LIVE_KSY_CONFIG); @@ -251,13 +273,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl RandomPkManager.getInstance().addOnRandomPkTimer(onRandomPkTimer); - manager.setOnMirrorChanged(new FaceManager.OnMirrorChanged() { - @Override - public void onChange(boolean falg) { - mLivePushViewHolder.setEnableBeauty(falg); - } - }); - //添加开播前设置控件 mLiveReadyViewHolder = new LiveNewReadyRyViewHolder(mContext, mContainer, mLiveSDK); mLiveReadyViewHolder.setManager(manager); @@ -294,8 +309,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl private void initFaceManager() { manager = new FaceManager(); manager.initFURender(mContext); - //暂时去掉 - //manager.drawRongFrame(mContext); + manager.drawRongFrame(mContext); } public boolean isStartPreview() { @@ -406,7 +420,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl public void onSuccess(int code, String msg, String[] info) { if (code == 0) { - LiveRyLinkMicPkPresenter.mApplyUid = CommonAppConfig.getInstance().getUid(); btn_start_dr_pk.setVisibility(View.VISIBLE); // dr_pk_view.setVisibility(View.VISIBLE); final SocketSendBean msg1 = new SocketSendBean() @@ -419,7 +432,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); Message message = Message.obtain("g" + mLiveUid, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(Message message) { @@ -708,6 +721,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl fragment.show(getSupportFragmentManager(), "LiveLinkMicListDialogFragment");*/ FreePkDialogFragment fragment = new FreePkDialogFragment(); fragment.setDrPkNum(pk_nub); + fragment.setLiveUid(mLiveUid); fragment.show(getSupportFragmentManager(), "LiveLinkMicListDialogFragment"); } @@ -725,6 +739,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl public void openRandomPkWindow() { RandomPkDialogFragment fragment = new RandomPkDialogFragment(); Bundle bundle = new Bundle(); + bundle.putBoolean("isSw",false); fragment.setArguments(bundle); fragment.show(getSupportFragmentManager(), "RandomPkDialogFragment"); } @@ -959,7 +974,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl JSONObject obj = JSON.parseObject(info[0]); JSONObject datas = obj.getJSONObject("data"); try { - SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid, mSocketRyClient); + SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid, mSocketSwClient); } catch (Exception e) { e.printStackTrace(); } @@ -1045,8 +1060,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl mLivePushViewHolder = null; mLiveLinkMicPresenter = null; //断开socket - if (mSocketRyClient != null) { - mSocketRyClient.disConnect(); + if (mSocketSwClient != null) { + mSocketSwClient.disConnect(); } super.release(); } @@ -1203,7 +1218,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl */ public void linkMicAnchorApply(String pkUid, String stream) { JSONObject msg1 = buildLinkMicJSON(); - linkMicAnchorApply(pkUid, stream, false); + linkMicAnchorApply(pkUid, stream, msg1.toString()); } public JSONObject buildLinkMicJSON() { @@ -1215,7 +1230,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl return msg1; } - public void linkMicAnchorApply(final String pkUid, String stream, boolean extra) { + public void linkMicAnchorApply(final String pkUid, String stream, String extra) { LiveHttpUtil.livePkCheckLive(pkUid, stream, mStream, new HttpCallback() { @Override @@ -1224,46 +1239,38 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl JSONObject obj = JSON.parseObject(info[0]); if (obj != null) { if (obj.getString("ispk").equals("0")) { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 1) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", pkUid) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - //判断是否是随机PK - if(extra){ - msg1.param("random_pk", "1"); - msg1.param("msgtype","11"); - if (RandomPkManager.getInstance().isRankModel()) { - msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + + + IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + // ToastUtil.show("邀请 " + pkUid + " 发送成功"); + runOnUiThread(new Runnable() { + @Override + public void run() { + dismiss(); + } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + runOnUiThread(new Runnable() { + @Override + public void run() { + dismiss(); + } + }); + //todo 安卓端状态码说明文档:https://docs.rongcloud.cn/v4/views/rtc/call/code/android.html + Log.e("ry", rtcErrorCode + "aaaaaa" + CommonAppConfig.getInstance().getUid() + "VDSSSS" + pkUid); + if (WordUtil.isNewZh()) { + ToastUtil.show("邀请 " + pkUid + " 发送失败 :" + rtcErrorCode); + } else { + ToastUtil.show("invite " + pkUid + " failed:" + rtcErrorCode); } } - msg1.create(); + }); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain("g" + pkUid, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("tx", "发送成功"); - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "发送失败" + errorCode.getMessage()); - - } - }); } else { ToastUtil.show("主播正在PK,稍後再試"); if (RandomPkManager.getInstance().isRandomModel()) { @@ -1289,6 +1296,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (mLiveAnchorViewHolder != null) { mLiveAnchorViewHolder.setYaoqing(pkUid); } + } /** @@ -1308,39 +1316,34 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (obj != null) { if (obj.getString("ispk").equals("0")) { - // TODO: 2024/4/19 邀请主播进行多人连麦 - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LIVE_DRPK) - .param("action", 1) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", pkUid) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - - String targetId = "g" + pkUid; - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - Message message = Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { @Override - public void onAttached(Message message) { - - } - - @Override - public void onSuccess(Message message) { - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(message.toString() + ""); + public void onSuccess() { + if (!extra.equals(SOCKET_LIVE_DRPK_RANDOM)) { + if (WordUtil.isNewZh()) { + ToastUtil.show("邀请 " + pkUid + " 发送成功"); + } else { + ToastUtil.show("invite " + pkUid + " successful"); + } } + runOnUiThread(new Runnable() { + @Override + public void run() { + dismiss(); + } + }); } @Override - public void onError(Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); + public void onFailed(RTCErrorCode rtcErrorCode) { + runOnUiThread(new Runnable() { + @Override + public void run() { + dismiss(); + } + }); + //todo 安卓端状态码说明文档:https://docs.rongcloud.cn/v4/views/rtc/call/code/android.html + Log.e("ry", rtcErrorCode + "aaaaaa" + CommonAppConfig.getInstance().getUid() + "VDSSSS" + pkUid); } }); } else { @@ -1411,7 +1414,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl //多人PK接受 @Override public void onLinkDRMicPkApplyOk(UserBean u) { - L.eSw("onLinkDRMicPkApplyOk111111"); if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.onLinkDRMicPkApplyOk(u); } @@ -1672,8 +1674,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl break; case DISCONNEXT_PK_TIME: if (mLivePushViewHolder != null) { - //mLivePushViewHolder.changeToBig(); - mLivePushViewHolder.anchorClose(); + mLivePushViewHolder.changeToBig(); mLiveRyLinkMicPkPresenter.leaveDRRoom(); } break; @@ -1721,6 +1722,15 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl liveInputDialogFragment.setArguments(liveInputBundle); liveInputDialogFragment.show(getSupportFragmentManager(), "LiveInputDialogFragment"); break; + case LIVE_DIALOG_ANCHOR_TIPS: + new DialogUitl.Builder(mContext) + .setContent(event.getObject().toString()) + .setConfirmString(WordUtil.isNewZh() ? "確定" : "confirm") + .setCancelable(true) + .setShowCancelButton(false) + .build() + .show(); + break; } } @@ -1859,6 +1869,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl .setIcon("https://downs.yaoulive.com/xzs_tab.png") .setNameColor("#f19ec2") .setSystemBubble("https://downs.yaoulive.com/xzs_qipao.9.png") + .setIconEn("https://downs.yaoulive.com/Robot_en.png") .setUserName("") .setContent(content); SocketSendBean msg = @@ -1872,7 +1883,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); Message message = Message.obtain(targetId, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(Message message) { @@ -1880,8 +1891,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl @Override public void onSuccess(Message message) { - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java new file mode 100644 index 000000000..bad0121c0 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -0,0 +1,1939 @@ +package com.yunbao.live.activity; + +import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_DISABLE; +import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_ENABLE; +import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; +import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; +import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_dr_pk_nub; +import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_start_dr_pk; +import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_start_dr_pk_view; + +import android.app.Dialog; +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.os.Handler; +import android.text.TextUtils; +import android.util.Log; +import android.view.KeyEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.blankj.utilcode.util.GsonUtils; +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.target.CustomTarget; +import com.bumptech.glide.request.transition.Transition; +import com.lxj.xpopup.XPopup; +import com.lxj.xpopup.core.BasePopupView; +import com.lxj.xpopup.interfaces.XPopupCallback; +import com.opensource.svgaplayer.SVGAImageView; +import com.tencent.trtc.TRTCCloudDef; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.CommonAppContext; +import com.yunbao.common.Constants; +import com.yunbao.common.bean.AiAutomaticSpeechModel; +import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.bean.LinkMicUserBean; +import com.yunbao.common.bean.LiveAiRobotBean; +import com.yunbao.common.bean.LiveBean; +import com.yunbao.common.bean.LiveUserGiftBean; +import com.yunbao.common.bean.MicUserBean; +import com.yunbao.common.bean.SendMoneyLongModel; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.dialog.NotCancelableDialog; +import com.yunbao.common.event.AllServerNotifyFFGGGDJANEvent; +import com.yunbao.common.event.GiftWallIlluminateEvent; +import com.yunbao.common.event.LiveSudGamePopupShowOrHideEvent; +import com.yunbao.common.event.LoginInvalidEvent; +import com.yunbao.common.event.SendBlindGiftEvent; +import com.yunbao.common.event.SendMoneyLongEndEvent; +import com.yunbao.common.event.ShowHideEvent; +import com.yunbao.common.http.CommonHttpConsts; +import com.yunbao.common.http.CommonHttpUtil; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.LiveHttpConsts; +import com.yunbao.common.http.LiveHttpUtil; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.manager.MicUserManager; +import com.yunbao.common.manager.MicedUserManager; +import com.yunbao.common.manager.RandomPkManager; +import com.yunbao.common.utils.BitmapUtil; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.DateFormatUtil; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.LogUtil; +import com.yunbao.common.utils.MicStatusManager; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.views.LiveNewWishListPopup; +import com.yunbao.common.views.LiveRobotSettingCustomPopup; +import com.yunbao.common.views.LiveSudGamePopup; +import com.yunbao.faceunity.FaceManager; +import com.yunbao.live.R; +import com.yunbao.live.bean.LiveChatBean; +import com.yunbao.live.bean.LiveGuardInfo; +import com.yunbao.live.bean.LiveKsyConfigBean; +import com.yunbao.live.bean.LiveReceiveGiftBean; +import com.yunbao.live.dialog.FreePkDialogFragment; +import com.yunbao.live.dialog.LiveInputDialogFragment; +import com.yunbao.live.dialog.LiveNewFunctionDialogFragment; +import com.yunbao.live.dialog.LivePrankDialogFragment; +import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience; +import com.yunbao.live.dialog.RandomPkDialogFragment; +import com.yunbao.live.event.LinkMicTxMixStreamEvent; +import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.interfaces.LiveFunctionClickListener; +import com.yunbao.live.interfaces.LivePushListener; +import com.yunbao.live.music.LiveMusicDialogFragment; +import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; +import com.yunbao.live.presenter.LiveLinkMicPresenter; +import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; +import com.yunbao.live.socket.SocketRyChatUtil; +import com.yunbao.live.socket.SocketSwClient; +import com.yunbao.live.socket.SocketSendBean; +import com.yunbao.live.views.LiveEndViewHolder; +import com.yunbao.live.views.LiveMusicViewHolder; +import com.yunbao.live.views.LiveNewReadySwViewHolder; +import com.yunbao.live.views.LivePushSwViewHolder; +import com.yunbao.live.views.LiveRoomViewHolder; +import com.yunbao.live.views.LiveRyAnchorViewHolder; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.io.File; +import java.util.List; +import java.util.Random; + +import cn.rongcloud.rtc.api.RCRTCEngine; +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.base.RCRTCRect; +import cn.rongcloud.rtc.base.RTCErrorCode; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; +import io.rong.message.TextMessage; +import pl.droidsonroids.gif.GifImageView; + + +/** + * Created by cxf on 2018/10/7. + * 主播直播间 + */ + +public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionClickListener { + + private static final String TAG = "LiveSwAnchorActivity"; + + public static void forward(Context context, int liveSdk, LiveKsyConfigBean bean) { + Intent intent = new Intent(context, LiveSwAnchorActivity.class); + intent.putExtra(Constants.LIVE_SDK, liveSdk); + intent.putExtra(Constants.LIVE_KSY_CONFIG, bean); + context.startActivity(intent); + } + + private ViewGroup mRoot; + private ViewGroup mContainerWrap; + public LivePushSwViewHolder mLivePushViewHolder; + public LiveNewReadySwViewHolder mLiveReadyViewHolder; + public static LiveRyAnchorViewHolder mLiveAnchorViewHolder; + private LiveMusicViewHolder mLiveMusicViewHolder; + private boolean mStartPreview;//是否开始预览 + private boolean mStartLive;//是否开始了直播 + private List mGameList;//游戏开关 + private boolean mBgmPlaying;//是否在播放背景音乐 + private LiveKsyConfigBean mLiveKsyConfigBean; + private HttpCallback mCheckLiveCallback; + private File mLogFile; + private int mReqCount; + private boolean mPaused; + String mBeautySdkType; + public static int isDRPK = 0; + public static boolean PKing = false; + public static int pk_nub; + public static int backIndex = 0;//0=未判断,1=已判断 + private FaceManager manager; + private ImageView leave_img; + + private final RandomPkManager.OnRandomPkTimer onRandomPkTimer = new RandomPkManager.OnRandomPkTimer() { + @Override + public void onTimer(String time) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.setRandomPkTimer(String.format(mContext.getString(R.string.random_pk_info_btn_ing), time)); + } + } + + @Override + public void onStartPK(String pkUid) { + JSONObject msg1 = buildLinkMicJSON(); + msg1.put("random_pk", "1"); + if (RandomPkManager.getInstance().isRankModel()) { + msg1.put("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + } + linkMicAnchorApply(pkUid, pkUid, true); + } + + @Override + public void onPking() { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.setRandomPkTimer(null); + } + } + + @Override + public void onPkEnd() { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.setRandomPkTimer(null); + } + } + }; + + @Override + protected int getLayoutId() { + return R.layout.activity_live_anchor; + } + + @Override + protected void main() { + super.main(); + Bus.getOn(this); + Intent intent = getIntent(); + initFaceManager(); + leave_img = findViewById(R.id.leave_img); + mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); + if(mLiveSDK ==Constants.LIVE_SDK_SW){ + isSw = true; + } + mLiveKsyConfigBean = intent.getParcelableExtra(Constants.LIVE_KSY_CONFIG); + L.e(TAG, "直播sdk----->" + (mLiveSDK == Constants.LIVE_SDK_KSY ? "金山云" : "腾讯云")); + mRoot = (ViewGroup) findViewById(R.id.root); + mSocketUserType = Constants.SOCKET_USER_TYPE_ANCHOR; + UserBean u = CommonAppConfig.getInstance().getUserBean(); + mLiveUid = u.getId(); + mLiveBean = new LiveBean(); + mLiveBean.setUid(mLiveUid); + mLiveBean.setUserNiceName(u.getUserNiceName()); + mLiveBean.setAvatar(u.getAvatar()); + mLiveBean.setAvatarThumb(u.getAvatarThumb()); + mLiveBean.setLevelAnchor(u.getLevelAnchor()); + mLiveBean.setGoodNum(u.getGoodName()); + mLiveBean.setCity(u.getCity()); + mBeautySdkType = CommonAppConfig.getInstance().getBeautySdkType(); + + mLivePushViewHolder = new LivePushSwViewHolder(mContext, (ViewGroup) findViewById(R.id.preview_container)); + mLivePushViewHolder.setLiveActivityContainer(mContainer); + + mLivePushViewHolder.addToParent(); + mLivePushViewHolder.subscribeActivityLifeCycle(); + mContainerWrap = (ViewGroup) findViewById(R.id.container_wrap); + mContainer = (ViewGroup) findViewById(R.id.container); + mLiveSwLinkMicPkPresenter = new LiveSwLinkMicPkPresenter(mContext, mLivePushViewHolder, true, mContainer); + + RandomPkManager.getInstance().addOnRandomPkTimer(onRandomPkTimer); + + manager.setOnMirrorChanged(new FaceManager.OnMirrorChanged() { + @Override + public void onChange(boolean falg) { + mLivePushViewHolder.setEnableBeauty(falg); + } + }); + + //添加开播前设置控件 + mLiveReadyViewHolder = new LiveNewReadySwViewHolder(mContext, mContainer, mLiveSDK); + mLiveReadyViewHolder.setManager(manager); + mLiveReadyViewHolder.addToParent(); + mLiveReadyViewHolder.setLiveUid(mLiveUid); + mLiveReadyViewHolder.subscribeActivityLifeCycle(); + mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePushViewHolder, true, mLiveSDK, mContainer); + mLiveLinkMicAnchorPresenter = new LiveLinkMicAnchorPresenter(mContext, mLivePushViewHolder, true, mLiveSDK, mContainer); + mLivePushViewHolder.setLivePushListener(new LivePushListener() { + @Override + public void onPreviewStart() { + //开始预览回调 + mStartPreview = true; + } + + @Override + public void onPushStart() { + //开始推流回调 + LiveHttpUtil.changeLive(mStream); + + + } + + @Override + public void onPushFailed() { + //推流失败回调 + ToastUtil.show(mContext.getString(R.string.live_push_failed)); + } + }); + + + } + + private void initFaceManager() { + manager = new FaceManager(); + manager.initFURender(mContext); + //暂时去掉 + //manager.drawRongFrame(mContext); + } + + public boolean isStartPreview() { + return mStartPreview; + } + + /** + * 主播直播间功能按钮点击事件 + * + * @param functionID + */ + int mrr = 0; + public int leave = 0; + + + @Override + public void onClick(int functionID) { + switch (functionID) { + case Constants.LIVE_ROBOT: + new XPopup.Builder(mContext) + .setPopupCallback(new XPopupCallback() { + @Override + public void onCreated(BasePopupView popupView) { + + } + + @Override + public void beforeShow(BasePopupView popupView) { + + } + + @Override + public void onShow(BasePopupView popupView) { + + } + + @Override + public void onDismiss(BasePopupView popupView) { + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UPDATA_ROBOT)); + } + + @Override + public void beforeDismiss(BasePopupView popupView) { + + } + + @Override + public boolean onBackPressed(BasePopupView popupView) { + return false; + } + + @Override + public void onKeyBoardStateChanged(BasePopupView popupView, int height) { + + } + + @Override + public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { + + } + + @Override + public void onClickOutside(BasePopupView popupView) { + + } + }) + .asCustom(new LiveRobotSettingCustomPopup(mContext)) + .show(); + break; + case Constants.LIVE_FUNC_ZG://zg + // ToastUtil.show("開發中,敬請期待"); + LivePrankDialogFragment fragment = new LivePrankDialogFragment(); + fragment.setmLiveUid(mLiveUid); + fragment.show(getSupportFragmentManager(), "LivePrankDialogFragment"); + break; + case Constants.LIVE_FUNC_MIC://語音 + //ToastUtil.show("開發中,敬請期待"); + if (isDRPK != 1) { + openMicWindow(1); + } else { + ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); + } + break; + case Constants.LIVE_FUNC_DR://多人PK +// if (LiveRyLinkMicPkPresenter.inputStreamList.size() == 4) { +// return; +// } + if (isDRPK != 1) { + HttpClient.getInstance().get("live.getdrnum", "live.getdrnum") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + pk_nub = Integer.valueOf(obj.getString("pk_num_day")); + + btn_dr_pk_nub.setText(String.format(getString(R.string.number_of_remaining_times), String.valueOf(pk_nub))); + DialogUitl.showSimpleDialog(mContext, String.format(getString(R.string.confirmed_to_proceed), String.valueOf(pk_nub)), + false, + new DialogUitl.SimpleCallback2() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + HttpClient.getInstance().get("live.createDRPKroom", "live.createDRPKroom") + .params("type", "1") + .params("sign", "1") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + if (code == 0) { + LiveSwLinkMicPkPresenter.mApplyUid = CommonAppConfig.getInstance().getUid(); + btn_start_dr_pk.setVisibility(View.VISIBLE); +// dr_pk_view.setVisibility(View.VISIBLE); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LIVE_DRPK) + .param("action", 9) + .param("msgtype", 1); + msg1.create(); + + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + Message message = Message.obtain("g" + mLiveUid, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + isDRPK = 1; + btn_start_dr_pk_view.setVisibility(View.VISIBLE); + mLiveSwLinkMicPkPresenter.setDRInitiator(true); + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + Log.i("tx", "发送失败" + errorCode + message); + + } + }); + + } else { + ToastUtil.show(msg); + } + } + }); + + } + + @Override + public void onCancelClick() { + + } + }); + } else { + ToastUtil.show(msg); + } + } + }); + } else { + ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); + } + break; + case Constants.LIVE_FUNC_BEAUTY://美颜 + beauty(); + break; + case Constants.LIVE_FUNC_CAMERA://切换镜头 + toggleCamera(); + break; + case Constants.LIVE_FUNC_FLASH://切换闪光灯 + toggleFlash(); + break; + case Constants.LIVE_FUNC_MUSIC://伴奏 + openMusicWindow(); + break; + case Constants.LIVE_FUNC_SHARE://分享 + openShareWindow(); + break; + case Constants.LIVE_FUNC_GAME://游戏 + openGameWindow(); + break; + case Constants.LIVE_FUNC_RED_PACK://红包 + openRedPackSendWindow(); + break; + case Constants.LIVE_FUNC_ZSLK://暫時離開 + leaveLive(); + break; + case Constants.LIVE_FUNC_WKS: + String url = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid; + ZhuangBanActivity.forward(mContext, url, false, 0); + break; + case Constants.LIVE_FUNC_LINK_MIC://连麦 + if (isDRPK != 1) { + //openLinkMicAnchorWindow(false); + openFreePkWindow(); + } else { + ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); + } + break; + case Constants.LIVE_FUNC_WISHLIST://心愿单 + openWishListWindow(); + break; + case Constants.LIVE_FUNC_MIRROR://鏡像 + + TRTCCloudDef.TRTCRenderParams t = new TRTCCloudDef.TRTCRenderParams(); + if (mrr == 0) { + mrr = 1; + t.mirrorType = TRTC_VIDEO_MIRROR_TYPE_ENABLE; + } else if (mrr == 1) { + mrr = 0; + t.mirrorType = TRTC_VIDEO_MIRROR_TYPE_DISABLE; + } + break; + case Constants.LIVE_FUNC_RANDOM_PK: + if (isDRPK != 1) { + openRandomPkWindow(); + } else { + ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); + } + break; + default: + break; + } + + } + + + /** + * 主播展示离开直播间 + */ + private void leaveLive() { + if (PKing || isDRPK == 1) { + return; + } + RCRTCRect rect = new RCRTCRect(0f, 0f, 1.0f); + if (leave == 0) { + leave = 1; + leave_img.setVisibility(View.VISIBLE); + Glide.with(mContext).asBitmap().load(R.mipmap.zslk).into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + + boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(BitmapUtil.getInstance().convertMirror(resource), rect); + sendSystemMessage(mContext.getString(R.string.live_anchor_leave)); + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); + } else if (leave == 1) { + leave = 0; + leave_img.setVisibility(View.GONE); + // 清除水印 + boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(null, rect); + sendSystemMessage(mContext.getString(R.string.live_anchor_come_back)); + } + + HttpClient.getInstance().get("Live.isLeave", "Live.isLeave") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("isleave", leave) + .params("token", CommonAppConfig.getInstance().getToken()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + } + }); + } + + + /** + * 打开心愿单窗口 + */ + public void openWishListWindow() { +// LiveNewWishListDialogFragment fragment = new LiveNewWishListDialogFragment(); +// if (mContext instanceof LiveRyAnchorActivity) { +// fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveWishListDialogFragment"); +// } + new XPopup.Builder(mContext) + .enableDrag(false) + .asCustom(new LiveNewWishListPopup(LiveSwAnchorActivity.this)) + + .show(); + } + + //打开相机前执行 + public void beforeCamera() { + if (mLivePushViewHolder != null) { + mLivePushViewHolder.setOpenCamera(true); + } + } + + + /** + * 切换镜头 + */ + public void toggleCamera() { + if (mLivePushViewHolder != null) { + mLivePushViewHolder.toggleCamera(); + } + } + + /** + * 切换闪光灯 + */ + public void toggleFlash() { + if (mLivePushViewHolder != null) { + mLivePushViewHolder.toggleFlash(); + } + } + + /** + * 设置美颜 + */ + public void beauty() { + if (mLiveReadyViewHolder != null) { + mLiveReadyViewHolder.hide(); + } + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.changeFaceUnityView(); + } + } + + /** + * 飘心 + */ + public void light() { + if (mLiveRoomViewHolder != null) { + } + } + + /** + * 打开音乐窗口 + */ + private void openMusicWindow() { + if (isLinkMicAnchor() || isLinkMicAnchor()) { + ToastUtil.show(mContext.getString(R.string.link_mic_not_bgm)); + return; + } + LiveMusicDialogFragment fragment = new LiveMusicDialogFragment(); + fragment.setActionListener(new LiveMusicDialogFragment.ActionListener() { + @Override + public void onChoose(String musicId) { + if (mLivePushViewHolder != null) { + if (mLiveMusicViewHolder == null) { + mLiveMusicViewHolder = new LiveMusicViewHolder(mContext, mContainer, mLivePushViewHolder); + mLiveMusicViewHolder.subscribeActivityLifeCycle(); + mLiveMusicViewHolder.addToParent(); + } + mLiveMusicViewHolder.play(musicId); + mBgmPlaying = true; + } + } + }); + fragment.show(getSupportFragmentManager(), "LiveMusicDialogFragment"); + } + + /** + * 关闭背景音乐 + */ + public void stopBgm() { + if (mLiveMusicViewHolder != null) { + mLiveMusicViewHolder.release(); + } + mLiveMusicViewHolder = null; + mBgmPlaying = false; + } + + public boolean isBgmPlaying() { + return mBgmPlaying; + } + + + /** + * 打开功能弹窗 + */ + public void showFunctionDialog() { + LiveNewFunctionDialogFragment fragment = new LiveNewFunctionDialogFragment(); + Bundle bundle = new Bundle(); + boolean hasGame = false; + if (CommonAppConfig.GAME_ENABLE && mGameList != null) { + hasGame = mGameList.size() > 0; + } + bundle.putBoolean(Constants.HAS_GAME, hasGame); + bundle.putInt("leave", leave); + bundle.putString("liveUid", mLiveUid); + bundle.putBoolean("isPk", isDRPK == 1 || PKing || mLivePushViewHolder.isPking()); + bundle.putLong("liveTime", mLiveAnchorViewHolder.getmAnchorLiveTime()); + bundle.putBoolean(Constants.OPEN_FLASH, mLivePushViewHolder != null && mLivePushViewHolder.isFlashOpen()); + fragment.setArguments(bundle); + fragment.setFunctionClickListener(this); + fragment.show(getSupportFragmentManager(), "LiveFunctionDialogFragment"); + } + + /** + * 打开主播连麦窗口 + */ + public void openLinkMicAnchorWindow(boolean isDRPK) { + if (mLiveLinkMicAnchorPresenter != null && !mLiveLinkMicAnchorPresenter.canOpenLinkMicAnchor()) { + return; + } +/* LiveLinkMicListDialogFragment fragment = new LiveLinkMicListDialogFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean("isDRPK", isDRPK); + fragment.setArguments(bundle); + fragment.show(getSupportFragmentManager(), "LiveLinkMicListDialogFragment");*/ + FreePkDialogFragment fragment = new FreePkDialogFragment(); + fragment.setDrPkNum(pk_nub); + fragment.setLiveUid(mLiveUid); + fragment.show(getSupportFragmentManager(), "LiveLinkMicListDialogFragment"); + + } + + public void openFreePkWindow() { + FreePkDialogFragment fragment = new FreePkDialogFragment(); + Bundle bundle = new Bundle(); + fragment.setArguments(bundle); + fragment.show(getSupportFragmentManager(), "FreePkDialogFragment"); + } + + /** + * 随机PK + */ + public void openRandomPkWindow() { + RandomPkDialogFragment fragment = new RandomPkDialogFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean("isSw",true); + fragment.setArguments(bundle); + fragment.show(getSupportFragmentManager(), "RandomPkDialogFragment"); + } + + /** + * 打开选择游戏窗口 + */ + private void openGameWindow() { + if (isLinkMic() || isLinkMicAnchor()) { + ToastUtil.show(mContext.getString(R.string.live_link_mic_cannot_game)); + return; + } + } + + /** + * 关闭游戏 + */ + public void closeGame() { +// if (mGamePresenter != null) { +// mGamePresenter.closeGame(); +// } + } + + /** + * 开播成功 + * + * @param data createRoom返回的数据 + */ + public void startLiveSuccess(String data, int liveType, int liveTypeVal) { + Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((" + data); + mLiveType = liveType; + mLiveTypeVal = liveTypeVal; + //处理createRoom返回的数据 + JSONObject obj = JSON.parseObject(data); + mStream = obj.getString("stream"); + mDanmuPrice = obj.getString("barrage_fee"); + String playUrl = obj.getString("pull"); + L.e("createRoom----播放地址--->" + playUrl); + mLiveBean.setPull(playUrl); + mTxAppId = obj.getString("tx_appid"); + + //移除开播前的设置控件,添加直播间控件 + if (mLiveReadyViewHolder != null) { + mLiveReadyViewHolder.removeFromParent(); + mLiveReadyViewHolder.release(); + } + mLiveReadyViewHolder = null; + if (mLiveRoomViewHolder == null) { + mLiveRoomViewHolder = new LiveRoomViewHolder(true, 2, mContext, mContainer, (GifImageView) findViewById(R.id.gift_gif), (SVGAImageView) findViewById(R.id.gift_svga), mContainerWrap, getWindowManager()); + mLiveRoomViewHolder.setManager(manager); + mLiveRoomViewHolder.addToParent(); + mLiveRoomViewHolder.subscribeActivityLifeCycle(); + mLiveRoomViewHolder.setLiveInfo(mLiveUid, mStream, obj.getIntValue("userlist_time") * 1000); + mLiveRoomViewHolder.setVotes(obj.getString("votestotal")); + mLiveRoomViewHolder.setMedaRankNum(obj.getString("medalRankNum")); + mLiveRoomViewHolder.startFace(); + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u != null) { + mLiveRoomViewHolder.setRoomNum(u.getLiangNameTip()); + mLiveRoomViewHolder.setName(u.getUserNiceName()); + mLiveRoomViewHolder.setAvatar(u.getAvatar()); + mLiveRoomViewHolder.setAnchorLevel(u.getLevelAnchor()); + mLiveRoomViewHolder.setAnchorGoodNumber(u.getGoodName()); + mLiveRoomViewHolder.initHourRankList(); + } + mLiveRoomViewHolder.startAnchorLight(); + //初始化女神说 + mLiveRoomViewHolder.initAnchorSay(); + mLiveRoomViewHolder.setGiftWall(obj.getString("gift_wall_lighten_number"), obj.getString("gift_wall_lighten_total")); + } + if (mLiveAnchorViewHolder == null) { + mLiveAnchorViewHolder = new LiveRyAnchorViewHolder(mContext, mContainer); + mLiveAnchorViewHolder.setLiveBean(mLiveBean); + mLiveAnchorViewHolder.addToParent(); + mLiveAnchorViewHolder.startAnchorLiveTime(); + } + mLiveBottomViewHolder = mLiveAnchorViewHolder; + mSocketSwClient = new SocketSwClient(mLiveUid, this, mContext); + mSocketSwClient.setLivePushSwViewHolder(mLivePushViewHolder); + CommonAppContext.Ingroup = 1; + + if (mLiveLinkMicPresenter != null) { + mLiveLinkMicPresenter.setSocketClient(mSocketClient); + } + if (mLiveLinkMicAnchorPresenter != null) { + mLiveLinkMicAnchorPresenter.setSocketClient(mSocketClient); + mLiveLinkMicAnchorPresenter.setPlayUrl(playUrl); + mLiveLinkMicAnchorPresenter.setSelfStream(mStream); + } + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.setSelfStream(mStream); + } + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.setLiveUid(mLiveUid, ""); + } + + //开始推流 + if (mLivePushViewHolder != null) { + mLivePushViewHolder.startPush(obj.getString("push")); + } + //开始显示直播时长 + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.startAnchorLiveTime(); + mLiveRoomViewHolder.startAnchorCheckLive(); + mLiveRoomViewHolder.setAnchorGoodNumber(obj.getString("goodnum")); + } + mStartLive = true; + mLiveRoomViewHolder.startRefreshUserList(); + mLiveRoomViewHolder.hideFloatMsg(); + mLiveRoomViewHolder.initPkRank(null); + + //守护相关 + mLiveGuardInfo = new LiveGuardInfo(); + int guardNum = obj.getIntValue("guard_nums"); + mLiveGuardInfo.setGuardNum(guardNum); + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.setGuardNum(guardNum); + + } + + //奖池等级 + int giftPrizePoolLevel = obj.getIntValue("jackpot_level"); + if (giftPrizePoolLevel >= 0) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.showPrizePoolLevel(String.valueOf(giftPrizePoolLevel)); + } + } + + //游戏相关 + if (CommonAppConfig.GAME_ENABLE) { + mGameList = JSON.parseArray(obj.getString("game_switch"), Integer.class); + } + getAiRobotStatus(); + MicedUserManager.get().removeAllMicUserList(); + MicUserManager.get().removeAllMicUserList(); + } + + /** + * 关闭直播 + */ + public void closeLive() { + DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.live_end_live), new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + MicStatusManager.getInstance().closeMic(mContext); + MicedUserManager.get().removeAllMicUserList(); + MicUserManager.get().removeAllMicUserList(); + PKing = false; + isDRPK = 0; + endLive(); + RandomPkManager.getInstance().release(); + } + }); + } + + public void endLives() { + + + RCRTCEngine.getInstance().getDefaultVideoStream().stopCamera(new IRCRTCResultCallback() { + @Override + public void onSuccess() { + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + }); + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.i("ry", "退出成功"); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.i("ry", "退出失败" + errorCode); + } + }); + + + if (mLivePushViewHolder != null) { + mLivePushViewHolder.release(); + } + if (mLiveLinkMicPresenter != null) { + mLiveLinkMicPresenter.release(); + } + mLivePushViewHolder = null; + mLiveLinkMicPresenter = null; + + superBackPressed(); + + + release(); + mStartLive = false; + } + + /** + * 结束直播 + */ + public void endLive() { + RCRTCEngine.getInstance().getDefaultVideoStream().stopCamera(new IRCRTCResultCallback() { + @Override + public void onSuccess() { + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + }); + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.i("ry", "退出成功"); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.i("ry", "退出失败" + errorCode); + } + }); + //请求关播的接口 + LiveHttpUtil.stopLive(mStream, new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (robotRunnable != null) { + robotHandler.removeCallbacks(robotRunnable); + robotRunnable = null; + } + if (code == 0) { + JSONObject obj = JSON.parseObject(info[0]); + JSONObject datas = obj.getJSONObject("data"); + try { + SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid, mSocketSwClient); + } catch (Exception e) { + e.printStackTrace(); + } + + if (mLiveEndViewHolder == null) { + mLiveEndViewHolder = new LiveEndViewHolder(mContext, mRoot, mLiveBean.getUid()); + mLiveEndViewHolder.subscribeActivityLifeCycle(); + mLiveEndViewHolder.addToParent(); + mLiveEndViewHolder.showData(mLiveBean, mStream); + mLiveEndViewHolder.upData(datas.getString("votes"), datas.getString("length"), Long.parseLong(datas.getString("nums"))); + } + if (mLiveAnchorViewHolder != null) { + mLiveAnchorViewHolder.release(); + mLiveAnchorViewHolder = null; + } + + if (mLivePushViewHolder != null) { + mLivePushViewHolder.release(); + } + if (mLiveLinkMicPresenter != null) { + mLiveLinkMicPresenter.release(); + } + mLivePushViewHolder = null; + mLiveLinkMicPresenter = null; + release(); + mStartLive = false; + } else { + ToastUtil.show(msg); + } + } + + @Override + public boolean showLoadingDialog() { + return true; + } + + @Override + public Dialog createLoadingDialog() { + return DialogUitl.loadingDialog(mContext, mContext.getString(R.string.live_end_ing)); + } + }); + } + + + @Override + public void onBackPressed() { + + if (mStartLive) { + if (!canBackPressed()) { + return; + } + closeLive(); + } else { + endLives(); + } + + } + + public void superBackPressed() { + super.onBackPressed(); + } + + public void release() { + LiveHttpUtil.cancel(LiveHttpConsts.CHANGE_LIVE); + LiveHttpUtil.cancel(LiveHttpConsts.STOP_LIVE); + LiveHttpUtil.cancel(LiveHttpConsts.LIVE_PK_CHECK_LIVE); + LiveHttpUtil.cancel(LiveHttpConsts.SET_LINK_MIC_ENABLE); + CommonHttpUtil.cancel(CommonHttpConsts.CHECK_TOKEN_INVALID); + if (mLiveReadyViewHolder != null) { + mLiveReadyViewHolder.release(); + } + if (mLiveMusicViewHolder != null) { + mLiveMusicViewHolder.release(); + } + if (mLivePushViewHolder != null) { + mLivePushViewHolder.release(); + } + if (mLiveLinkMicPresenter != null) { + mLiveLinkMicPresenter.release(); + } + mLiveMusicViewHolder = null; + mLiveReadyViewHolder = null; + mLivePushViewHolder = null; + mLiveLinkMicPresenter = null; + //断开socket + if (mSocketSwClient != null) { + mSocketSwClient.disConnect(); + } + super.release(); + } + + private boolean isKeyBack = false; + + @Override + public boolean onKeyUp(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK) { + isKeyBack = true; + } + return super.onKeyUp(keyCode, event); + } + + @Override + protected void onDestroy() { + if (manager != null) { + manager.release(); + } + LiveHttpUtil.cancel(LiveHttpConsts.ANCHOR_CHECK_LIVE); + super.onDestroy(); + if (mLivePushViewHolder != null) { + mLivePushViewHolder.onDestroy(); + } + if (mLiveReadyViewHolder != null) { + mLiveReadyViewHolder.onDestroy(); + } + if (mLiveAnchorViewHolder != null) { + mLiveAnchorViewHolder.onDestroy(); + } + mLivePushViewHolder = null; + mLiveReadyViewHolder = null; + mLiveAnchorViewHolder = null; + if (MicStatusManager.getInstance().isAnchorOpenRoom()) { + MicStatusManager.getInstance().closeMic(mContext); + } + L.e("LiveAnchorActivity-------onDestroy------->"); + RandomPkManager.getInstance().unregisterOnRandomPkTimer(onRandomPkTimer); + Bus.getOff(this); + } + + + @Override + protected void onPause() { +// if (mLiveRoomViewHolder != null) { +// mLiveRoomViewHolder.anchorPause(); +// } + super.onPause(); +// if (isKeyBack) { +// sendSystemMessage(mContext.getString(R.string.live_anchor_leave)); +// } +// mPaused = true; + } + + @Override + protected void onResume() { + super.onResume(); +// if (mPaused) { +// if (mLiveRoomViewHolder != null) { +// mLiveRoomViewHolder.anchorResume(); +// } +// sendSystemMessage(mContext.getString(R.string.live_anchor_come_back)); +// CommonHttpUtil.checkTokenInvalid(); +// } +// mPaused = false; + } + + + /** + * 直播间 主播登录失效 + */ + @Override + public void onAnchorInvalid() { + super.onAnchorInvalid(); + endLive(); + } + + /** + * 超管关闭直播间 + */ + @Override + public void onSuperCloseLive() { + endLive(); + DialogUitl.showSimpleTipDialog(mContext, mContext.getString(R.string.live_illegal)); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLoginInvalidEvent(LoginInvalidEvent e) { + release(); + } + + public void setBtnFunctionDark() { + if (mLiveAnchorViewHolder != null) { + mLiveAnchorViewHolder.setBtnFunctionDark(); + } + } + + /** + * 主播与主播连麦 主播收到其他主播发过来的连麦申请 + */ + @Override + public void onLinkMicAnchorApply(UserBean u, String stream) { + if (mLiveLinkMicAnchorPresenter != null) { + mLiveLinkMicAnchorPresenter.onLinkMicAnchorApply(u, stream); + } + } + + /** + * 主播与主播连麦 对方主播拒绝连麦的回调 + */ + @Override + public void onLinkMicAnchorRefuse() { + if (mLiveLinkMicAnchorPresenter != null) { + mLiveLinkMicAnchorPresenter.onLinkMicAnchorRefuse(); + } + } + + /** + * 主播与主播连麦 对方主播无响应的回调 + */ + @Override + public void onLinkMicAnchorNotResponse() { + if (mLiveLinkMicAnchorPresenter != null) { + mLiveLinkMicAnchorPresenter.onLinkMicNotResponse(); + } + } + + /** + * 主播与主播连麦 对方主播正在游戏 + */ + @Override + public void onlinkMicPlayGaming() { + if (mLiveLinkMicAnchorPresenter != null) { + mLiveLinkMicAnchorPresenter.onlinkMicPlayGaming(); + } + } + + + /** + * 主播与主播连麦 对方主播正在忙的回调 + */ + @Override + public void onLinkMicAnchorBusy() { + if (mLiveLinkMicAnchorPresenter != null) { + mLiveLinkMicAnchorPresenter.onLinkMicAnchorBusy(); + } + } + + /** + * 发起主播连麦PK申请 + * + * @param pkUid 对方主播的uid + * @param stream 对方主播的stream + */ + public void linkMicAnchorApply(String pkUid, String stream) { + JSONObject msg1 = buildLinkMicJSON(); + linkMicAnchorApply(pkUid, stream, false); + } + + public JSONObject buildLinkMicJSON() { + JSONObject msg1 = new JSONObject(); + msg1.put("uid", CommonAppConfig.getInstance().getUid()); + msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); + msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()); + return msg1; + } + + public void linkMicAnchorApply(final String pkUid, String stream, boolean extra) { + + LiveHttpUtil.livePkCheckLive(pkUid, stream, mStream, new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (obj.getString("ispk").equals("0")) { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 1) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", pkUid) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + //判断是否是随机PK + if(extra){ + msg1.param("random_pk", "1"); + msg1.param("msgtype","11"); + if (RandomPkManager.getInstance().isRankModel()) { + msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + } + } + msg1.create(); + + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain("g" + pkUid, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("tx", "发送成功"); + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "发送失败" + errorCode.getMessage()); + + } + }); + } else { + ToastUtil.show("主播正在PK,稍後再試"); + if (RandomPkManager.getInstance().isRandomModel()) { + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); + } + } + } + } + } + }); + + + } + + /** + * 发起多人主播连麦PK申请 + * + * @param pkUid 对方主播的uid + * @param stream 对方主播的stream (无需steam) + */ + public void linkDrMicAnchorApply(String pkUid, String stream) { + linkDrMicAnchorApply(pkUid, stream, SOCKET_LIVE_DRPK); + if (mLiveAnchorViewHolder != null) { + mLiveAnchorViewHolder.setYaoqing(pkUid); + } + } + + /** + * 发起多人主播连麦PK申请 + * + * @param pkUid 对方主播的uid + * @param stream 对方主播的stream (无需steam) + * @param extra PK类型 + */ + public void linkDrMicAnchorApply(final String pkUid, String stream, String extra) { + + LiveHttpUtil.livePkCheckLive(pkUid, stream, mStream, new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (obj.getString("ispk").equals("0")) { + + // TODO: 2024/4/19 邀请主播进行多人连麦 + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LIVE_DRPK) + .param("action", 1) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", pkUid) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + + String targetId = "g" + pkUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(message.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + } else { + ToastUtil.show("主播正在PK,稍後再試"); + } + } + } + } + }); + + + } + + /** + * 设置连麦pk按钮是否可见 + */ + public void setPkBtnVisible(boolean visible) { + if (mLiveAnchorViewHolder != null) { + if (visible) { + if (mLiveLinkMicAnchorPresenter.isLinkMic()) { + mLiveAnchorViewHolder.setPkBtnVisible(true); + } + } else { + mLiveAnchorViewHolder.setPkBtnVisible(false); + } + } + } + + /** + * 发起主播连麦pk + */ + public void applyLinkMicPk() { + String pkUid = null; + if (mLiveLinkMicAnchorPresenter != null) { + pkUid = mLiveLinkMicAnchorPresenter.getPkUid(); + } + if (!TextUtils.isEmpty(pkUid) && mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.applyLinkMicPk(pkUid, mStream); + } + } + + /** + * 主播与主播PK 主播收到对方主播发过来的PK申请的回调 + * + * @param u 对方主播的信息 + * @param stream 对方主播的stream + */ + @Override + public void onLinkMicPkApply(UserBean u, String stream, int forwhat) { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkApply(u, stream, 0); + } + } + + //多人PK接受 + @Override + public void onLinkDRMicPkApply(UserBean u) { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkDRMicPkApply(u); + } + } + + @Override + public void onLinkDRMicPKToUser(UserBean u) { + + } + + //多人PK接受 + @Override + public void onLinkDRMicPkApplyOk(UserBean u) { + L.eSw("onLinkDRMicPkApplyOk111111"); + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkDRMicPkApplyOk(u); + } + } + + /** + * 主播与主播PK 对方主播拒绝pk的回调 + */ + @Override + public void onLinkMicPkRefuse() { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkRefuse(); + } + } + + /** + * 主播与主播PK 对方主播正在忙的回调 + */ + @Override + public void onLinkMicPkBusy() { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkBusy(); + } + } + + /** + * 主播与主播PK 对方主播无响应的回调 + */ + @Override + public void onLinkMicPkNotResponse() { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkNotResponse(); + } + } + + @Override + public void onLinkMicToPk(String uid, String pkhead, String pkname) { + + } + + @Override + public void prankTurntable(String msgtype, int time, JSONObject jsonObject) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.closeAndOpenTrickery(msgtype, time, jsonObject); + } + } + + + /** + * 腾讯sdk连麦时候主播混流 + */ + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLinkMicTxMixStreamEvent(LinkMicTxMixStreamEvent e) { + + } + + /** + * 主播checkLive + */ + public void checkLive() { + if (mCheckLiveCallback == null) { + mCheckLiveCallback = new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + int status = JSON.parseObject(info[0]).getIntValue("status"); + printLog(DateFormatUtil.getCurTimeString2() + " <=== " + mReqCount + "----status=" + status + "\n"); + if (status == 0) { + NotCancelableDialog dialog = new NotCancelableDialog(); + dialog.setContent(mContext.getString(R.string.live_anchor_error)); + dialog.setActionListener(new NotCancelableDialog.ActionListener() { + @Override + public void onConfirmClick(Context context, DialogFragment dialog) { + dialog.dismiss(); + release(); + superBackPressed(); + } + }); + dialog.show(getSupportFragmentManager(), "VersionUpdateDialog"); + } + } + } + }; + } + mReqCount++; + printLog(DateFormatUtil.getCurTimeString2() + " ===> " + mReqCount + "\n"); + LiveHttpUtil.anchorCheckLive(mLiveUid, mStream, mCheckLiveCallback); + } + + @Override + public void onSendGift(LiveReceiveGiftBean bean, SendBlindGiftEvent event) { + if (event != null) { + LiveChatBean liveChatBean = null; + if (!TextUtils.isEmpty(event.isBlindBoxStatus()) && TextUtils.equals(event.isBlindBoxStatus(), "true")) { + if (!TextUtils.isEmpty(event.getDressName()) && !TextUtils.isEmpty(event.getDressMsg())) { + liveChatBean = new LiveChatBean(); + liveChatBean.setUserNiceName(event.getUserNiceName()); + liveChatBean.setType(LiveChatBean.BLIND_BOX); + liveChatBean.setGiftName(event.getDressName()); + liveChatBean.setContent(event.getDressMsg()); + } + //插入盲盒礼物消息 + bean.getLiveChatBean().setType(LiveChatBean.BLIND_BOX); + bean.getLiveChatBean().setContent(WordUtil.isNewZh() ? event.getGiftMsg() : event.getGiftMsgen()); + bean.getLiveChatBean().setGiftName(WordUtil.isNewZh() ? event.getGiftname() : event.getGiftname_en()); + bean.getLiveChatBean().setUserNiceName(event.getUserNiceName()); + } + + + if (mLiveRoomViewHolder != null) { + if (bean.getmLiveUId().equals(bean.getRoomnum())) { + if (liveChatBean != null) { + mLiveRoomViewHolder.insertChat(liveChatBean, 1); + } + mLiveRoomViewHolder.insertChat(bean.getLiveChatBean(), 1); + } + mLiveRoomViewHolder.showGiftMessage(bean, false); + mLiveRoomViewHolder.updataWishList(bean.getGiftId(), bean.getGiftCount()); + } + } else { + //购买守护 + if (bean.ismTypeBuyGuard()) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.showGuardGifMessage(bean); + } + } else { + + if (mLiveRoomViewHolder != null) { + if (bean.getmLiveUId().equals(bean.getRoomnum())) { + mLiveRoomViewHolder.insertChat(bean.getLiveChatBean(), 1); + } + mLiveRoomViewHolder.showGiftMessage(bean, false); + mLiveRoomViewHolder.updataWishList(bean.getGiftId(), bean.getGiftCount()); + } + + } + } + + } + + private void printLog(String content) { + if (mLogFile == null) { + File dir = new File(CommonAppConfig.LOG_PATH); + if (!dir.exists()) { + dir.mkdirs(); + } + mLogFile = new File(dir, DateFormatUtil.getCurTimeString2() + "_" + mLiveUid + "_" + mStream + ".txt"); + } + L.e(TAG, content); + LogUtil.print(mLogFile, content); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onOpenDrawer(LiveAudienceEvent event) { + Bundle bundle = new Bundle(); + IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); + switch (event.getType()) { + case LIVE_WKS: + String weeklyStarUrl = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" + + userInfo.getId() + + "&token=" + userInfo.getToken() + "&anchorUid=" + mLiveUid; + ZhuangBanActivity.forward(mContext, weeklyStarUrl, false, 0); + break; + case WISH_LIST: + LiveWishListDialogFragment4Audience fragment4Audience = new LiveWishListDialogFragment4Audience(); + bundle.putString(Constants.LIVE_UID, mLiveUid); + fragment4Audience.setArguments(bundle); + if (mContext instanceof LiveSwAnchorActivity) { + fragment4Audience.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveWishListDialogFragment4Audience"); + } + break; + case UN_LEAVELIVE: + if (leave == 1) { + leaveLive(); + } + break; + case LINK_MIC: + if (!StringUtil.isEmpty(((LinkMicUserBean) event.getObject()).getId())) { + mMicQueueList.put(((LinkMicUserBean) event.getObject()).getId(), (LinkMicUserBean) event.getObject()); + } + if (micListener != null) { + micListener.updateMicList(mMicQueueList); + DialogUitl.showSimpleDialog(mContext, + String.format(mContext.getString(R.string.live_mic_user_apply), ((LinkMicUserBean) event.getObject()).getUserNicename()), + new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + openMicWindow(2); + dialog.dismiss(); + } + } + ); + } + break; + case LINK_MIC_CANCEL: + mMicQueueList.remove(((LinkMicUserBean) event.getObject()).getId()); + if (micListener != null) { + micListener.updateMicList(mMicQueueList); + } + break; + case LINK_MIC_UPDATE_MIC_LIST: + List list = (List) event.getObject(); + mMicQueueList.clear(); + for (LinkMicUserBean bean : list) { + if (!StringUtil.isEmpty(bean.getId())) { + mMicQueueList.put(bean.getId(), bean); + } + } + if (micListener != null) { + micListener.updateMicList(mMicQueueList); + } + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.updataMicList(list); + Log.i("多人连麦", "onOpenDrawer: " + list.size()); + for (LinkMicUserBean userBean : list) { + Log.i("多人连麦", "u list: " + userBean.toString()); + } + } + break; + case LINK_MIC_UPDATE_AUDIENCE_LIST: + mAudienceList = (List) event.getObject(); + if (micListener != null) { + micListener.updateAudienceList(mAudienceList); + } + break; + case LINK_MIC_CLOSE: + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.updataCleanMic(); + } + break; + case LEAVE_DR_ROOM: + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.leaveDRRoom(); + } + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.seisShowGif(true); + mLiveRoomViewHolder.endDRGif(); + } +// if (mLiveRoomViewHolder != null) { +// mLiveRoomViewHolder.hotAddVisibility(false); +// } + break; + case LEAVE_PK_SCORE: + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.upDataPkScore(event.getPkScores(), event.getUid(), event.getTime()); + } + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.seisShowGif(true); + } +// if (mLiveRoomViewHolder != null) { +// mLiveRoomViewHolder.hotAddVisibility(true); +// } + break; + case PK_TIME_COUNT: + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.endDRGif(); + } + break; + case DISCONNEXT_PK_TIME: + if (mLivePushViewHolder != null) { + //mLivePushViewHolder.changeToBig(); + mLivePushViewHolder.anchorClose(); + mLiveSwLinkMicPkPresenter.leaveDRRoom(); + } + break; + case AI_AUTOMATIC_SPEECH: + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.aiAutomaticSpeech((event.getAiAutomaticSpeechModel())); + } + break; + case UPDATA_ROBOT: + getAiRobotStatus(); + break; + //主播强制下播 + case LIVE_END: + endLive(); + break; + case RED_PACKET: + if (manager != null) { + mLiveRoomViewHolder.redPacketManage(event.getRedPacketModel()); + } + break; + case BLIND_BOX: + if (mLiveRoomViewHolder != null) { + if (event.getAllServerNotifyEvent().isRedPacket()) + mLiveRoomViewHolder.blindBoxAllServerNotify(event.getAllServerNotifyEvent()); + } + break; + case GIFT_WALL: + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.showGiftWall(event.getUid(), event.isVoicePress(), event.getUname(), event.getAvatar()); + } + break; + case INPUT_DIALOG: + LiveInputDialogFragment liveInputDialogFragment = new LiveInputDialogFragment(); + Bundle liveInputBundle = new Bundle(); + liveInputBundle.putString(Constants.LIVE_DANMU_PRICE, mDanmuPrice); + liveInputBundle.putString(Constants.COIN_NAME, mCoinName); + liveInputBundle.putString(Constants.LIVE_UID, mLiveUid); + liveInputBundle.putString(Constants.LIVE_STREAM, mStream); + liveInputBundle.putString(Constants.LIVE_UID, mLiveUid); + if (event.getOlineUserlistModel() == null) { + liveInputBundle.putString("TagUser", ""); + } else { + liveInputBundle.putString("TagUser", GsonUtils.toJson(event.getOlineUserlistModel())); + } + liveInputDialogFragment.setArguments(liveInputBundle); + liveInputDialogFragment.show(getSupportFragmentManager(), "LiveInputDialogFragment"); + break; + + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSendMoneyLongModel(SendMoneyLongModel sendMoneyLongModel) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.onSendMoneyLongModel(sendMoneyLongModel); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSendMoneyLongEndEvent(SendMoneyLongEndEvent sendMoneyLongModel) { + Log.e("DateRemindModel", sendMoneyLongModel.toString()); + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.onSendMoneyLongEndEvent(sendMoneyLongModel); + } + + + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void GiftWallIlluminateEvent(GiftWallIlluminateEvent event) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.setGiftWall(String.valueOf(event.getNewNumber()), String.valueOf(event.getMaxNumber())); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onShowHideEvent(ShowHideEvent event) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.onShowHideEvent(); + + } + } + + /** + * 检查指定直播间连麦人数 + * + * @param mLiveUid 直播间 + */ + public static void checkMicUserLength(String mLiveUid, LiveFunctionClickListener listener) { + LiveHttpUtil.getMicList(mLiveUid, 0, new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + try { + JSONObject obj = JSON.parseObject(info[0]); + List list = JSON.parseArray(obj.getString("userlist"), MicUserBean.class); + listener.onClick(list.size()); + } catch (Exception e) { + e.printStackTrace(); + } + + } + } + }); + } + + /** + * 获取机器人配置;取得求关注时间间隔 + */ + private long robotTime = 0; + + private void getAiRobotStatus() { + Log.e("随机打招呼", "((((((((((((((((((((((((((((((((((((((((((((((("); + LiveNetManager.get(mContext) + .getAiRobotStatus(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveAiRobotBean data) { + Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((" + data.toString()); + if (data.getStatus() == 1) { + if (robotRunnable != null) { + robotHandler.removeCallbacks(robotRunnable); + robotRunnable = null; + } + robotRunnable = new Runnable() { + @Override + public void run() { + Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((data.getName())" + data.getName()); + String robotName = data.getName(); + //发送消息 + LiveNetManager.get(mContext) + .getAiRobotBody(LiveAiRobotBean.Message.TYPE_FOLLOW, + new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List messageList) { + Random random = new Random(); + int randNumber = random.nextInt(messageList.size()) - 1; + if (randNumber < 0) { + randNumber = 0; + } + Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((data.randNumber())" + randNumber); + Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((data)" + messageList.toString()); + sendRobotMessage(robotName, messageList.get(randNumber).getContent()); + } + + @Override + public void onError(String error) { + Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((data.error())" + error); + } + }); + + } + }; + robotTime = data.getTime() * 60 * 1000; + Log.e("随机打招呼", "(((((((((((((((((((((((((((((((((((((((((((((((robotTime)" + robotTime); + robotHandler.postDelayed(robotRunnable, robotTime); + } + } + + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); + } + + //机器人求关注轮询器 + private Handler robotHandler = new Handler(); + private Runnable robotRunnable = null; + + /** + * '{"msg": + * [{"_method_":"aiAutomaticSpeech", + * "ct":{"name_color":"#f19ec2","ai_name":"'+_this.robotInfo.ai_name+'", + * "content":"'+content+'","user_name":"", + * "icon":"https://downs.yaoulive.com/xzs_tab.png", + * "system_bubble":"https://downs.yaoulive.com/xzs_qipao.9.png"}, + * "msgtype":"10"}],"retcode":"000000","retmsg":"OK"}' + */ + private void sendRobotMessage(String name, String content) { + Log.e("随机打招呼", name + "==========00000000000000++++" + content); + AiAutomaticSpeechModel aiAutomaticSpeechModel = new AiAutomaticSpeechModel(); + aiAutomaticSpeechModel.setAiName(name) + .setIcon("https://downs.yaoulive.com/xzs_tab.png") + .setNameColor("#f19ec2") + .setSystemBubble("https://downs.yaoulive.com/xzs_qipao.9.png") + .setUserName("") + .setContent(content); + SocketSendBean msg = + new SocketSendBean() + .param("_method_", "aiAutomaticSpeechNew") + .param("msgtype", "10") + .param("ct", GsonUtils.toJson(aiAutomaticSpeechModel, AiAutomaticSpeechModel.class)); + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + robotHandler.postDelayed(robotRunnable, robotTime); + } + + private LiveSudGamePopup liveSudGamePopupXPopup = null; + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLiveSudGamePopupShowOrHideEvent(LiveSudGamePopupShowOrHideEvent event) { + switch (event.getType()) { + case 0: + if (liveSudGamePopupXPopup == null) { + liveSudGamePopupXPopup = new LiveSudGamePopup(mContext, event.getCreateSudRoomModel()); + new XPopup.Builder(mContext) + .enableDrag(false) + .dismissOnTouchOutside(false) + .dismissOnBackPressed(false) + .asCustom(liveSudGamePopupXPopup).show(); + } else { + if (liveSudGamePopupXPopup != null) { + liveSudGamePopupXPopup.dialog.show(); + } + } + + + break; + + case 1: + if (liveSudGamePopupXPopup != null) { + liveSudGamePopupXPopup.dialog.hide(); + } + + break; + case 2: + if (liveSudGamePopupXPopup != null) { + liveSudGamePopupXPopup.BusGetOff(); + liveSudGamePopupXPopup.dialog.dismiss(); + liveSudGamePopupXPopup = null; + } + break; + } + + + } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onAllServerNotifyFFGGGDJANEvent(AllServerNotifyFFGGGDJANEvent event) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.showAllServerNotifyFFGGGD(event,false); + } + } +} diff --git a/live/src/main/java/com/yunbao/live/activity/LiveTRTCAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveTRTCAnchorActivity.java index 0db3b6e73..6f99feee7 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveTRTCAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveTRTCAnchorActivity.java @@ -213,7 +213,7 @@ public class LiveTRTCAnchorActivity extends TRTCBaseActivity { return; } String title = mEditTitle.getText().toString().trim(); - LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, null,0, new HttpCallback() { + LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, null,0,false, new HttpCallback() { @Override public void onSuccess(int code, String msg, final String[] info) { if (code == 0 && info.length > 0) { diff --git a/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java b/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java index 42ce00194..a9f9b3138 100644 --- a/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java @@ -197,8 +197,8 @@ public class PDLIiveChatActivity extends FragmentActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/live/src/main/java/com/yunbao/live/activity/WebViewActivityMedal.java b/live/src/main/java/com/yunbao/live/activity/WebViewActivityMedal.java index 3a762d003..3d6e6e089 100644 --- a/live/src/main/java/com/yunbao/live/activity/WebViewActivityMedal.java +++ b/live/src/main/java/com/yunbao/live/activity/WebViewActivityMedal.java @@ -172,7 +172,7 @@ public class WebViewActivityMedal extends AbsActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -180,7 +180,7 @@ public class WebViewActivityMedal extends AbsActivity { MicStatusManager.getInstance().showDownMicDialog(mContext); return; } - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); finish(); } diff --git a/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java b/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java index c55118a49..1ce6a9acd 100644 --- a/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java @@ -409,7 +409,7 @@ public class ZhuangBanActivity extends AbsActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -426,7 +426,7 @@ public class ZhuangBanActivity extends AbsActivity { EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal))); finish(); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } finish(); } diff --git a/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java b/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java index 05b04fc0d..b5bff9e8b 100644 --- a/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java @@ -21,7 +21,6 @@ import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.bean.BaseModel; -import com.yunbao.common.bean.LevelBean; import com.yunbao.common.bean.UserBean; import com.yunbao.common.custom.CommonRefreshView; import com.yunbao.common.dialog.AbsDialogFragment; @@ -37,6 +36,7 @@ import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.socket.SocketSendBean; +import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.utils.LiveTextRender; import java.net.MalformedURLException; @@ -173,7 +173,7 @@ public class AnchorUserMicInfoAdapter extends RefreshAdapter { /** * 发送IM消息 * - * @param action 4为同意请求,1为邀请,其余见 {@link com.yunbao.live.socket.SocketRyClient} Constants.LIAN_MAI解析 + * @param action 4为同意请求,1为邀请,其余见 {@link SocketSwClient} Constants.LIAN_MAI解析 */ void applyMic(UserBean bean, int action, SocketSendBean msg) { msg.param("action", action); diff --git a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java index 3f2a0cbf6..065f13413 100644 --- a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java @@ -22,6 +22,7 @@ import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import java.util.Arrays; import java.util.HashMap; @@ -35,6 +36,7 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { private static final int ITEM = 2; private int freePkNum;//PK次数 private int mDrPkNum = -1;//多人PK剩余次数,为-1则认为是单人PK + private String liveUid; public void setFreePkNum(int freePkNum) { this.freePkNum = freePkNum; @@ -48,6 +50,10 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { this.mDrPkNum = mDrPkNum; } + public void setLiveUid(String liveUid) { + this.liveUid = liveUid; + } + @NonNull @Override public HeadViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -128,8 +134,7 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { ToastUtil.show(mContext.getString(R.string.free_pk_num_null)); // return; } - - LiveHttpUtil.getMicList(LiveRyAnchorActivity.mLiveUid, 0, new com.yunbao.common.http.HttpCallback() { + LiveHttpUtil.getMicList(liveUid, 0, new com.yunbao.common.http.HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); @@ -142,8 +147,14 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { ToastUtil.show("invite " + bean.getUserNiceName() + " successful"); } mOnItemClickListener.onItemClick(bean, -1); - ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), - false); + if(mContext instanceof LiveSwAnchorActivity){ + ((LiveSwAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), + false); + }else{ + ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), + ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() + ); + } return; } if (mDrPkNum <= 0) { @@ -156,7 +167,11 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { } yaoqing.put(bean.getId(), bean.getId()); if (yaoqing.size() < 5) { - ((LiveRyAnchorActivity) mContext).linkDrMicAnchorApply(bean.getId(), bean.getId()); + if(mContext instanceof LiveSwAnchorActivity){ + ((LiveSwAnchorActivity) mContext).linkDrMicAnchorApply(bean.getId(), bean.getId()); + }else{ + ((LiveRyAnchorActivity) mContext).linkDrMicAnchorApply(bean.getId(), bean.getId()); + } } else { ToastUtil.show(WordUtil.isNewZh() ? "多人PK最大參與人數為4人" : "The maximum number of participants in a multiplayer PK is 4 people"); } diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveFunctionAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveFunctionAdapter.java index 338c84bb9..167dd8a0f 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveFunctionAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveFunctionAdapter.java @@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.Constants; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.bean.LiveFunctionBean; import java.util.ArrayList; @@ -38,11 +38,10 @@ public class LiveFunctionAdapter extends RecyclerView.Adapter mLiveRoomHandler.postDelayed(() -> ((LiveRyAnchorActivity) (mContext)).mLiveRoomViewHolder.initAnchorSayData(), 1000)).showDialog(); + new LiveAnchorSayPopDialog(mContext).setLiveUid(liveUid).setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(LiveAnchorSayModel bean, int position) { + mLiveRoomHandler.postDelayed(new Runnable() { + @Override + public void run() { + if (mContext instanceof LiveSwAnchorActivity) { + ((LiveSwAnchorActivity) (mContext)).mLiveRoomViewHolder.initAnchorSayData(); + } else { + ((LiveRyAnchorActivity) (mContext)).mLiveRoomViewHolder.initAnchorSayData(); + } + } + }, 1000); + } + }).showDialog(); } else if (id == R.id.live_tool_qa) { new LiveAnchorCreateQADialog(mContext).setLiveUid(liveUid).showDialog(); } else if (id == R.id.live_tool_game) { - LiveNetManager.get(mContext) - .getCustomSidebarInfo("1", new HttpCallback>() { - @Override - public void onSuccess(List data) { - for (CustomSidebarInfoModel datum : data) { - if (datum.getType().equals("6")) { - //直播间来的 - new XPopup.Builder(mContext) - .enableDrag(false) - .moveUpToKeyboard(false) + LiveNetManager.get(mContext).getCustomSidebarInfo("1", new HttpCallback>() { + @Override + public void onSuccess(List data) { + for (CustomSidebarInfoModel datum : data) { + if (datum.getType().equals("6")) { + //直播间来的 + new XPopup.Builder(mContext).enableDrag(false).moveUpToKeyboard(false) // .dismissOnTouchOutside(false) // .dismissOnBackPressed(false) - .asCustom(new SudGameListPopup(mContext, 0, datum.getChild(), liveUid)) + .asCustom(new SudGameListPopup(mContext, 0, datum.getChild(), liveUid)) - .show(); - return; - } - } + .show(); + return; } + } + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); dismiss(); } } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java index af918e29c..915b38355 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java @@ -42,7 +42,7 @@ import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.GuardRightAdapter; import com.yunbao.live.adapter.LiveNewGuardBuyItemsAdapter; import com.yunbao.live.bean.GuardBuyBean; @@ -305,7 +305,7 @@ public class LiveNewGuardBuyDialogFragment extends AbsDialogFragment implements private void gotoBack() { dismiss(); - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); } /** diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveNewWishListDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveNewWishListDialogFragment.java index b1a7905d0..6f56ecd5b 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveNewWishListDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveNewWishListDialogFragment.java @@ -25,7 +25,7 @@ import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveAnchorActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.LiveNewWishListAdapter; import com.yunbao.live.bean.LiveWishlistBean; import com.yunbao.live.event.LiveAudienceEvent; @@ -119,7 +119,7 @@ public class LiveNewWishListDialogFragment extends AbsDialogFragment implements @Override public void onSuccess(int code, String msg, String[] info) { if (code == 0 && info.length > 0) { - ToastUtil.show(WordUtil.isNewZh()?"修改成功":"Success"); + ToastUtil.show(WordUtil.isNewZh() ? "修改成功" : "Success"); dismiss(); } else { ToastUtil.show("修改失败" + (msg.isEmpty() ? "" : msg)); @@ -178,17 +178,16 @@ public class LiveNewWishListDialogFragment extends AbsDialogFragment implements } - /** * 心愿单打开礼物窗口 */ public void openGiftWindow() { LiveGiftDialogFragment4Wishlist fragment = new LiveGiftDialogFragment4Wishlist(); - Log.e("ry",getTag()); - if(getTag().equals("TX")) { + Log.e("ry", getTag()); + if (mContext instanceof LiveSwAnchorActivity) { + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + } else { fragment.show(((LiveAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); - }else{ - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); } } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java index 21f31a484..c2aff85c3 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java @@ -145,7 +145,7 @@ public class LiveOldUserDialogFragment extends AbsDialogFragment implements View LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java index 79d4166a1..4ab67742a 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java @@ -52,7 +52,7 @@ import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveReportActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.utils.LiveTextRender; @@ -663,7 +663,7 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -722,7 +722,7 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On } else if (i == R.id.btn_guard) { if (TextUtils.equals(mLiveUid, "uid")) return; MobclickAgent.onEvent(mContext, "anchor_avatar_guard", "守护按钮"); - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity, mToUid); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity, mToUid); } else if (i == R.id.btn_live) { gotoLive(mToUid); } else if (i == R.id.noble_icon_layout) { diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java index 5f68adfbb..cc589f42e 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java @@ -36,7 +36,7 @@ import com.yunbao.common.http.HttpCallback; import com.yunbao.common.utils.DpUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.UserMoreInfoAdapter; import com.yunbao.live.bean.LiveGuardInfo; import com.yunbao.common.http.LiveHttpUtil; @@ -144,7 +144,7 @@ public class LiveUserMoreDialogFragment extends AbsDialogFragment implements Vie ((LiveActivity) mContext).openLuckGiftTip(); } else if (Tips.equals("2")) { dismiss(); - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); } else if (Tips.equals("3")) { dismiss(); ((LiveActivity) mContext).openFansWindow(); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveWishListDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveWishListDialogFragment.java index 12eb62dd7..616fdd1f0 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveWishListDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveWishListDialogFragment.java @@ -22,6 +22,7 @@ import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveAnchorActivity; import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.LiveWishListAdapter; import com.yunbao.live.bean.LiveWishlistBean; import com.yunbao.common.http.LiveHttpConsts; @@ -192,8 +193,8 @@ public class LiveWishListDialogFragment extends AbsDialogFragment implements OnI public void openGiftWindow() { LiveGiftDialogFragment4Wishlist fragment = new LiveGiftDialogFragment4Wishlist(); Log.e("ry",getTag()); - if(getTag().equals("TX")) { - fragment.show(((LiveAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + if(mContext instanceof LiveSwAnchorActivity){ + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); }else{ fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); } diff --git a/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java index f5c7f0666..5112dd593 100644 --- a/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java @@ -23,6 +23,7 @@ import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.common.manager.RandomPkManager; import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.common.http.LiveHttpUtil; import java.util.Arrays; @@ -36,6 +37,7 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On private TextView mPkBtnTitle; private TextView mPkBtnDesc; private ImageView mRandomPkSwitch; + private boolean isSw ; private final RandomPkManager.OnRandomPkTimer randomPkTimer = new RandomPkManager.OnRandomPkTimer() { @@ -124,6 +126,7 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); + isSw = getArguments().getBoolean("isSw"); initView(); initData(); RandomPkManager.debugUid = null; @@ -260,14 +263,13 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On } else { ToastUtil.show("The random PK switch is not enabled"); } - return; } if ((mPkBtn.getTag() != null && (boolean) mPkBtn.getTag()) || RandomPkManager.getInstance().isRequestPk()) { RandomPkManager.getInstance().exitPk(); return; } - LiveHttpUtil.getMicList(LiveRyAnchorActivity.mLiveUid, 0, new HttpCallback() { + LiveHttpUtil.getMicList(isSw?LiveSwAnchorActivity.mLiveUid: LiveRyAnchorActivity.mLiveUid, 0, new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); diff --git a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index 55e5044e4..30de0e49e 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -489,7 +489,8 @@ public class LiveAudienceEvent extends BaseModel { UPDATE_FANS_TASK_STATUS(74, "更新粉丝任务状态"), SUD_GAME_CREATE_ROOM(75, "主播创建sud游戏"), PK_RANK_START(76, "PK排位赛开始"), - GuardSpecialEffect(77, "PK排位赛开始"); + GuardSpecialEffect(77, "PK排位赛开始"), + LIVE_DIALOG_ANCHOR_TIPS(78, "主播公会赛tips"); private int type; private String name; diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java index b73e45d18..1696e56af 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java @@ -452,7 +452,7 @@ public class LiveGiftAnimPresenter { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 8357e9d30..4c4f563ed 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -29,7 +29,6 @@ import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; @@ -38,7 +37,6 @@ import android.widget.TextView; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.google.gson.Gson; import com.tencent.trtc.TRTCCloud; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.LiveInfoModel; @@ -51,10 +49,10 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.RandomPkManager; +import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; -import com.yunbao.common.utils.L; import com.yunbao.common.utils.ScreenDimenUtil; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; @@ -62,18 +60,14 @@ import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.activity.LiveRyAnchorActivity; -import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.bean.LivePKUserListBean; import com.yunbao.live.custom.ProgressTextView; import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.live.event.LiveOpenSuccessEvent; -import com.yunbao.live.event.LivePKRightUserInfoEvent; import com.yunbao.live.interfaces.ILiveLinkMicViewHolder; import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketRyLinkMicPkUtil; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.views.LiveLinkMicPkViewHolder; -import com.yunbao.live.views.LivePlayRyViewHolder; import com.yunbao.live.views.LivePushRyViewHolder; import org.greenrobot.eventbus.EventBus; @@ -102,7 +96,6 @@ import cn.rongcloud.rtc.base.RCRTCMediaType; import cn.rongcloud.rtc.base.RCRTCRoomType; import cn.rongcloud.rtc.base.RCRTCStream; import cn.rongcloud.rtc.base.RTCErrorCode; -import io.agora.beautyapi.faceunity.agora.SWManager; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; @@ -167,8 +160,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public static List inputStreamList1 = new ArrayList<>(); private boolean DRInitiator = false;//是否是duorenPK发起人 - private List drPkbeans = new ArrayList<>(); - public LiveRyLinkMicPkPresenter setDRInitiator(boolean DRInitiator) { this.DRInitiator = DRInitiator; return this; @@ -403,34 +394,50 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { Log.i("tts2", s1); mLiveLinkMicPkViewHolder.setTime(s + " " + s1); if (s1.equals("00:01") && mIsAnchor && !s.contains("懲罰")) { - HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK").params("uid", CommonAppConfig.getInstance().getUid()).params("addtime", "00:00").params("type", "0").params("sign", "1").execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - JSONObject datas = JSONObject.parseObject(info[0]); + HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("addtime", "00:00") + .params("type", "0") + .params("sign", "1") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + JSONObject datas = JSONObject.parseObject(info[0]); - SocketSendBean seed_msg = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); - seed_msg.create(); - String pkUid = datas.getString("pkuid"); - Log.i("seed", seed_msg.mResult.toString()); + SocketSendBean seed_msg = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 9) + .param("msgtype", 10) + .param("win_uid", datas.getString("win_uid")) + .param("uid", CommonAppConfig.getInstance().getUid()); + seed_msg.create(); + String pkUid = datas.getString("pkuid"); + Log.i("seed", seed_msg.mResult.toString()); - Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid")); + Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid")); - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2") + .params("GroupId", "g" + pkUid) + .params("jsonstr", seed_msg.mResult.toString()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2") + .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) + .params("jsonstr", seed_msg.mResult.toString()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + } + }); + } + }); - } - }); } - }); - - } - } - }); + } + }); } } @@ -517,44 +524,137 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { /** * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 */ + public void onLinkDRMicPkApplyOk(UserBean u) { - L.eSw("onLinkDRMicPkApplyOk(UserBean u) " + u.getUserNiceName()); - int index = 0; - if (livePushRyViewHolder != null) { - livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); - } - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 3) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("type", 3) - .param("uid", u.getId()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - - String targetId = "g" + CommonAppConfig.getInstance().getUid(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + /** + * 加入副房间 + * + * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 + * + * @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_` + * @param callBack 加入房间回调 + * @group 房间管理 + */ + RCRTCEngine.getInstance().joinOtherRoom("" + u.getId(), new IRCRTCResultDataCallback() { @Override - public void onAttached(io.rong.imlib.model.Message message) { + public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { + rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); + runOnUiThread(new Runnable() { + @Override + public void run() { + //遍历远端用户列表 + for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { + //遍历远端用户发布的资源列表 + for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { + if (stream.getMediaType() == RCRTCMediaType.VIDEO) { + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + if (i == 1) { + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(mContext); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); + //todo 本demo只演示添加1个远端用户的视图 + livePushRyViewHolder.mPreView1.removeAllViews(); + remoteView.setScalingType(SCALE_ASPECT_FILL); + livePushRyViewHolder.mPreView1.addView(remoteView); + + } else if (i == 2) { + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 +// RCRTCVideoView remoteView = new RCRTCVideoView(mContext); +// ((RCRTCVideoInputStream) stream).setVideoView(remoteView); +// //todo 本demo只演示添加1个远端用户的视图 +// LivePushRyViewHolder.dr2_preview.removeAllViews(); +// remoteView.setScalingType(SCALE_ASPECT_FILL); +// LivePushRyViewHolder.dr2_preview.addView(remoteView); + } else if (i == 3) { + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 +// RCRTCVideoView remoteView = new RCRTCVideoView(mContext); +// ((RCRTCVideoInputStream) stream).setVideoView(remoteView); +// //todo 本demo只演示添加1个远端用户的视图 +// LivePushRyViewHolder.dr3_preview.removeAllViews(); +// remoteView.setScalingType(SCALE_ASPECT_FILL); +// LivePushRyViewHolder.dr3_preview.addView(remoteView); + } else if (i == 4) { + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 +// RCRTCVideoView remoteView = new RCRTCVideoView(mContext); +// ((RCRTCVideoInputStream) stream).setVideoView(remoteView); +// //todo 本demo只演示添加1个远端用户的视图 +// LivePushRyViewHolder.dr4_preview.removeAllViews(); +// remoteView.setScalingType(SCALE_ASPECT_FILL); +// LivePushRyViewHolder.dr4_preview.addView(remoteView); + } + //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 + inputStreamList.add(stream); + } + //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 + inputStreamList1.add(stream); + } + } + //开始订阅资源 + rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.i("ry", "订阅资源成功"); + + RCRTCMixConfig config = new RCRTCMixConfig(); + RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); + config.setMediaConfig(mediaConfig); + //视频输出配置 + RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); + mediaConfig.setVideoConfig(videoConfig); + //大流视频的输出参数 + RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); + videoConfig.setVideoLayout(normal); + //推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 + //如不设置宽高值则服务端将使用默认宽高 360 * 640 + //例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, + //所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 + RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); + int fps = defaultVideoConfig.getVideoFps().getFps(); + int width = 960; + int height = 720; + normal.setWidth(width); //视频宽 + normal.setHeight(height); //视频高 + normal.setFps(fps); //视频帧率 + + //1. 设置自适应合流布局模式 + config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); + //2. 合流画布设置 + if (rcrtcLiveInfo != null) { + rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "混成功" + u.getId()); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); + + } + }); + } else { + Log.w("PkDebug", "PK合流失败,rcrtcLiveInfo为空"); + } + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + }); + } + }); } @Override - public void onSuccess(io.rong.imlib.model.Message message) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason()); } }); - dRjoinOtherRoom(u); + } /** @@ -584,21 +684,129 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void onLinkMicToPk(UserBean u) { EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar())); Log.e("eve", u.getId() + ""); - L.eSw("主播接受了主播的PK邀請"); + /** + * 加入副房间 + * + * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 + * + * @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_` + * @param callBack 加入房间回调 + * @group 房间管理 + */ RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + RCRTCEngine.getInstance().joinOtherRoom(u.getId(), new IRCRTCResultDataCallback() { + @Override + public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { + rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + //遍历远端用户列表 + for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { + //遍历远端用户发布的资源列表 + for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { + Log.e("ry", stream.getMediaType() + "类型"); + if (stream.getMediaType() == RCRTCMediaType.VIDEO) { + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + livePushRyViewHolder.mPreView1.removeAllViews(); + remoteView.setScalingType(SCALE_ASPECT_FILL); + livePushRyViewHolder.mPreView1.addView(remoteView); + } + //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 + inputStreamList.add(stream); + + + RCRTCMixConfig config = new RCRTCMixConfig(); + RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); + config.setMediaConfig(mediaConfig); +//视频输出配置 + RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); + mediaConfig.setVideoConfig(videoConfig); +//大流视频的输出参数 + RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); + videoConfig.setVideoLayout(normal); +//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 +//如不设置宽高值则服务端将使用默认宽高 360 * 640 +//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, +//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 + RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); + int fps = defaultVideoConfig.getVideoFps().getFps(); + int width = 960; + int height = 720; + normal.setWidth(width); //视频宽 + normal.setHeight(height); //视频高 + normal.setFps(fps); //视频帧率 + + //1. 设置自适应合流布局模式 + config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); + //2. 合流画布设置 + if (rcrtcLiveInfo == null) { + Log.w("PkDebug", "PK合流失败,rcrtcLiveInfo为空"); + } + rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "混成功13"); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); + + } + }); + } + } + //开始订阅资源 + rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.i("ry", "订阅资源成功"); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + }); + } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.i("ry", "11111加入其他房间失败 :" + rtcErrorCode.getReason()); + } + }); LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); LiveRyAnchorActivity.isDRPK = 1; - livePushRyViewHolder.setAnPkRtc(u);//设置对方主播视图 + ScreenDimenUtil util = ScreenDimenUtil.getInstance(); + int mScreenWdith = util.getScreenWdith(); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); + params.weight = 1; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + livePushRyViewHolder.camera.setLayoutParams(params); + livePushRyViewHolder.mPreView1.setLayoutParams(params); + livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 4).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", u.getId()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", u.getAvatar()).param("pkname", u.getUserNiceName()); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 4) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", u.getId()) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", u.getAvatar()) + .param("pkname", u.getUserNiceName()); msg1.create(); - LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); - /*Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain("g" + CommonAppConfig.getInstance().getUid(), conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -614,12 +822,11 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { Log.e("tx", "发送失败" + errorCode.getMessage()); } - });*/ + }); } private void isPK(UserBean bean) { - EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar())); ScreenDimenUtil util = ScreenDimenUtil.getInstance(); int mScreenWdith = util.getScreenWdith(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); @@ -631,56 +838,127 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); LiveRyAnchorActivity.isDRPK = 1; - /*---------------------------------------------------------------- */ - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 2) //回复PK申请 2 - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", bean.getId()) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - if (RandomPkManager.getInstance().isRankModel()) { - L.eSw("排位赛"); - msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + JSONObject msg1 = new JSONObject(); + msg1.put("uid", CommonAppConfig.getInstance().getUid()); + msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); + msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb()); + msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar())); + + if (bean != null && bean.isRandomPk()) { + msg1.put("random_pk", bean.isRandomPk() ? 1 : 0); + msg1.put("is_ladders", bean.getRankPkImgUrl()); } - msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); - msg1.create(); System.out.println("PK回执 = " + msg1.toString()); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain( bean.getId(), conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() { @Override - public void onAttached(io.rong.imlib.model.Message message) { + public void onSuccess() { + RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback() { + @Override + public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { + rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { + //遍历远端用户发布的资源列表 + for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { + if (stream.getMediaType() == RCRTCMediaType.VIDEO) { + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + livePushRyViewHolder.mPreView1.removeAllViews(); + remoteView.setScalingType(SCALE_ASPECT_FILL); + livePushRyViewHolder.mPreView1.addView(remoteView); + } + //如果要订阅所有远端用户的流。保存所有流信息,方便后面统一订阅 + inputStreamList.add(stream); + } + } + Log.e("ry", "asa" + inputStreamList.size()); + //开始订阅资源 + rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.i("ry", "订阅资源成功"); + List streams = new ArrayList<>(); + streams.add(RCRTCEngine.getInstance().getDefaultVideoStream()); + RCRTCMixConfig config = new RCRTCMixConfig(); + RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); + config.setMediaConfig(mediaConfig); +//视频输出配置 + RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); + mediaConfig.setVideoConfig(videoConfig); +//大流视频的输出参数 + RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); + videoConfig.setVideoLayout(normal); +//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 +//如不设置宽高值则服务端将使用默认宽高 360 * 640 +//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, +//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 + RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); + int fps = defaultVideoConfig.getVideoFps().getFps(); + int width = 960; + int height = 720; + normal.setWidth(width); //视频宽 + normal.setHeight(height); //视频高 + normal.setFps(fps); //视频帧率 + + //1. 设置自适应合流布局模式 + config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); + //2. 合流画布设置 + rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "混成功14"); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); + + } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.i("ry", "订阅资源失败: " + rtcErrorCode); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + }); + } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); + Log.i("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); + } + }); + + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); + LiveRyAnchorActivity.isDRPK = 1; + LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); + SocketRyLinkMicPkUtil.linkMicPkAccept(mSocketRyClient, mApplyUid, mApplyUrl, mApplyNmae); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid)); + onLinkMicPkStart(mApplyUid, 2); + } + }); } @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("tx", "发送成功"); - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "发送失败" + errorCode.getMessage()); - + public void onFailed(RTCErrorCode errorCode) { + ToastUtil.show("接受失败"); } }); - // TODO: 2024/4/12 视图渲染 - livePushRyViewHolder.setAnPkRtc(bean); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); - LiveRyAnchorActivity.isDRPK = 1; - LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); - SocketRyLinkMicPkUtil.linkMicPkAccept(mSocketRyClient, mApplyUid, mApplyUrl, mApplyNmae); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid)); - onLinkMicPkStart(mApplyUid, 2); - } - }); } //与用户连麦 @@ -772,9 +1050,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { isPK(u); } else { if (mPkWaitCount < 0) { - if(rtcRoom==null){ - return; - } rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { @Override @@ -784,7 +1059,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 8); msg1.create(); String targetId = u.getId(); @@ -792,7 +1069,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -864,12 +1141,82 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void run() { if (btn_close != null) { btn_close.setVisibility(View.GONE); - livePushRyViewHolder.timeTitle.setVisibility(View.GONE); } } }); - livePushRyViewHolder.exitChannelDrPk(drPkbeans); - leaveHandler.removeCallbacks(leaveRunnable); + + for (int i = 0; i < inputStreamList.size(); i++) { + Log.e("ry", "退出多人ID" + inputStreamList.get(i).getUserId()); + //退出副房间 + RCRTCEngine.getInstance().leaveOtherRoom(inputStreamList.get(i).getUserId(), true, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "退出多人成功"); + + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", "退出多人失败" + rtcErrorCode); + + } + }); + } + + + RCRTCMixConfig config = new RCRTCMixConfig(); + RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); + config.setMediaConfig(mediaConfig); +//视频输出配置 + RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); + mediaConfig.setVideoConfig(videoConfig); +//大流视频的输出参数 + RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); + videoConfig.setVideoLayout(normal); +//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 +//如不设置宽高值则服务端将使用默认宽高 360 * 640 +//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, +//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 + RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); + int fps = defaultVideoConfig.getVideoFps().getFps(); + int width = 720; + int height = 1280; + normal.setWidth(width); //视频宽 + normal.setHeight(height); //视频高 + normal.setFps(fps); //视频帧率 + + //2. 合流画布设置 + //(请参照画布和声音配置示例代码) + //3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高 + ArrayList list = new ArrayList<>(); + config.setCustomLayouts(list); + //user1的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + list.add(videoLayout1); + videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video + videoLayout1.setX(0); //X 坐标 + videoLayout1.setY(0); //Y 坐标 + videoLayout1.setWidth(720); // 视频窗口的宽 + videoLayout1.setHeight(1280); // 视频窗口的高 + //2. 合流画布设置 + if (rcrtcLiveInfo != null) { + rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "混成功15"); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); + + } + }); + + } + + leaveHandler.post(leaveRunnable); + } private Handler leaveHandler = new Handler(Looper.getMainLooper()); @@ -877,12 +1224,15 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void run() { //恢复全屏画面 + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + params.topMargin = 0; + livePushRyViewHolder.camera.setLayoutParams(params); livePushRyViewHolder.dr_pk_view.setVisibility(View.GONE); + inputStreamList.clear(); + inputStreamList1.clear(); //删除之前其他主播的画面 livePushRyViewHolder.dr1_preview.removeAllViews(); - livePushRyViewHolder.dr2_preview.removeAllViews(); livePushRyViewHolder.dr3_preview.removeAllViews(); - livePushRyViewHolder.dr4_preview.removeAllViews(); livePushRyViewHolder.cameraPreview3.removeAllViews(); leaveHandler.removeCallbacks(leaveRunnable); livePushRyViewHolder.timeTitle.setVisibility(View.GONE); @@ -895,70 +1245,82 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 随机PK拒绝对话框 */ public void showPkDialog(UserBean u) { - new DialogUitl.Builder(mContext).setHtmlCode(Html.fromHtml("有人向您发起PK请求。
" + "若拒绝PK,将会10分钟内不会再收到任何随机PK请求。")).setConfirmString("接受").setCancelString("拒絕").setView(R.layout.dialog_live_random_pk).setSimpleCallbackView(new DialogUitl.SimpleCallbackView() { - boolean clickCancel = false; - String titleVal; - TimerTask task; - - @Override - public void onShow(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - task = new TimerTask() { - int time = 11; - final Handler handler = new Handler(Looper.getMainLooper()); + new DialogUitl.Builder(mContext) + .setHtmlCode(Html.fromHtml( + "有人向您发起PK请求。
" + + "若拒绝PK,将会10分钟内不会再收到任何随机PK请求。" + )) + .setConfirmString("接受") + .setCancelString("拒絕") + .setView(R.layout.dialog_live_random_pk) + .setSimpleCallbackView(new DialogUitl.SimpleCallbackView() { + boolean clickCancel = false; + String titleVal; + TimerTask task; @Override - public void run() { - if (titleVal == null) { - titleVal = ((TextView) title).getText().toString(); - } - handler.post(() -> ((TextView) title).setText(titleVal + " " + time)); - if (time-- == 0) { - handler.post(() -> showClose(dialog, title, context, confirmBtn, cancelBtn)); - cancel(); - } + public void onShow(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + task = new TimerTask() { + int time = 11; + final Handler handler = new Handler(Looper.getMainLooper()); + + @Override + public void run() { + if (titleVal == null) { + titleVal = ((TextView) title).getText().toString(); + } + handler.post(() -> ((TextView) title).setText(titleVal + " " + time)); + if (time-- == 0) { + handler.post(() -> showClose(dialog, title, context, confirmBtn, cancelBtn)); + cancel(); + } + } + }; + new Timer().schedule(task, 1000, 1000); } - }; - new Timer().schedule(task, 1000, 1000); - } - @Override - public void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - dialog.dismiss(); - task.cancel(); - apply(); - } + @Override + public void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + dialog.dismiss(); + task.cancel(); + apply(); + } - @Override - public void onCancel(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - if (!clickCancel) { - titleVal = "拒絕PK提示"; - ((TextView) context).setText(Html.fromHtml("若拒絕PK,將會關閉你的隨機PK開關。
" + "並且10分鍾不會收到任何隨機PK請求。
")); - ((TextView) cancelBtn).setText("堅持拒絕"); - clickCancel = true; - return; - } - showClose(dialog, title, context, confirmBtn, cancelBtn); - } + @Override + public void onCancel(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + if (!clickCancel) { + titleVal = "拒絕PK提示"; + ((TextView) context).setText(Html.fromHtml( + "若拒絕PK,將會關閉你的隨機PK開關。
" + + "並且10分鍾不會收到任何隨機PK請求。
" + )); + ((TextView) cancelBtn).setText("堅持拒絕"); + clickCancel = true; + return; + } + showClose(dialog, title, context, confirmBtn, cancelBtn); + } - void showClose(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { - task.cancel(); - ((TextView) title).setText("您因拒絕隨機PK,被限制關閉中"); - ((TextView) confirmBtn).setText("确定"); - ((TextView) context).setText("隨機PK可打開時間:" + new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis() + 7200000)));//7200000ms=120m=2h - ((TextView) context).setTextSize(12); - ((TextView) context).setTextColor(Color.parseColor("#999999")); - refusePk(u); - cancelBtn.setVisibility(View.GONE); - confirmBtn.setOnClickListener(v -> { - dialog.dismiss(); - }); - } + void showClose(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + task.cancel(); + ((TextView) title).setText("您因拒絕隨機PK,被限制關閉中"); + ((TextView) confirmBtn).setText("确定"); + ((TextView) context).setText("隨機PK可打開時間:" + new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis() + 7200000)));//7200000ms=120m=2h + ((TextView) context).setTextSize(12); + ((TextView) context).setTextColor(Color.parseColor("#999999")); + refusePk(u); + cancelBtn.setVisibility(View.GONE); + confirmBtn.setOnClickListener(v -> { + dialog.dismiss(); + }); + } - void apply() { - isPK(u); - } - }).build().show(); + void apply() { + isPK(u); + } + }) + .build().show(); } private void refusePk(UserBean u) { @@ -971,7 +1333,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) // .param("randomPk",u.isRandomPk()+"") .param("action", 3); msg1.create(); @@ -981,7 +1344,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -1006,7 +1369,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { LiveNetManager.get(mContext).setBanRandomPK(null); } - /** * 显示申请多人PK的弹窗 */ @@ -1030,215 +1392,135 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } if (mAcceptPk) { - HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive").params("uid", CommonAppConfig.getInstance().getUid()).params("pkuid", u.getId()).params("type", "1").params("sign", "1").execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msgs, String[] info) { - if (code == 0) { - Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); - HttpClient.getInstance().get("live.getdrnum", "live.getdrnum").execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - if (info.length > 0) { - JSONObject datas = JSONObject.parseObject(info[0]); - boolean agree = true; - if (datas.getIntValue("pk_num_day") <= 0) { - ToastUtil.show("多人PK次数已用完"); - agree = false; - } - boolean finalAgree = agree; - if (finalAgree) { - HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", u.getId()).execute(new HttpCallback() { + HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("pkuid", u.getId()) + .params("type", "1") + .params("sign", "1") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msgs, String[] info) { + if (code == 0) { + Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); + HttpClient.getInstance().get("live.getdrnum", "live.getdrnum") + .execute(new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { - L.eSw("多人PK" + "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - if (info.length == 0) { - return; - } - JSONObject obj = JSONObject.parseObject(info[0]); - drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - SWManager.get().setDimensions(3);//加入成功后,将分别率设置为 VD_320x240 - //将自己从多人pk列表里剔除 - int removeIndex = -1; - for (int i = 0; i < drPkbeans.size(); i++) { - if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - removeIndex = i; + Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + if (info.length > 0) { + + JSONObject datas = JSONObject.parseObject(info[0]); + boolean agree = true; + if (datas.getIntValue("pk_num_day") <= 0) { + ToastUtil.show("多人PK次数已用完"); + agree = false; } - } - if (removeIndex != -1) { - drPkbeans.remove(removeIndex); - L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); - } + boolean finalAgree = agree; + IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, agree, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + if (finalAgree == true) { + HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("roomid", u.getId()) + .execute(new HttpCallback() { - HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (info.length > 0) { - JSONObject obj = JSONObject.parseObject(info[0]); - drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - for (int i = 0; i < drPkbeans.size(); i++) { - if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 2) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 2) - .param("uid", drPkbeans.get(i).getId()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - L.eSw("uiduiduiduiduiduiduiduid"+drPkbeans.get(i).getId()); - String targetId = String.valueOf(drPkbeans.get(i).getId()); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i("多人PK", "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LIVE_DRPK) + .param("action", 10) + .param("uid", CommonAppConfig.getInstance().getUid()); + msg1.create(); + String targetId = "g" + CommonAppConfig.getInstance().getUid(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - } + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - } + } - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } - // - int index = livePushRyViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗"); + } + }); + if (info.length == 0) { + return; + } + JSONObject obj = JSONObject.parseObject(info[0]); + JSONArray users = obj.getJSONArray("userlist"); - L.eSw("onLinkDRMicPkApplyOk(UserBean u)-点击接收 1 " + u.getUserNiceName()); - L.eSw("發送action = 2"); + //添加水印 +// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f); +// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect); + dRjoinOtherRoom(u.getId(), 1); - } + for (int i = 0; i < users.size(); i++) { + JSONObject user = users.getJSONObject(i); + Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); + if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { + if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { + /** + * 向指定用户发送跨房间连麦请求 + *

+ * 1: inviterAutoMix为true时: + * + * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 + * + * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 + * + * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 + *

+ */ + IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { + @Override + public void onSuccess() { + } - if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 3) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 3) - .param("uid", drPkbeans.get(i).getId()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - L.eSw("發送給自己直播間"+drPkbeans.get(i).getId()); - String targetId = "g" + CommonAppConfig.getInstance().getUid(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + @Override + public void onFailed(RTCErrorCode errorCode) { - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); - } - - - if(!mApplyUid.equals(String.valueOf(drPkbeans.get(i).getId()))&&!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))){ - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 3) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 3) - .param("uid", drPkbeans.get(i).getId()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - L.eSw("發送給其他主播直播间"+drPkbeans.get(i).getId()); - String targetId = "g" + drPkbeans.get(i).getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); - } + } + }); + } + } + } + } + }); } - dRjoinOtherRoom(u); } - } - }); - - /*for (int i = 0; i < users.size(); i++) { - JSONObject user = users.getJSONObject(i); - Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { - *//** - * 向指定用户发送跨房间连麦请求 - *

- * 1: inviterAutoMix为true时: - * - * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 - * - * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 - * - * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 - *

- *//* - IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - }); + @Override + public void onFailed(RTCErrorCode errorCode) { + ToastUtil.show("接受失败"); } - } - }*/ + }); + } else { + ToastUtil.show(msg); + } } + }); - } - } else { - ToastUtil.show(msg); - } + + } - - }); - - - } - } - }); + } + }); } else { @@ -1252,7 +1534,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 8); msg1.create(); String targetId = u.getId(); @@ -1260,7 +1544,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -1292,7 +1576,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 3); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 3); msg1.create(); String targetId = u.getId(); @@ -1300,7 +1586,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -1336,134 +1622,190 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } - public void setMyDrPkDetailsView() { - if (detailsView1 != null) { - livePushRyViewHolder.dr1_preview.removeView(detailsView1); - } - detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); - linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); - imageGrade1 = detailsView1.findViewById(R.id.image_grade1); - textGrade1 = detailsView1.findViewById(R.id.text_grade1); - textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.dr1_preview.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.GONE); - linearGrade1.setVisibility(View.GONE); - } - - - public void setPkUserInfoView(UserBean userBean){ - - } //多人PK接受申请画 加入副房间 - public void dRjoinOtherRoom(UserBean u) { - setMyDrPkDetailsView(); - HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { + public void dRjoinOtherRoom(String uid, int i) { + Log.e("ry", uid + "洒洒" + i + "VVVV" + i); + mApplyUid = uid; + RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback() { @Override - public void onSuccess(int code, String msg, String[] info) { - if (info.length > 0) { - JSONObject obj = JSONObject.parseObject(info[0]); - drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - int removeIndex = -1; - for (int i = 0; i < drPkbeans.size(); i++) { - if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - removeIndex = i; + public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { + rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + //把多人PK的View显示出来 + if (livePushRyViewHolder.dr_pk_view.getVisibility() == View.GONE) { + ScreenDimenUtil util = ScreenDimenUtil.getInstance(); + int mScreenWdith = util.getScreenWdith(); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); + params.weight = 1; + params.topMargin = DpUtil.dp2px(123); + livePushRyViewHolder.dr_pk_view.setLayoutParams(params); + livePushRyViewHolder.camera.setLayoutParams(params); + livePushRyViewHolder.dr_pk_view.setVisibility(View.VISIBLE); + livePushRyViewHolder.dr1_preview.setVisibility(View.GONE); + livePushRyViewHolder.dr2_preview.setVisibility(View.GONE); + livePushRyViewHolder.dr3_preview.setVisibility(View.GONE); + livePushRyViewHolder.dr4_preview.setVisibility(View.GONE); + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); + linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); + imageGrade1 = detailsView1.findViewById(R.id.image_grade1); + textGrade1 = detailsView1.findViewById(R.id.text_grade1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + livePushRyViewHolder.mPreView.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.GONE); } + + Log.e("ry", "多人接受成功" + mApplyUid); + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); + //遍历远端用户列表 + for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { + Log.e("ry", rcrtcOtherRoom.getRemoteUsers().get(i).getUserId() + "收到rcrtcOtherRoom" + rcrtcOtherRoom.getRemoteUsers().size()); + //遍历远端用户发布的资源列表 + for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { + Log.e("ry", i + "收到" + stream.getMediaType() + "实打实打算" + rcrtcOtherRoom.getRemoteUsers().get(i).getUserId()); + if (stream.getMediaType() == RCRTCMediaType.VIDEO) { + if (inputStreamList.size() == 0) { + livePushRyViewHolder.dr1_preview.setVisibility(View.VISIBLE); + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(mContext); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + livePushRyViewHolder.dr1_preview.removeAllViews(); + remoteView.setScalingType(SCALE_ASPECT_FILL); + livePushRyViewHolder.dr1_preview.addView(remoteView); + + + LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(String.valueOf(uid)); + textPkName2.setText(data.getUserNicename()); + livePushRyViewHolder.dr1_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.GONE); + } + + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + } + }); + + } else if (inputStreamList.size() == 1) { + livePushRyViewHolder.dr3_preview.setVisibility(View.VISIBLE); + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(mContext); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + livePushRyViewHolder.dr3_preview.removeAllViews(); + remoteView.setScalingType(SCALE_ASPECT_FILL); + livePushRyViewHolder.dr3_preview.addView(remoteView); + LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(uid); + textPkName4.setText(data.getUserNicename()); + livePushRyViewHolder.dr3_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.GONE); + } + + @Override + public void onError(String error) { + + } + }); + } else if (inputStreamList.size() == 2) { + livePushRyViewHolder.cameraPreview3.setVisibility(View.VISIBLE); + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(mContext); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + livePushRyViewHolder.cameraPreview3.removeAllViews(); + remoteView.setScalingType(SCALE_ASPECT_FILL); + livePushRyViewHolder.cameraPreview3.addView(remoteView); + + LiveNetManager.get(mContext).getLiveInfo(uid, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); + linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); + textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); + imageGrade3 = detailsView3.findViewById(R.id.image_grade3); + textGrade3 = detailsView3.findViewById(R.id.text_grade3); + imageGrade3.setTag(uid); + textPkName3.setText(data.getUserNicename()); + livePushRyViewHolder.cameraPreview3.addView(detailsView3); + detailsLinearLayout3.setVisibility(View.VISIBLE); + linearGrade3.setVisibility(View.GONE); + } + + @Override + public void onError(String error) { + + } + }); + } + inputStreamList.add(stream); + } + inputStreamList1.add(stream); + } + } + //开始订阅资源 + rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.i("ry", "订阅资源成功"); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + }); + //2. 合流画布设置 + rcrtcLiveInfo.setMixConfig(create_Custom_MixConfig(false, inputStreamList), new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "222混成功"); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); + + } + }); + } - if (removeIndex != -1) { - drPkbeans.remove(removeIndex); - } - setDrPkUserInfoView(drPkbeans); - } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); + Log.i("ry", mApplyUid + "加入其他房间失败 :" + rtcErrorCode); } }); } - private void setDrPkUserInfoView(List drPkbeanList) { - L.eSw("setDrPkUserInfoView" + new Gson().toJson(drPkbeanList)); - mHandler.postDelayed(new Runnable() { - @Override - public void run() { - for (int j = 0; j < drPkbeanList.size(); j++) { - if (j == 0) { - L.eSw("j == 0:" + j); - //设置多人PK数据 - if (detailsView2 != null) { - livePushRyViewHolder.dr2_preview.removeView(detailsView2); - } - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(String.valueOf(drPkbeanList.get(0).getId())); - textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); - livePushRyViewHolder.dr2_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.GONE); - linearGrade2.setVisibility(View.GONE); - } else if (j == 1) { - L.eSw("j == 1:" + j); - if (detailsView4 != null) { - livePushRyViewHolder.dr4_preview.removeView(detailsView4); - } - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(String.valueOf(drPkbeanList.get(1).getId())); - textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); - livePushRyViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.GONE); - linearGrade4.setVisibility(View.GONE); - } else if (j == 2) { - L.eSw("j == 2:" + j); - - if (detailsView4 != null) { - livePushRyViewHolder.dr4_preview.removeView(detailsView4); - } - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(String.valueOf(drPkbeanList.get(2).getId())); - textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); - livePushRyViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.GONE); - linearGrade4.setVisibility(View.GONE); - - if (detailsView3 != null) { - livePushRyViewHolder.dr3_preview.removeView(detailsView3); - } - detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); - linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); - textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); - imageGrade3 = detailsView3.findViewById(R.id.image_grade3); - textGrade3 = detailsView3.findViewById(R.id.text_grade3); - imageGrade3.setTag(String.valueOf(drPkbeanList.get(1).getId())); - textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); - livePushRyViewHolder.dr3_preview.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.GONE); - linearGrade3.setVisibility(View.GONE); - - - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - - } - } - } - }, 2000); - L.eSw("dRjoinOtherRoom:size:" + drPkbeanList.size() + " json " + new Gson().toJson(drPkbeanList)); - - } - /** * 多人PK PK主播发过来的已经接受 */ @@ -1479,7 +1821,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * @group 房间管理 */ - /*RCRTCEngine.getInstance().joinOtherRoom(u, new IRCRTCResultDataCallback() { + RCRTCEngine.getInstance().joinOtherRoom(u, new IRCRTCResultDataCallback() { @Override public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); @@ -1653,7 +1995,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { public void onFailed(RTCErrorCode rtcErrorCode) { Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason()); } - });*/ + }); } @@ -1905,7 +2247,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 主播与主播PK 所有人收到PK开始的回调 */ public void onLinkMicPkStart(String pkUid, int i) { - L.eSw("onLinkMicPkStart pkUid "+pkUid+" "+i); Log.d("tag", i + "mPkTimeCount2"); mIsPk = true; hideSendPkWait(); @@ -1914,7 +2255,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mPkUid = pkUid; mApplyUid = null; mApplyStream = null; - isDRPK=1; if (mLiveLinkMicPkViewHolder == null) { mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); mLiveLinkMicPkViewHolder.addToParent(); @@ -1922,15 +2262,17 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).getmLivePlayViewHolder().setPkview(); } + } mLiveLinkMicPkViewHolder.startAnim(); EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(pkUid)); mLiveLinkMicPkViewHolder.showTime(); mPkTimeCount = 100; - nextPkTimeCountDown(2);//时间倒计时 + nextPkTimeCountDown(2); if (mIsAnchor) { ((LiveRyAnchorActivity) mContext).setPkBtnVisible(false); mPkTimeCount = PK_TIME_MAX; + } else { // mPkTimeCount=mPkTimeFromServer; mPkTimeCount = PK_TIME_MAX; @@ -2004,6 +2346,45 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } }); +// inputStreamList.clear(); + RCRTCMixConfig config = new RCRTCMixConfig(); + RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); + config.setMediaConfig(mediaConfig); + //视频输出配置 + RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); + mediaConfig.setVideoConfig(videoConfig); +//大流视频的输出参数 + RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); + videoConfig.setVideoLayout(normal); +//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 +//如不设置宽高值则服务端将使用默认宽高 360 * 640 +//例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, +//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 + RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); + int fps = defaultVideoConfig.getVideoFps().getFps(); + int width = 720; + int height = 1280; + normal.setWidth(width); //视频宽 + normal.setHeight(height); //视频高 + normal.setFps(fps); //视频帧率 + + //1. 设置自适应合流布局模式 + config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.ADAPTIVE); + //2. 合流画布设置 + if (rcrtcLiveInfo != null) { + rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "混成功16"); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); + + } + }); + } runOnUiThread(new Runnable() { public void run() { @@ -2118,7 +2499,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 更新Pk分数 */ public void upDataPkScore(JSONArray pkScores, String uid, int time) { - L.eSw("更新Pk分数 upDataPkScore time:" + time + " " + pkScores); String userID1 = (String) imageGrade1.getTag(); String userID2 = (String) imageGrade2.getTag(); String userID4 = (String) imageGrade4.getTag(); @@ -2131,18 +2511,15 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { String pkTime = StringUtil.getDurationText(time * 1000); livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime)); mPkTimeCount = time; - if (time > 0) { + if (time>0){ String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); mHandler.sendEmptyMessage(WHAT_PK_TIME2); } + } int pkScoreSize = pkScores.size(); if (pkScoreSize == 3) { - detailsLinearLayout1.setVisibility(View.VISIBLE); - detailsLinearLayout2.setVisibility(View.VISIBLE); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.VISIBLE); linearGrade2.setVisibility(View.VISIBLE); linearGrade4.setVisibility(View.VISIBLE); @@ -2218,12 +2595,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } else { String userID3 = (String) imageGrade3.getTag(); - - detailsLinearLayout1.setVisibility(View.VISIBLE); - detailsLinearLayout2.setVisibility(View.VISIBLE); - detailsLinearLayout3.setVisibility(View.VISIBLE); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.VISIBLE); linearGrade2.setVisibility(View.VISIBLE); linearGrade3.setVisibility(View.VISIBLE); @@ -2342,7 +2713,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); } - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); // endDRGif(); if (DRInitiator) { LiveNetManager.get(mContext).jieshuDRPK("" + IMLoginManager.get(mContext).getUserInfo().getId()); diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java new file mode 100644 index 000000000..0eefc39f1 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -0,0 +1,2324 @@ +package com.yunbao.live.presenter; + +import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; +import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; +import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; +import static com.yunbao.live.activity.LiveSwAnchorActivity.PKing; +import static com.yunbao.live.activity.LiveSwAnchorActivity.isDRPK; +import static com.yunbao.live.views.LivePushSwViewHolder.btn_close; +import static com.yunbao.live.views.LivePushSwViewHolder.rtcRoom; + +import android.app.Dialog; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.drawable.ColorDrawable; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.os.SystemClock; +import android.text.Html; +import android.text.TextUtils; +import android.util.Log; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.PopupWindow; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; +import com.tencent.trtc.TRTCCloud; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.event.AnchorInfoEvent; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.manager.IMRTCManager; +import com.yunbao.common.manager.RandomPkManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.ScreenDimenUtil; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; +import com.yunbao.live.bean.DrPkbean; +import com.yunbao.live.bean.LivePKUserListBean; +import com.yunbao.live.custom.ProgressTextView; +import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.interfaces.ILiveLinkMicViewHolder; +import com.yunbao.live.socket.SocketSwClient; +import com.yunbao.live.socket.SocketSwLinkMicPkUtil; +import com.yunbao.live.socket.SocketSendBean; +import com.yunbao.live.views.LiveLinkMicPkViewHolder; +import com.yunbao.live.views.LivePushSwViewHolder; + +import org.greenrobot.eventbus.EventBus; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.Timer; +import java.util.TimerTask; + +import cn.rongcloud.rtc.api.RCRTCEngine; +import cn.rongcloud.rtc.api.RCRTCMixConfig; +import cn.rongcloud.rtc.api.RCRTCOtherRoom; +import cn.rongcloud.rtc.api.RCRTCRemoteUser; +import cn.rongcloud.rtc.api.callback.IRCRTCOtherRoomEventsListener; +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; +import cn.rongcloud.rtc.api.stream.RCRTCInputStream; +import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; +import cn.rongcloud.rtc.base.RCRTCMediaType; +import cn.rongcloud.rtc.base.RCRTCRoomType; +import cn.rongcloud.rtc.base.RTCErrorCode; +import io.agora.beautyapi.faceunity.agora.SWManager; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.message.TextMessage; + +//import cn.rongcloud.rtc.jni.video.RCRect; + +/** + * Created by cxf on 2018/11/16. + * 主播与主播PK逻辑 + */ + +public class LiveSwLinkMicPkPresenter implements View.OnClickListener { + + private static final int WHAT_PK_WAIT_RECEIVE = 0;//收到pk申请等待 what + private static final int WHAT_PK_WAIT_SEND = 1;//发送pk申请等待 what + private static final int WHAT_PK_TIME = 2;//pk时间变化 what + private static final int WHAT_PK_TIME2 = 22;//pk时间变化 what + private static final int LINK_MIC_COUNT_MAX = 10; + private static int PK_TIME_MAX = 60 * 15;//pk时间 15分钟 + private static final int PK_TIME_MAX_2 = 60;//惩罚时间 1分钟 + private Context mContext; + private View mRoot; + private boolean mIsAnchor;//自己是否是主播 + private SocketSwClient mSocketRyClient; + private ViewGroup mPkContainer; + private boolean mIsApplyDialogShow;//是否显示了申请PK的弹窗 + private boolean mAcceptPk;//是否接受连麦 + private boolean mIsPk;//是否已经Pk了 + public static String mApplyUid;//正在申请Pk的主播的uid + private String mApplyUrl;//正在申请Pk的主播的头像 + private String mApplyNmae;//正在申请Pk的主播的名字 + private String mApplyStream;//正在申请Pk的主播的stream + private String mLiveUid;//自己主播的uid + private String mUrl;//主播的头像 + public static String mPkUid;//正在Pk的对方主播的uid + public static String oldmPkUid;//正在Pk的对方主播的uid + private ProgressTextView mLinkMicWaitProgress; + private int mPkWaitCount;//Pk弹窗等待倒计时Live + private int mPkTimeCount;//pk时间 + private PopupWindow mPkPopWindow; + private Handler mHandler; + private LiveLinkMicPkViewHolder mLiveLinkMicPkViewHolder; + private String mPkTimeString1; + private String mPkTimeString2; + private boolean mIsPkEnd;//pk是否结束,进入惩罚时间 + private boolean mPkSend;//pk请求是否已经发送 + private int mPkSendWaitCount;//发送pk请求后的等待时间 + private String mSelfStream; + private int mPkTimeFromServer; + public static TRTCCloud mTRTCCloud1; + private View detailsView1, detailsView2, detailsView3, detailsView4; + private LinearLayout detailsLinearLayout1, detailsLinearLayout2, detailsLinearLayout3, detailsLinearLayout4; + private LinearLayout linearGrade1, linearGrade2, linearGrade3, linearGrade4; + private TextView textPkName1, textPkName2, textPkName3, textPkName4; + private TextView textGrade1, textGrade2, textGrade3, textGrade4; + private ImageView imageGrade1, imageGrade2, imageGrade3, imageGrade4; + + public LivePushSwViewHolder livePushRyViewHolder; + + public static List inputStreamList = new ArrayList<>(); + public static List inputStreamList1 = new ArrayList<>(); + private boolean DRInitiator = false;//是否是duorenPK发起人 + + private List drPkbeans = new ArrayList<>(); + + public LiveSwLinkMicPkPresenter setDRInitiator(boolean DRInitiator) { + this.DRInitiator = DRInitiator; + return this; + } + + private IRCRTCOtherRoomEventsListener otherRoomEventsListener = new IRCRTCOtherRoomEventsListener() { + + @Override + public void onRemoteUserPublishResource(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, List streams) { + } + + @Override + public void onRemoteUserMuteAudio(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { + } + + @Override + public void onRemoteUserMuteVideo(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { + } + + @Override + public void onRemoteUserUnpublishResource(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, List streams) { + } + + @Override + public void onUserJoined(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) { + } + + @Override + public void onUserLeft(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) { + } + + @Override + public void onUserOffline(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) { + RCRTCEngine.getInstance().leaveOtherRoom(room.getRoomId(), true, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + } + }); + } + + @Override + public void onLeaveRoom(RCRTCOtherRoom room, int reasonCode) { + Log.d("RYM_DG", "Other onLeaveRoom: room = " + room.getRoomId()); + } + }; + + public LiveSwLinkMicPkPresenter(Context context, ILiveLinkMicViewHolder linkMicViewHolder, boolean isAnchor, View root) { + mContext = context; + mIsAnchor = isAnchor; + mRoot = root; + mPkContainer = linkMicViewHolder.getPkContainer(); + mPkTimeString1 = ""; + mPkTimeString2 = mContext.getString(R.string.live_pk_time_2); + //从本地取数据 + String pkTime = CommonAppConfig.getInstance().getAnchorPkTime(); + if (!pkTime.isEmpty()) { + try { + int time = Integer.parseInt(pkTime) * 60; + if (time > 0) { + PK_TIME_MAX = time; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + Log.d("PK_TIME_MAX", "" + PK_TIME_MAX); + mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case WHAT_PK_WAIT_RECEIVE: + onApplyPkWait(); + break; + case WHAT_PK_WAIT_SEND: + onSendPkWait(); + break; + case WHAT_PK_TIME: + changePkTime(); + break; + + } + } + }; + + } + + public LiveSwLinkMicPkPresenter(Context context, LivePushSwViewHolder linkMicViewHolder, boolean isAnchor, View root) { + mContext = context; + mIsAnchor = isAnchor; + mRoot = root; + mPkContainer = linkMicViewHolder.getPkContainer(); + livePushRyViewHolder = linkMicViewHolder; + mPkTimeString1 = ""; + mPkTimeString2 = mContext.getString(R.string.live_pk_time_2); + //从本地取数据 + String pkTime = CommonAppConfig.getInstance().getAnchorPkTime(); + if (!pkTime.isEmpty()) { + try { + int time = Integer.parseInt(pkTime) * 60; + if (time > 0) { + PK_TIME_MAX = time; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + Log.d("PK_TIME_MAX", "" + PK_TIME_MAX); + mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case WHAT_PK_WAIT_RECEIVE: + onApplyPkWait(); + break; + case WHAT_PK_WAIT_SEND: + onSendPkWait(); + break; + case WHAT_PK_TIME2: + pkCountdownTimer(); + break; + case WHAT_PK_TIME: + changePkTime(); + break; + } + } + }; + + } + + public void setSocketRyClient(SocketSwClient SocketRyClient) { + mSocketRyClient = SocketRyClient; + } + + public void setLiveUid(String liveUid, String url) { + Log.e("liveUid", liveUid); + mLiveUid = liveUid; + mUrl = url; + } + + + /** + * 申请pk弹窗倒计时 + */ + private void onApplyPkWait() { + mPkWaitCount--; + if (mPkWaitCount >= 0) { + if (mLinkMicWaitProgress != null) { + mLinkMicWaitProgress.setProgress(mPkWaitCount); + if (mHandler != null) { + mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_RECEIVE, getNextSecondTime()); + } + } + } else { + if (mPkPopWindow != null) { + mPkPopWindow.dismiss(); + } + } + } + + /** + * 发送pk申请后等待倒计时 + */ + private void onSendPkWait() { + mPkSendWaitCount--; + if (mPkSendWaitCount >= 0) { + nextSendPkWaitCountDown(); + } else { + hideSendPkWait(); + if (mIsAnchor) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(true); + } + } + } + + /** + * 进入下一次pk申请等待倒计时 + */ + private void nextSendPkWaitCountDown() { + if (mLiveLinkMicPkViewHolder != null) { + mLiveLinkMicPkViewHolder.setPkWaitProgress(mPkSendWaitCount); + } + if (mHandler != null) { + mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_SEND, getNextSecondTime()); + } + } + + /** + * 隐藏pk申请等待 + */ + private void hideSendPkWait() { + mPkSend = false; + if (mHandler != null) { + mHandler.removeMessages(WHAT_PK_WAIT_SEND); + } + if (mLiveLinkMicPkViewHolder != null) { + mLiveLinkMicPkViewHolder.setPkWaitProgressVisible(false); + } + } + + /** + * 进入下一次pk倒计时 + */ + int i = 0; + + private void nextPkTimeCountDown(int is) { + + if (mHandler != null) { + mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME, getNextSecondTime()); + } + if (mLiveLinkMicPkViewHolder != null) { + String s = mIsPkEnd ? mPkTimeString2 : mPkTimeString1; + String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); + Log.i("tag23333", mPkTimeCount + "mPkTimeCount" + s1 + "is" + is); + if (i == 1 && s1.equals("00:01")) { + s1 = "00:00"; + i = 0; + } + if (rtcRoom != null) { + ScreenDimenUtil util = ScreenDimenUtil.getInstance(); + int mScreenWdith = util.getScreenWdith(); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); + params.weight = 1; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + livePushRyViewHolder.camera.setLayoutParams(params); + livePushRyViewHolder.mPreView1.setLayoutParams(params); + } + + Log.i("tts2", s1); + mLiveLinkMicPkViewHolder.setTime(s + " " + s1); + if (s1.equals("00:01") && mIsAnchor && !s.contains("懲罰")) { + HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK").params("uid", CommonAppConfig.getInstance().getUid()).params("addtime", "00:00").params("type", "0").params("sign", "1").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + JSONObject datas = JSONObject.parseObject(info[0]); + + SocketSendBean seed_msg = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); + seed_msg.create(); + String pkUid = datas.getString("pkuid"); + Log.i("seed", seed_msg.mResult.toString()); + + Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid")); + + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + } + }); + } + }); + + } + } + }); + } + + } + } + + + /** + * pk时间倒计时 + */ + private void changePkTime() { + if (mPkTimeCount < 0) return; + mPkTimeCount--; + Log.i("vvvs", "mPkTimeCount:" + mPkTimeCount); + if (mPkTimeCount >= 0) {// + nextPkTimeCountDown(1); + if (mContext instanceof LiveAudienceActivity) { + ((LiveAudienceActivity) mContext).setPkStatus(true); + } + } else { + if (mIsPkEnd) { + onLinkMicPkClose(0); + if (mIsAnchor) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(true); + } + if (mContext instanceof LiveAudienceActivity) { + ((LiveAudienceActivity) mContext).setPkStatus(false); + } + //如果PK结束Im没有发送关闭PK的消息,倒计时结束自动关闭 +// if (mLiveLinkMicPkViewHolder != null) { +// mLiveLinkMicPkViewHolder.removeFromParent(); +// mLiveLinkMicPkViewHolder.release(); +// } +// mLiveLinkMicPkViewHolder = null; + } + } + } + + /** + * 获取下一秒钟的时间 + */ + private long getNextSecondTime() { + long now = SystemClock.uptimeMillis(); + return now + (1000 - now % 1000); + } + + /** + * 发起主播PK申请 + */ + public void applyLinkMicPk(String pkUid, String stream) { + if (mPkSend) { + ToastUtil.show(mContext.getString(R.string.link_mic_apply_waiting)); + return; + } + if (mIsPk) { + ToastUtil.show(mContext.getString(R.string.live_link_mic_cannot_pk)); + return; + } + mPkSend = true; + SocketSwLinkMicPkUtil.linkMicPkApply(mSocketRyClient, pkUid, stream); + ToastUtil.show(mContext.getString(R.string.link_mic_apply_pk)); + + if (mLiveLinkMicPkViewHolder == null) { + mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); + mLiveLinkMicPkViewHolder.addToParent(); + mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor); + + } + mLiveLinkMicPkViewHolder.setPkWaitProgressVisible(true); + mPkSendWaitCount = LINK_MIC_COUNT_MAX; + nextSendPkWaitCountDown(); + if (mIsAnchor) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(false); + } + } + + /** + * 主播与主播PK 主播收到其他主播发过来的多人PK申请的回调 + */ + public void onLinkDRMicPkApply(UserBean u) { + Log.e("ry", "多人收到"); + showDRApplyDialog(u); + } + + /** + * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 + */ + public void onLinkDRMicPkApplyOk(UserBean u) { + L.eSw("onLinkDRMicPkApplyOk(UserBean u) " + u.getUserNiceName()); + int index = 0; + if (livePushRyViewHolder != null) { + livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); + } + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 3) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("type", 3) + .param("uid", u.getId()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + + String targetId = "g" + CommonAppConfig.getInstance().getUid(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + dRjoinOtherRoom(u); + } + + /** + * 主播与主播PK 主播收到其他主播发过来的PK申请的回调 + */ + public void onLinkMicPkApply(UserBean u, String stream, int by) { + Log.e("ry", u.getUserNiceName() + "单人收到" + u.getAvatar()); + mApplyUid = u.getId(); + mApplyUrl = u.getAvatar(); + mApplyNmae = u.getUserNiceName(); + if (by != 1) { + if (mIsApplyDialogShow == false) { + if (u.isRandomPk()) { + showPkDialog(u); + } else { + showApplyDialog(u); + } + } + } else { + isPK(u); + } + } + + /** + * 主播与主播PK PK主播发过来的已经接受 + */ + public void onLinkMicToPk(UserBean u) { + EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar())); + Log.e("eve", u.getId() + ""); + L.eSw("主播接受了主播的PK邀請"); + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); + LiveSwAnchorActivity.isDRPK = 1; + livePushRyViewHolder.setAnPkRtc(u);//设置对方主播视图 + + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK).param("action", 4) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", u.getId()).param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", u.getAvatar()).param("pkname", u.getUserNiceName()); + msg1.create(); + LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); + } + + private void isPK(UserBean bean) { + EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar())); + ScreenDimenUtil util = ScreenDimenUtil.getInstance(); + int mScreenWdith = util.getScreenWdith(); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); + params.weight = 1; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + livePushRyViewHolder.camera.setLayoutParams(params); + livePushRyViewHolder.mPreView1.setLayoutParams(params); + livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); + LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); + LiveSwAnchorActivity.isDRPK = 1; + + /*---------------------------------------------------------------- */ + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 2) //回复PK申请 2 + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", bean.getId()) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + if (RandomPkManager.getInstance().isRankModel()) { + L.eSw("排位赛"); + msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + } + msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); + msg1.create(); + System.out.println("PK回执 = " + msg1.toString()); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain( bean.getId(), conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("tx", "发送成功"); + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "发送失败" + errorCode.getMessage()); + + } + }); + + // TODO: 2024/4/12 视图渲染 + livePushRyViewHolder.setAnPkRtc(bean); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); + LiveSwAnchorActivity.isDRPK = 1; + LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); + SocketSwLinkMicPkUtil.linkMicPkAccept(mSocketRyClient, mApplyUid, mApplyUrl, mApplyNmae); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid)); + onLinkMicPkStart(mApplyUid, 2); + } + }); + } + + //与用户连麦 + public void setUserMic(String liveid) { + JSONObject msg1 = new JSONObject(); + msg1.put("uid", CommonAppConfig.getInstance().getUid()); + msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); + msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb()); + msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + + rtcRoom.getLocalUser().responseJoinOtherRoom(liveid, liveid, true, true, msg1.toString(), new IRCRTCResultCallback() { + @Override + public void onSuccess() { + RCRTCEngine.getInstance().joinOtherRoom(liveid, new IRCRTCResultDataCallback() { + @Override + public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { + rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + Log.e("ry", liveid + "来了!!!!" + rcrtcOtherRoom.getRemoteUsers().size()); + for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { + //遍历远端用户发布的资源列表 + for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { + Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + rcrtcOtherRoom.getRemoteUsers().size()); + if (stream.getMediaType() == RCRTCMediaType.AUDIO) { + //音频只需要订阅 + inputStreamList.add(stream); + } + } + } + + Log.e("ry", "asa" + inputStreamList.size()); + //开始订阅资源 + rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + + + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", "订阅资源失败: " + rtcErrorCode); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + }); + } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", liveid + "加入其他房间失败 :" + rtcErrorCode); + Log.i("ry", liveid + "加入其他房间失败 :" + rtcErrorCode); + } + }); + + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + ToastUtil.show("接受失败"); + } + }); + } + + /** + * 显示申请PK的弹窗 + */ + private void showApplyDialog(UserBean u) { + mIsApplyDialogShow = true; + mAcceptPk = false; + View v = LayoutInflater.from(mContext).inflate(R.layout.dialog_link_mic_pk_wait, null); + mLinkMicWaitProgress = v.findViewById(R.id.pk_wait_progress); + v.findViewById(R.id.btn_refuse).setOnClickListener(this); + v.findViewById(R.id.btn_accept).setOnClickListener(this); + mPkWaitCount = LINK_MIC_COUNT_MAX; + mPkPopWindow = new PopupWindow(v, DpUtil.dp2px(280), ViewGroup.LayoutParams.WRAP_CONTENT, true); + mPkPopWindow.setBackgroundDrawable(new ColorDrawable()); + mPkPopWindow.setOutsideTouchable(true); + mPkPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { + @Override + public void onDismiss() { + if (mHandler != null) { + mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); + } + if (mAcceptPk) { + isPK(u); + } else { + if (mPkWaitCount < 0) { + if(rtcRoom==null){ + return; + } + rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + + Log.e("ry", "发送成功"); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + u.getId()); + } + }); + } + }); + + } + mApplyUid = null; + mApplyStream = null; + } + mIsApplyDialogShow = false; + mLinkMicWaitProgress = null; + mPkPopWindow = null; + } + }); + mPkPopWindow.showAtLocation(mRoot, Gravity.CENTER, 0, 0); + if (mHandler != null) { + mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_RECEIVE, getNextSecondTime()); + } + } + + + public static Bitmap fromText(float textSize, String text) { + Paint paint = new Paint(); + paint.setTextSize(textSize); + paint.setTextAlign(Paint.Align.LEFT); + paint.setColor(Color.BLACK); + + Paint.FontMetricsInt fm = paint.getFontMetricsInt(); + int width = (int) paint.measureText(text); + int height = fm.descent - fm.ascent; + + Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + canvas.drawText(text, 0, fm.leading - fm.ascent, paint); + canvas.save(); + + return bitmap; + } + + private String TAG = "多人PK"; + + /** + * 退出多人PK + */ + public void leaveDRRoom() { + //清理PK上面对方的头像 + EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); + Log.e("ry", "退出多人OKKK" + inputStreamList.size()); + isDRPK = 0; + runOnUiThread(new Runnable() { + @Override + public void run() { + if (btn_close != null) { + btn_close.setVisibility(View.GONE); + livePushRyViewHolder.timeTitle.setVisibility(View.GONE); + } + } + }); + livePushRyViewHolder.exitChannelDrPk(drPkbeans); + leaveHandler.removeCallbacks(leaveRunnable); + } + + private Handler leaveHandler = new Handler(Looper.getMainLooper()); + private Runnable leaveRunnable = new Runnable() { + @Override + public void run() { + //恢复全屏画面 + livePushRyViewHolder.dr_pk_view.setVisibility(View.GONE); + //删除之前其他主播的画面 + livePushRyViewHolder.dr1_preview.removeAllViews(); + livePushRyViewHolder.dr2_preview.removeAllViews(); + livePushRyViewHolder.dr3_preview.removeAllViews(); + livePushRyViewHolder.dr4_preview.removeAllViews(); + livePushRyViewHolder.cameraPreview3.removeAllViews(); + leaveHandler.removeCallbacks(leaveRunnable); + livePushRyViewHolder.timeTitle.setVisibility(View.GONE); + livePushRyViewHolder.mPreView.removeView(detailsView1); + livePushRyViewHolder.cameraPreview3.setVisibility(View.GONE); + } + }; + + /** + * 随机PK拒绝对话框 + */ + public void showPkDialog(UserBean u) { + new DialogUitl.Builder(mContext).setHtmlCode(Html.fromHtml("有人向您发起PK请求。
" + "若拒绝PK,将会10分钟内不会再收到任何随机PK请求。")).setConfirmString("接受").setCancelString("拒絕").setView(R.layout.dialog_live_random_pk).setSimpleCallbackView(new DialogUitl.SimpleCallbackView() { + boolean clickCancel = false; + String titleVal; + TimerTask task; + + @Override + public void onShow(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + task = new TimerTask() { + int time = 11; + final Handler handler = new Handler(Looper.getMainLooper()); + + @Override + public void run() { + if (titleVal == null) { + titleVal = ((TextView) title).getText().toString(); + } + handler.post(() -> ((TextView) title).setText(titleVal + " " + time)); + if (time-- == 0) { + handler.post(() -> showClose(dialog, title, context, confirmBtn, cancelBtn)); + cancel(); + } + } + }; + new Timer().schedule(task, 1000, 1000); + } + + @Override + public void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + dialog.dismiss(); + task.cancel(); + apply(); + } + + @Override + public void onCancel(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + if (!clickCancel) { + titleVal = "拒絕PK提示"; + ((TextView) context).setText(Html.fromHtml("若拒絕PK,將會關閉你的隨機PK開關。
" + "並且10分鍾不會收到任何隨機PK請求。
")); + ((TextView) cancelBtn).setText("堅持拒絕"); + clickCancel = true; + return; + } + showClose(dialog, title, context, confirmBtn, cancelBtn); + } + + void showClose(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + task.cancel(); + ((TextView) title).setText("您因拒絕隨機PK,被限制關閉中"); + ((TextView) confirmBtn).setText("确定"); + ((TextView) context).setText("隨機PK可打開時間:" + new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis() + 7200000)));//7200000ms=120m=2h + ((TextView) context).setTextSize(12); + ((TextView) context).setTextColor(Color.parseColor("#999999")); + refusePk(u); + cancelBtn.setVisibility(View.GONE); + confirmBtn.setOnClickListener(v -> { + dialog.dismiss(); + }); + } + + + void apply() { + isPK(u); + } + }).build().show(); + } + + private void refusePk(UserBean u) { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra_randm_pk", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) + // .param("randomPk",u.isRandomPk()+"") + .param("action", 3); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + u.getId()); + } + }); + } + }); + + LiveNetManager.get(mContext).setBanRandomPK(null); + } + + + /** + * 显示申请多人PK的弹窗 + */ + private void showDRApplyDialog(UserBean u) { + mApplyUid = u.getId(); + mIsApplyDialogShow = true; + mAcceptPk = false; + View v = LayoutInflater.from(mContext).inflate(R.layout.dialog_link_mic_pk_wait, null); + mLinkMicWaitProgress = v.findViewById(R.id.pk_wait_progress); + v.findViewById(R.id.btn_refuse).setOnClickListener(this); + v.findViewById(R.id.btn_accept).setOnClickListener(this); + mPkWaitCount = LINK_MIC_COUNT_MAX; + mPkPopWindow = new PopupWindow(v, DpUtil.dp2px(280), ViewGroup.LayoutParams.WRAP_CONTENT, true); + mPkPopWindow.setBackgroundDrawable(new ColorDrawable()); + mPkPopWindow.setOutsideTouchable(true); + mPkPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { + @Override + public void onDismiss() { + if (mHandler != null) { + mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); + } + if (mAcceptPk) { + + HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive").params("uid", CommonAppConfig.getInstance().getUid()).params("pkuid", u.getId()).params("type", "1").params("sign", "1").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msgs, String[] info) { + if (code == 0) { + Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); + HttpClient.getInstance().get("live.getdrnum", "live.getdrnum").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + if (info.length > 0) { + JSONObject datas = JSONObject.parseObject(info[0]); + boolean agree = true; + if (datas.getIntValue("pk_num_day") <= 0) { + ToastUtil.show("多人PK次数已用完"); + agree = false; + } + boolean finalAgree = agree; + if (finalAgree) { + HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", u.getId()).execute(new HttpCallback() { + + @Override + public void onSuccess(int code, String msg, String[] info) { + L.eSw("多人PK" + "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + if (info.length == 0) { + return; + } + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + SWManager.get().setDimensions(3);//加入成功后,将分别率设置为 VD_320x240 + //将自己从多人pk列表里剔除 + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; + } + } + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); + L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); + } + + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + for (int i = 0; i < drPkbeans.size(); i++) { + if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 2) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 2) + .param("uid", drPkbeans.get(i).getId()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + L.eSw("uiduiduiduiduiduiduiduid"+drPkbeans.get(i).getId()); + String targetId = String.valueOf(drPkbeans.get(i).getId()); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + + // + int index = livePushRyViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); + + L.eSw("onLinkDRMicPkApplyOk(UserBean u)-点击接收 1 " + u.getUserNiceName()); + L.eSw("發送action = 2"); + + } + + if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 3) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 3) + .param("uid", drPkbeans.get(i).getId()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + L.eSw("發送給自己直播間"+drPkbeans.get(i).getId()); + String targetId = "g" + CommonAppConfig.getInstance().getUid(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + } + + + if(!mApplyUid.equals(String.valueOf(drPkbeans.get(i).getId()))&&!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))){ + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) + .param("action", 3) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 3) + .param("uid", drPkbeans.get(i).getId()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + L.eSw("發送給其他主播直播间"+drPkbeans.get(i).getId()); + String targetId = "g" + drPkbeans.get(i).getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + } + } + dRjoinOtherRoom(u); + } + } + }); + + + /*for (int i = 0; i < users.size(); i++) { + JSONObject user = users.getJSONObject(i); + Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); + if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { + if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { + *//** + * 向指定用户发送跨房间连麦请求 + *

+ * 1: inviterAutoMix为true时: + * + * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 + * + * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 + * + * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 + *

+ *//* + IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { + @Override + public void onSuccess() { + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + }); + } + } + }*/ + } + }); + } + } else { + ToastUtil.show(msg); + } + } + + }); + + + } + } + }); + + + } else { + if (mPkWaitCount < 0) { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + mApplyUid); + } + }); + } + }); + + } else { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 3); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗"); + } + }); + } + }); + } + mApplyUid = null; + mApplyStream = null; + } + mIsApplyDialogShow = false; + mLinkMicWaitProgress = null; + mPkPopWindow = null; + } + }); + mPkPopWindow.showAtLocation(mRoot, Gravity.CENTER, 0, 0); + if (mHandler != null) { + mHandler.sendEmptyMessageAtTime(WHAT_PK_WAIT_RECEIVE, getNextSecondTime()); + } + } + + public void setMyDrPkDetailsView() { + if (detailsView1 != null) { + livePushRyViewHolder.dr1_preview.removeView(detailsView1); + } + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); + linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); + imageGrade1 = detailsView1.findViewById(R.id.image_grade1); + textGrade1 = detailsView1.findViewById(R.id.text_grade1); + textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + livePushRyViewHolder.dr1_preview.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.GONE); + linearGrade1.setVisibility(View.GONE); + } + + + public void setPkUserInfoView(UserBean userBean){ + + } + + //多人PK接受申请画 加入副房间 + public void dRjoinOtherRoom(UserBean u) { + setMyDrPkDetailsView(); + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; + } + } + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); + } + setDrPkUserInfoView(drPkbeans); + } + } + }); + } + + private void setDrPkUserInfoView(List drPkbeanList) { + L.eSw("setDrPkUserInfoView" + new Gson().toJson(drPkbeanList)); + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + for (int j = 0; j < drPkbeanList.size(); j++) { + if (j == 0) { + L.eSw("j == 0:" + j); + //设置多人PK数据 + if (detailsView2 != null) { + livePushRyViewHolder.dr2_preview.removeView(detailsView2); + } + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(String.valueOf(drPkbeanList.get(0).getId())); + textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); + livePushRyViewHolder.dr2_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.GONE); + linearGrade2.setVisibility(View.GONE); + } else if (j == 1) { + L.eSw("j == 1:" + j); + if (detailsView4 != null) { + livePushRyViewHolder.dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(String.valueOf(drPkbeanList.get(1).getId())); + textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); + livePushRyViewHolder.dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + } else if (j == 2) { + L.eSw("j == 2:" + j); + + if (detailsView4 != null) { + livePushRyViewHolder.dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(String.valueOf(drPkbeanList.get(2).getId())); + textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); + livePushRyViewHolder.dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + + if (detailsView3 != null) { + livePushRyViewHolder.dr3_preview.removeView(detailsView3); + } + detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); + linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); + textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); + imageGrade3 = detailsView3.findViewById(R.id.image_grade3); + textGrade3 = detailsView3.findViewById(R.id.text_grade3); + imageGrade3.setTag(String.valueOf(drPkbeanList.get(1).getId())); + textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); + livePushRyViewHolder.dr3_preview.addView(detailsView3); + detailsLinearLayout3.setVisibility(View.GONE); + linearGrade3.setVisibility(View.GONE); + + + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); + + } + } + } + }, 2000); + L.eSw("dRjoinOtherRoom:size:" + drPkbeanList.size() + " json " + new Gson().toJson(drPkbeanList)); + + } + + /** + * 多人PK PK主播发过来的已经接受 + */ + public void onDRLinkMicToPk(String u) { + Log.e("eve", u + ""); + /** + * 加入副房间 + * + * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 + * + * @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_` + * @param callBack 加入房间回调 + * @group 房间管理 + */ + + /*RCRTCEngine.getInstance().joinOtherRoom(u, new IRCRTCResultDataCallback() { + @Override + public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { + rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + + if (livePushRyViewHolder.dr_pk_view.getVisibility() == View.GONE) { + ScreenDimenUtil util = ScreenDimenUtil.getInstance(); + int mScreenWdith = util.getScreenWdith(); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); + params.weight = 1; + params.topMargin = DpUtil.dp2px(123); + livePushRyViewHolder.dr_pk_view.setLayoutParams(params); + livePushRyViewHolder.camera.setLayoutParams(params); + livePushRyViewHolder.dr_pk_view.setVisibility(View.VISIBLE); + livePushRyViewHolder.dr1_preview.setVisibility(View.GONE); + livePushRyViewHolder.dr2_preview.setVisibility(View.GONE); + livePushRyViewHolder.dr3_preview.setVisibility(View.GONE); + livePushRyViewHolder.dr4_preview.setVisibility(View.GONE); + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); + linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); + imageGrade1 = detailsView1.findViewById(R.id.image_grade1); + textGrade1 = detailsView1.findViewById(R.id.text_grade1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + livePushRyViewHolder.mPreView.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.GONE); + } + + //遍历远端用户列表 + for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { + //遍历远端用户发布的资源列表 + for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { + Log.e("ry111", stream.getMediaType() + ""); + if (stream.getMediaType() == RCRTCMediaType.VIDEO) { + if (inputStreamList.size() == 0) { + livePushRyViewHolder.dr1_preview.setVisibility(View.VISIBLE); + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + livePushRyViewHolder.dr1_preview.removeAllViews(); + remoteView.setScalingType(SCALE_ASPECT_FILL); + livePushRyViewHolder.dr1_preview.addView(remoteView); + LiveNetManager.get(mContext).getLiveInfo(u, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(String.valueOf(u)); + textPkName2.setText(data.getUserNicename()); + livePushRyViewHolder.dr1_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.GONE); + } + + @Override + public void onError(String error) { + + } + }); + } else if (inputStreamList.size() == 1) { + livePushRyViewHolder.dr3_preview.setVisibility(View.VISIBLE); + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + livePushRyViewHolder.dr3_preview.removeAllViews(); + remoteView.setScalingType(SCALE_ASPECT_FILL); + livePushRyViewHolder.dr3_preview.addView(remoteView); + LiveNetManager.get(mContext).getLiveInfo(u, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(u); + textPkName4.setText(data.getUserNicename()); + livePushRyViewHolder.dr3_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.GONE); + } + + @Override + public void onError(String error) { + + } + }); + } else if (inputStreamList.size() == 2) { + livePushRyViewHolder.cameraPreview3.setVisibility(View.VISIBLE); + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + livePushRyViewHolder.cameraPreview3.removeAllViews(); + remoteView.setScalingType(SCALE_ASPECT_FILL); + livePushRyViewHolder.cameraPreview3.addView(remoteView); + + LiveNetManager.get(mContext).getLiveInfo(u, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); + linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); + textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); + imageGrade3 = detailsView3.findViewById(R.id.image_grade3); + textGrade3 = detailsView3.findViewById(R.id.text_grade3); + imageGrade3.setTag(u); + textPkName3.setText(data.getUserNicename()); + livePushRyViewHolder.cameraPreview3.addView(detailsView3); + detailsLinearLayout3.setVisibility(View.VISIBLE); + linearGrade3.setVisibility(View.GONE); + } + + @Override + public void onError(String error) { + + } + }); + } + inputStreamList.add(stream); + + } + inputStreamList1.add(stream); + + + } + + //开始订阅资源 + rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.i("ry", "订阅资源成功"); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + }); + + //2. 合流画布设置 + rcrtcLiveInfo.setMixConfig(create_Custom_MixConfig(false, inputStreamList), new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", inputStreamList.size() + "混成功" + u); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); + + } + }); + } + + } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason()); + } + });*/ + + } + + + /** + * 创建自定义合流布局配置 + * + * @param isCrop 是否裁减画布 + * @param streams 必须为视频流列表 + * @return + */ + private RCRTCMixConfig create_Custom_MixConfig(boolean isCrop, List streams) { + Log.e("视频合流", streams.toString()); + Log.e("视频合流", "视频长度:" + streams.size()); + RCRTCMixConfig config = new RCRTCMixConfig(); + //1. 设置自定义合流布局模式 + config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.CUSTOM); + RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); + config.setMediaConfig(mediaConfig); + //视频输出配置 + RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); + mediaConfig.setVideoConfig(videoConfig); + //大流视频的输出参数 + RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); + videoConfig.setVideoLayout(normal); + //推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 + //如不设置宽高值则服务端将使用默认宽高 360 * 640 + //例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, + //所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 + RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); + int fps = defaultVideoConfig.getVideoFps().getFps(); + int width = 960; + int height = 720; + normal.setWidth(width); //视频宽 + normal.setHeight(height); //视频高 + normal.setFps(fps); //视频帧率 + + //2. 合流画布设置 + //(请参照画布和声音配置示例代码) + //3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高 + ArrayList list = new ArrayList<>(); + + if (streams.size() == 1) { + //user1的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video + videoLayout1.setX(0); //X 坐标 + videoLayout1.setY(0); //Y 坐标 + videoLayout1.setWidth(480); // 视频窗口的宽 + videoLayout1.setHeight(720); // 视频窗口的高 + list.add(videoLayout1); + + //user2的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video + videoLayout2.setX(480); //X 坐标 + videoLayout2.setY(0); //Y 坐标 + videoLayout2.setWidth(480); // 视频窗口的宽 + videoLayout2.setHeight(720); // 视频窗口的高 + list.add(videoLayout2); + + } else if (streams.size() == 2) { + //user1的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + list.add(videoLayout1); + videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video + videoLayout1.setX(0); //X 坐标 + videoLayout1.setY(0); //Y 坐标 + videoLayout1.setWidth(480); // 视频窗口的宽 + videoLayout1.setHeight(720); // 视频窗口的高 + + //user2的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video + videoLayout2.setX(480); //X 坐标 + videoLayout2.setY(0); //Y 坐标 + videoLayout2.setWidth(480); // 视频窗口的宽 + videoLayout2.setHeight(360); // 视频窗口的高 + list.add(videoLayout2); + + //user3的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout3 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + videoLayout3.setVideoStream(streams.get(1)); // RCRTCStream#MediaType 必须是Video + videoLayout3.setX(480); //X 坐标 + videoLayout3.setY(360); //Y 坐标 + videoLayout3.setWidth(480); // 视频窗口的宽 + videoLayout3.setHeight(360); // 视频窗口的高 + list.add(videoLayout3); + + } else if (streams.size() == 3) { + //user1的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video + videoLayout1.setX(0); //X 坐标 + videoLayout1.setY(0); //Y 坐标 + videoLayout1.setWidth(480); // 视频窗口的宽 + videoLayout1.setHeight(720); // 视频窗口的高 + list.add(videoLayout1); + + //user2的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video + videoLayout2.setX(480); //X 坐标 + videoLayout2.setY(0); //Y 坐标 + videoLayout2.setWidth(480); // 视频窗口的宽 + videoLayout2.setHeight(360); // 视频窗口的高 + list.add(videoLayout2); + + //user3的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout3 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + videoLayout3.setVideoStream(streams.get(1)); // RCRTCStream#MediaType 必须是Video + videoLayout3.setX(480); //X 坐标 + videoLayout3.setY(360); //Y 坐标 + videoLayout3.setWidth(480); // 视频窗口的宽 + videoLayout3.setHeight(360); // 视频窗口的高 + list.add(videoLayout3); + + //user3的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout4 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + videoLayout4.setVideoStream(streams.get(2)); // RCRTCStream#MediaType 必须是Video + videoLayout4.setX(0); //X 坐标 + videoLayout4.setY(360); //Y 坐标 + videoLayout4.setWidth(480); // 视频窗口的宽 + videoLayout4.setHeight(360); // 视频窗口的高 + list.add(videoLayout4); + } + config.setCustomLayouts(list); + return config; + } + + @Override + public void onClick(View v) { + int i = v.getId(); + if (i == R.id.btn_refuse) { + refuseLinkMic(); + + } else if (i == R.id.btn_accept) { + acceptLinkMic(); + + } + } + + /** + * 拒绝PK + */ + private void refuseLinkMic() { + if (mPkPopWindow != null) { + mPkPopWindow.dismiss(); + } + } + + /** + * 接受PK + */ + private void acceptLinkMic() { + mAcceptPk = true; + if (mPkPopWindow != null) { + mPkPopWindow.dismiss(); + } + } + + /** + * pk 进度发送变化 + * + * @param leftGift + * @param rightGift + */ + public void onPkProgressChanged(long leftGift, long rightGift, LivePKUserListBean bean) { + if (mLiveLinkMicPkViewHolder != null) { + mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean); + } + } + + /** + * 进房间的时候PK开始 + */ + public void onEnterRoomPkStart(String pkUid, long leftGift, long rightGift, int pkTime, LivePKUserListBean bean) { + mIsPk = true; + mIsPkEnd = false; + mPkUid = pkUid; + mApplyUid = null; + mApplyStream = null; + if (mLiveLinkMicPkViewHolder == null) { + mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); + mLiveLinkMicPkViewHolder.addToParent(); + mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor); + + } + mLiveLinkMicPkViewHolder.showTime(); + mLiveLinkMicPkViewHolder.onEnterRoomPkStart(); + mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean); + mPkTimeCount = pkTime; + Log.d("mPkTimeCount1", "" + mPkTimeCount + ";mPkTimeFromServer=" + mPkTimeFromServer); + mPkTimeFromServer = pkTime; + nextPkTimeCountDown(2); + } + + /** + * 修改最终PK数据 + * + * @param leftGift 左边数据 + * @param rightGift 右边数据 + * @param bean 排位数据 + */ + public void onPkProgressEnd(long leftGift, long rightGift, LivePKUserListBean bean) { + if (mLiveLinkMicPkViewHolder != null) { + mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean, true); + } + } + + + /** + * 进房间的时候懲罰开始 + */ + public void onEnterRoomCFStart(String pkUid, long leftGift, long rightGift, int pkTime, LivePKUserListBean bean) { + mIsPk = true; + mIsPkEnd = true; + mPkUid = pkUid; + mApplyUid = null; + mApplyStream = null; + if (mLiveLinkMicPkViewHolder == null) { + mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); + mLiveLinkMicPkViewHolder.addToParent(); + mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor); + + } + mLiveLinkMicPkViewHolder.showTime(); +// -1自己的主播输 0平 1自己的主播赢 + int p = 0; + if (leftGift < rightGift) { + p = -1; + } else if (leftGift > rightGift) { + p = 1; + } else if (leftGift == rightGift) { + p = 0; + } + mLiveLinkMicPkViewHolder.new_end(p); + + mLiveLinkMicPkViewHolder.onProgressChanged(leftGift, rightGift, bean); + mPkTimeCount = pkTime; + Log.d("mPkTimeCount1", "" + mPkTimeCount + ";mPkTimeFromServer=" + mPkTimeFromServer); +// mPkTimeFromServer=pkTime; + //恢复播放画面 + nextPkTimeCountDown(3); + } + + + /** + * 主播与主播PK 所有人收到PK开始的回调 + */ + public void onLinkMicPkStart(String pkUid, int i) { + L.eSw("onLinkMicPkStart pkUid "+pkUid+" "+i); + Log.d("tag", i + "mPkTimeCount2"); + mIsPk = true; + hideSendPkWait(); + mIsPkEnd = false; + oldmPkUid = pkUid; + mPkUid = pkUid; + mApplyUid = null; + mApplyStream = null; + isDRPK=1; + if (mLiveLinkMicPkViewHolder == null) { + mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); + mLiveLinkMicPkViewHolder.addToParent(); + mLiveLinkMicPkViewHolder.setIsAnchor(mIsAnchor); + if (mContext instanceof LiveAudienceActivity) { + ((LiveAudienceActivity) mContext).getmLivePlayViewHolder().setPkview(); + } + } + mLiveLinkMicPkViewHolder.startAnim(); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(pkUid)); + mLiveLinkMicPkViewHolder.showTime(); + mPkTimeCount = 100; + nextPkTimeCountDown(2);//时间倒计时 + if (mIsAnchor) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(false); + mPkTimeCount = PK_TIME_MAX; + } else { +// mPkTimeCount=mPkTimeFromServer; + mPkTimeCount = PK_TIME_MAX; + } + Log.d("mPkTimeCount2", "" + mPkTimeCount + ";mPkTimeFromServer=" + mPkTimeFromServer); + } + + + /** + * 主播与主播PK PK结果的回调 + */ + int s1 = 0; + + public void onLinkMicPkEnd(String winUid) { + Log.i("收", "9"); + + if (mIsPkEnd) { + return; + } + mIsPkEnd = true; + if (mHandler != null) { + mHandler.removeMessages(WHAT_PK_TIME); + } + if (mLiveLinkMicPkViewHolder != null) { + if (!TextUtils.isEmpty(winUid)) { + if ("0".equals(winUid)) { + mLiveLinkMicPkViewHolder.end(0); + mLiveLinkMicPkViewHolder.hideTime(); + if (mHandler != null) { + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + onLinkMicPkClose(0); + if (mIsAnchor) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(true); + } + } + }, 3000); + } + } else { + Log.e("ry1", winUid + "result"); + if (winUid.equals(mLiveUid)) { + mLiveLinkMicPkViewHolder.end(1); + } else { + mLiveLinkMicPkViewHolder.end(-1); + } + mPkTimeCount = PK_TIME_MAX_2;//进入惩罚时间 + nextPkTimeCountDown(5); + } + } + + } + } + + /** + * 主播与主播PK 断开连麦PK的回调 + */ + public void onLinkMicPkClose(int i) { + Log.e("ry", mPkUid + "aaaaqwqw" + i); + + PKing = false; + LiveSwAnchorActivity.isDRPK = 0; + +// //恢复播放画面 + if (i == 1) { + runOnUiThread(new Runnable() { + @Override + public void run() { + if (btn_close != null) { + btn_close.setVisibility(View.GONE); + } + } + }); + + runOnUiThread(new Runnable() { + public void run() { +// try { +// Thread.sleep(4000); + if (mContext instanceof LiveAudienceActivity && LiveAudienceActivity.getmLivePlayViewHolder() != null) { + LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview(); + } +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } + } + }); + + } + if (mHandler != null) { + mHandler.removeCallbacksAndMessages(null); + } + if (mPkPopWindow != null) { + mPkPopWindow.dismiss(); + } + mPkPopWindow = null; + mIsPk = false; + mIsPkEnd = false; + hideSendPkWait(); + mPkUid = null; + mApplyUid = null; + mApplyStream = null; + if (mLiveLinkMicPkViewHolder != null) { + mLiveLinkMicPkViewHolder.removeFromParent(); + mLiveLinkMicPkViewHolder.release(); + } + mLiveLinkMicPkViewHolder = null; + } + + /** + * 主播与主播Pk 对方主播拒绝Pk的回调 + */ + public void onLinkMicPkRefuse() { + hideSendPkWait(); + if (mIsAnchor) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(true); + } + ToastUtil.show(mContext.getString(R.string.link_mic_refuse_pk)); + } + + /** + * 主播与主播Pk 对方主播无响应的回调 + */ + public void onLinkMicPkNotResponse() { + hideSendPkWait(); + if (mIsAnchor) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(true); + } + ToastUtil.show(mContext.getString(R.string.link_mic_anchor_not_response_2)); + } + + /** + * 主播与主播Pk 对方主播正在忙的回调 + */ + public void onLinkMicPkBusy() { + hideSendPkWait(); + if (mIsAnchor) { + ((LiveSwAnchorActivity) mContext).setPkBtnVisible(true); + } + ToastUtil.show(mContext.getString(R.string.link_mic_anchor_busy_2)); + } + + + public void release() { + if (mHandler != null) { + mHandler.removeCallbacksAndMessages(null); + } + mHandler = null; + mSocketRyClient = null; + if (mLiveLinkMicPkViewHolder != null) { + mLiveLinkMicPkViewHolder.release(); + } + mLiveLinkMicPkViewHolder = null; + } + + + public void clearData() { + mIsApplyDialogShow = false; + mAcceptPk = false; + mIsPk = false; + mApplyUid = null; + mApplyStream = null; + mLiveUid = null; + mPkUid = null; + mPkWaitCount = 0; + mPkTimeCount = 0; + mIsPkEnd = false; + mPkSend = false; + mPkSendWaitCount = 0; + if (mHandler != null) { + mHandler.removeCallbacksAndMessages(null); + } + if (mLiveLinkMicPkViewHolder != null) { + mLiveLinkMicPkViewHolder.release(); + mLiveLinkMicPkViewHolder.removeFromParent(); + } + mLiveLinkMicPkViewHolder = null; + } + + + public void setSelfStream(String selfStream) { + mSelfStream = selfStream; + } + + /** + * 更新Pk分数 + */ + public void upDataPkScore(JSONArray pkScores, String uid, int time) { + L.eSw("更新Pk分数 upDataPkScore time:" + time + " " + pkScores); + String userID1 = (String) imageGrade1.getTag(); + String userID2 = (String) imageGrade2.getTag(); + String userID4 = (String) imageGrade4.getTag(); + if (livePushRyViewHolder.timeTitle.getVisibility() == View.GONE) { + mHandler.removeMessages(WHAT_PK_TIME2); + RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) livePushRyViewHolder.timeTitle.getLayoutParams(); + layoutParams.topMargin = DpUtil.dp2px(123); + livePushRyViewHolder.timeTitle.setLayoutParams(layoutParams); + livePushRyViewHolder.timeTitle.setVisibility(View.VISIBLE); + String pkTime = StringUtil.getDurationText(time * 1000); + livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime)); + mPkTimeCount = time; + if (time > 0) { + String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); + livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); + mHandler.sendEmptyMessage(WHAT_PK_TIME2); + } + } + int pkScoreSize = pkScores.size(); + if (pkScoreSize == 3) { + detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.VISIBLE); + + linearGrade1.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.VISIBLE); + //拿到原始数据 + for (int i = 0; i < pkScores.size(); i++) { + JSONObject score = pkScores.getJSONObject(i); + String userID = score.getString("id"); + long userScore = score.getLong("score"); + if (TextUtils.equals(userID, userID1)) { + textGrade1.setText(String.valueOf(userScore)); + if (!score.containsKey("paiming")) { + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + } else { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + break; + case 2: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade1); + break; + case 3: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade1); + break; + case 4: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade1); + break; + } + } + } else if (TextUtils.equals(userID, userID2)) { + textGrade2.setText(String.valueOf(userScore)); + if (!score.containsKey("paiming")) { + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + } else { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + break; + case 2: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade2); + break; + case 3: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade2); + break; + case 4: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade2); + break; + } + } + } else if (TextUtils.equals(userID, userID4)) { + textGrade4.setText(String.valueOf(userScore)); + if (!score.containsKey("paiming")) { + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); + } else { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); + break; + case 2: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade4); + break; + case 3: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade4); + break; + case 4: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade4); + break; + } + } + } + } + } else { + String userID3 = (String) imageGrade3.getTag(); + + detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.VISIBLE); + detailsLinearLayout3.setVisibility(View.VISIBLE); + detailsLinearLayout4.setVisibility(View.VISIBLE); + + linearGrade1.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.VISIBLE); + linearGrade3.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.VISIBLE); + //拿到原始数据 + for (int i = 0; i < pkScores.size(); i++) { + JSONObject score = pkScores.getJSONObject(i); + String userID = score.getString("id"); + long userScore = score.getLong("score"); + if (TextUtils.equals(userID, userID1)) { + textGrade1.setText(String.valueOf(userScore)); + if (!score.containsKey("paiming")) { + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + } else { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + break; + case 2: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade1); + break; + case 3: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade1); + break; + case 4: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade1); + break; + } + } + } else if (TextUtils.equals(userID, userID2)) { + textGrade2.setText(String.valueOf(userScore)); + if (!score.containsKey("paiming")) { + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + } else { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + break; + case 2: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade2); + break; + case 3: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade2); + break; + case 4: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade2); + break; + } + } + } else if (TextUtils.equals(userID, userID4)) { + textGrade4.setText(String.valueOf(userScore)); + if (!score.containsKey("paiming")) { + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); + } else { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); + break; + case 2: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade4); + break; + case 3: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade4); + break; + case 4: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade4); + break; + } + } + } else if (TextUtils.equals(userID, userID3)) { + textGrade3.setText(String.valueOf(userScore)); + if (!score.containsKey("paiming")) { + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade3); + } else { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade3); + break; + case 2: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade3); + break; + case 3: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade3); + break; + case 4: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade3); + break; + } + } + } + + } + } + + } + + + /** + * PK倒计时 + */ + private void pkCountdownTimer() { + + mPkTimeCount--; + if (mPkTimeCount > 0) {// + if (mHandler != null) { + String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); + livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); + mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME2, getNextSecondTime()); + } + } else { + livePushRyViewHolder.timeTitle.setVisibility(View.GONE); + if (mHandler != null) { + mHandler.removeCallbacksAndMessages(null); + } + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); +// endDRGif(); + if (DRInitiator) { + LiveNetManager.get(mContext).jieshuDRPK("" + IMLoginManager.get(mContext).getUserInfo().getId()); + } + } + } + + +} diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java index 6192c56cc..f451fb908 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java @@ -34,7 +34,7 @@ import io.rong.message.TextMessage; public class SocketRyChatUtil { //关闭直播 - public static void closeLive(final String votes, final String length, final String nums, final String mLiveUid, SocketRyClient client) { + public static void closeLive(final String votes, final String length, final String nums, final String mLiveUid, SocketSwClient client) { UserBean u = CommonAppConfig.getInstance().getUserBean(); final SocketSendBean msg = new SocketSendBean() .param("_method_", Constants.SOCKET_LIVE_END) @@ -64,8 +64,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -128,8 +128,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } LiveNetManager.get(CommonAppContext.sInstance) .addChatCount(LiveActivity.mStream, new com.yunbao.common.http.base.HttpCallback() { @@ -212,11 +212,10 @@ public class SocketRyChatUtil { if (code == 0) { EventBus.getDefault().post("stop_svga_new_user_double1"); } - } }); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -264,8 +263,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -401,8 +400,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -471,8 +470,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -518,8 +517,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -555,8 +554,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -598,8 +597,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -635,8 +634,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -675,8 +674,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -779,8 +778,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index c5b55e527..57e2d62ae 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -2,10 +2,7 @@ package com.yunbao.live.socket; import static com.blankj.utilcode.util.SnackbarUtils.dismiss; import static com.blankj.utilcode.util.ViewUtils.runOnUiThread; -import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; -import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import static com.yunbao.common.Constants.SOCKET_LIVE_MSG_TO_USER; -import static com.yunbao.common.Constants.isAnchor; import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK; import static com.yunbao.live.views.LiveRoomViewHolder.getIsHot; @@ -22,7 +19,6 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.GsonUtils; -import com.google.gson.Gson; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; @@ -30,7 +26,6 @@ import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.FansModel; import com.yunbao.common.bean.GuardMaturityDateRemindModel; import com.yunbao.common.bean.LinkMicUserBean; -import com.yunbao.common.bean.LiveInfoModel; import com.yunbao.common.bean.LiveUserGiftBean; import com.yunbao.common.bean.MsgModel; import com.yunbao.common.bean.PkRankBean; @@ -51,7 +46,6 @@ import com.yunbao.common.event.SendBlindGiftEvent; import com.yunbao.common.event.SendMoneyLongEndEvent; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; -import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.MicUserManager; import com.yunbao.common.manager.MicedUserManager; @@ -59,7 +53,6 @@ import com.yunbao.common.manager.NewLevelManager; import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.L; -import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; @@ -80,7 +73,7 @@ import com.yunbao.live.event.LiveAnchorEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.views.LiveEndViewHolder; import com.yunbao.live.views.LivePlayKsyViewHolder; -import com.yunbao.live.views.LivePlayRyViewHolder; +import com.yunbao.live.views.LivePlaySwViewHolder; import com.yunbao.live.views.LivePushRyViewHolder; import com.yunbao.live.views.LiveRoomViewHolder; @@ -92,26 +85,21 @@ import java.util.List; import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.base.RTCErrorCode; -import io.agora.beautyapi.faceunity.agora.SWManager; -import io.rong.imlib.IRongCallback; import io.rong.imlib.IRongCoreCallback; import io.rong.imlib.IRongCoreEnum; -import io.rong.imlib.RongIMClient; import io.rong.imlib.chatroom.base.RongChatRoomClient; -import io.rong.imlib.model.Conversation; -import io.rong.message.TextMessage; public class SocketRyClient { private final String TAG = "socket"; private String mLiveUid; private String mStream; - public static SocketRyClient.SocketHandler mSocketHandler; + public static SocketHandler mSocketHandler; private Context mContext; public SocketRyClient(String mLiveUid, SocketMessageListener listener, Activity mContext) { this.mContext = mContext; - mSocketHandler = new SocketRyClient.SocketHandler(listener); + mSocketHandler = new SocketHandler(listener); mSocketHandler.setLiveUid(mLiveUid); RongChatRoomClient.getInstance().joinChatRoom("g" + mLiveUid, -1, new IRongCoreCallback.OperationCallback() { @Override @@ -208,7 +196,6 @@ public class SocketRyClient { //用户连麦 case Constants.LIAN_MAI: int actions = map.getIntValue("action"); - L.eSw("用户连麦:actions"+actions); //主播邀请用户连麦消息 if (actions == 1) { EventBus.getDefault().post("inviteMic"); @@ -217,7 +204,10 @@ public class SocketRyClient { EventBus.getDefault().post("UsertoRY"); } else if (actions == 5) { JSONObject mic_data = map.getJSONObject("ct"); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_MIC_LIST).setObject(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(), LinkMicUserBean.class))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_MIC_LIST) + .setObject(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(), LinkMicUserBean.class)) + ); MicedUserManager.get().upDataMicUserList(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(), LinkMicUserBean.class)); } else if (actions == 6) { if (WordUtil.isNewZh()) { @@ -226,9 +216,10 @@ public class SocketRyClient { ToastUtil.show("The host has disabled the voice connection function"); } EventBus.getDefault().post("endMic"); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CLOSE).setObject(map.toJavaObject(LinkMicUserBean.class))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CLOSE) + .setObject(map.toJavaObject(LinkMicUserBean.class))); } else if (actions == 8) { - //提下買,退出 if (WordUtil.isNewZh()) { ToastUtil.show("您已被移出多人語音連麥"); } else { @@ -236,16 +227,24 @@ public class SocketRyClient { } EventBus.getDefault().post("endMic"); } else if (actions == 3) { - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC).setObject(map.toJavaObject(LinkMicUserBean.class))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC) + .setObject(map.toJavaObject(LinkMicUserBean.class)) + ); MicUserManager.get().upDataMicUser(map); } else if (actions == 7) {//取消连麦 - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CANCEL)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CANCEL) + ); MicUserManager.get().removeMiscUser(map); } break; case Constants.UP_USER_LIST: mListener.onUpUserList(map.getJSONObject("ct")); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_AUDIENCE_LIST).setObject(JSON.parseArray(map.getJSONObject("ct").getString("userlist"), LiveUserGiftBean.class))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_AUDIENCE_LIST) + .setObject(JSON.parseArray(map.getJSONObject("ct").getString("userlist"), LiveUserGiftBean.class)) + ); break; case Constants.CARD: // LiveLinkMicPresenter.setHD(map.getString("ct")); @@ -264,7 +263,9 @@ public class SocketRyClient { } else { if (!WordUtil.isNewZh() && map.getString("ct").contains("退出比賽") && map.getString("ct").contains("獲得勝利")) { String ctTmp = map.getString("ct"); - ctTmp = ctTmp.replace("由於", "Due to").replace("退出比賽", "withdrawing from the competition").replace("獲得勝利", "won"); + ctTmp = ctTmp.replace("由於", "Due to") + .replace("退出比賽", "withdrawing from the competition") + .replace("獲得勝利", "won"); map.put("ct", ctTmp); } systemChatMessage2(map.getString("ct")); @@ -276,15 +277,15 @@ public class SocketRyClient { if (LivePlayKsyViewHolder.leave != null) { LivePlayKsyViewHolder.leave.setVisibility(View.VISIBLE); } - if (LivePlayRyViewHolder.leave != null) { - LivePlayRyViewHolder.leave.setVisibility(View.VISIBLE); + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.VISIBLE); } } else if (action21 == 13 && map.getString("ct").contains("回來")) { if (LivePlayKsyViewHolder.leave != null) { LivePlayKsyViewHolder.leave.setVisibility(View.GONE); } - if (LivePlayRyViewHolder.leave != null) { - LivePlayRyViewHolder.leave.setVisibility(View.GONE); + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.GONE); } } break; @@ -313,7 +314,6 @@ public class SocketRyClient { // break; case Constants.SOCKET_LIVE_DRPK_RANDOM: case Constants.SOCKET_LIVE_DRPK://多人PK - L.eSw("map"+new Gson().toJson(map)); int action3 = map.getIntValue("action"); //收到多人PK邀请 if (action3 == 1) { @@ -324,65 +324,59 @@ public class SocketRyClient { } //收到对方同意多人PK邀请 else if (action3 == 2) { - if("0".equals(map.getString("msgtype"))){ - return; - } - UserBean u = new UserBean(); -// u.setUserNiceName(map.getString("uname")); - u.setId(map.getString("pkuid")); - L.eSw("action3 == 2:"+u.getId()); - L.eSw("收到对方同意多人PK邀请"); - mListener.onLinkDRMicPkApplyOk(u); - SWManager.get().setDimensions(3);//退出直播间,将分别率设置为 VD_840x480 +// UserBean u = new UserBean(); +//// u.setUserNiceName(map.getString("uname")); +// u.setId(map.getString("uid")); +// mListener.onLinkDRMicPkApplyOk(u); } else if (action3 == 6) {//开始Pk if (LiveRoomViewHolder.mHandler != null) { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); } // LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, map.getIntValue("drpk_time")); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE).setPkScores(map.getJSONArray("userlist")).setUid(mLiveUid).setTime(map.getIntValue("drpk_time"))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE) + .setPkScores(map.getJSONArray("userlist")) + .setUid(mLiveUid) + .setTime(map.getIntValue("drpk_time"))); if (livePushRyViewHolder == null) { // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) + ); } + + } else if (action3 == 5) { // endDRGif(); LiveRoomViewHolder.d_pk_view.setVisibility(View.GONE); if (LiveRyAnchorActivity.mLiveAnchorViewHolder != null) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); params.topMargin = 0; - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LEAVE_DR_ROOM)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LEAVE_DR_ROOM)); isDRPK = 0; } else { // LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview(); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW) + ); + } - SWManager.get().setDimensions(0);//退出直播间,将分别率设置为 VD_840x480 //創建了多人房間 } else if (action3 == 3) { - L.eSw("創建了多人房間action3 == 3"); /* if (LiveAudienceActivity.getmLivePlayViewHolder() != null) { LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); }*/ - if(livePushRyViewHolder==null){ - if("4".equals(map.getString("msgtype"))){ - return; - } - UserBean u = new UserBean(); -// u.setUserNiceName(map.getString("uname")); - u.setId(map.getString("uid")); - if(StringUtil.isEmpty(u.getId())){ - return; - } - L.eSw("通知用户 action3 == 3:"+u.getId()); - mListener.onLinkDRMicPKToUser(u); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); - isDRPK = 1; - } + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) + ); + isDRPK = 1; } else if (action3 == 10) { - //显示pk分数 if (!map.getString("uid").equals(CommonAppConfig.getInstance().getUid())) { // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) + ); } } @@ -395,7 +389,7 @@ public class SocketRyClient { receiveGiftBean.setSendtype(map.getIntValue("action")); receiveGiftBean.setAllServerNotify(true); mListener.onSys(receiveGiftBean); - } else if (action2 == 61) {//赠送礼物 + } else if (action2 == 61) {//赠送礼物 超级头条 sendGiftByNotify(map); } else if (action2 == 62) {//购买守护 // buyGuardByNotify(map); @@ -408,7 +402,7 @@ public class SocketRyClient { buyZuoJiByNotify(map); } else if (action2 == 66) {//购买贵族 buyVipByNotify(map); - } else if (action2 == 88) { + } else if (action2 == 88) {//盲盒 JSONObject mCt = map.getJSONObject("ct"); String boxType = map.getString("box_type"); String boxTypeName = ""; @@ -419,19 +413,39 @@ public class SocketRyClient { } else { boxTypeName = WordUtil.isNewZh() ? "PD盲盒" : "PD blind box"; } - AllServerNotifyEvent allServerNotifyEvent = new AllServerNotifyEvent().setBlindBoxId(map.getString("blind_box_id")).setBoxType(boxType).setBoxTypeName(boxTypeName).setDressName(WordUtil.isNewZh() ? map.getString("dress_name") : TextUtils.isEmpty(map.getString("dress_nameen")) ? map.getString("dress_name") : map.getString("dress_nameen")).setGiftNotification(map.getString("gift_notification")).setGiftName(WordUtil.isNewZh() ? mCt.getString("giftname") : mCt.getString("giftnameen")).setUserNiceName(map.getString("uname")).setGiftIcon(map.getString("gifticon")).setAnchorName(map.getString("ancherName")).setDisplaySrc(map.getString("display_src")); + AllServerNotifyEvent allServerNotifyEvent + = new AllServerNotifyEvent() + .setBlindBoxId(map.getString("blind_box_id")) + .setBoxType(boxType) + .setBoxTypeName(boxTypeName) + .setDressName(WordUtil.isNewZh() ? map.getString("dress_name") : TextUtils.isEmpty(map.getString("dress_nameen")) ? map.getString("dress_name") : map.getString("dress_nameen")) + .setGiftNotification(map.getString("gift_notification")) + .setGiftName(WordUtil.isNewZh() ? mCt.getString("giftname") : mCt.getString("giftnameen")) + .setUserNiceName(map.getString("uname")) + .setGiftIcon(map.getString("gifticon")) + .setAnchorName(map.getString("ancherName")) + .setDisplaySrc(map.getString("display_src")); Log.e("AllServerNotifyEvent", allServerNotifyEvent.toString()); Log.e("AllServerNotifyEvent", map.toJSONString()); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX).setAllServerNotifyEvent(allServerNotifyEvent)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX) + .setAllServerNotifyEvent(allServerNotifyEvent)); } else if (action2 == 89) {//红包 JSONObject mCt = map.getJSONObject("ct"); - AllServerNotifyEvent allServerNotifyEvent = new AllServerNotifyEvent().setUserNiceName(mCt.getString("user_nicename")).setGiftName(WordUtil.isNewZh() ? map.getString("giftname") : map.getString("giftname_en")).setGiftIcon(mCt.getString("gifticon")).setRedPacket(true); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX).setAllServerNotifyEvent(allServerNotifyEvent)); + AllServerNotifyEvent allServerNotifyEvent + = new AllServerNotifyEvent() + .setUserNiceName(mCt.getString("user_nicename")) + .setGiftName(WordUtil.isNewZh() ? map.getString("giftname") : map.getString("giftname_en")) + .setGiftIcon(mCt.getString("gifticon")) + .setRedPacket(true); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX) + .setAllServerNotifyEvent(allServerNotifyEvent)); } else if (action2 == 90) { NewAllServerNotifyGuardEvent notifyGuardEvent = GsonUtils.fromJson(map.toString(), NewAllServerNotifyGuardEvent.class); Bus.get().post(notifyGuardEvent); buyGuardInSameRoom(map); - } else if (action2 == 91) { + } else if (action2 == 91) {//通用模板 AllServerNotifyFFGGGDJANEvent notifyFFGGGDJANEvent = GsonUtils.fromJson(map.toString(), AllServerNotifyFFGGGDJANEvent.class); Bus.get().post(notifyFFGGGDJANEvent); } @@ -459,7 +473,12 @@ public class SocketRyClient { mListener.onAnchorInvalid(); } //主播强制下播 - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_END).setVotes(map.getString("votes")).setLength(map.getString("length")).setNums(map.getIntValue("nums")).setUname(map.getString("uname"))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LIVE_END) + .setVotes(map.getString("votes")) + .setLength(map.getString("length")) + .setNums(map.getIntValue("nums")) + .setUname(map.getString("uname"))); break; case Constants.SOCKET_CHANGE_LIVE://主播切换计时收费类型 mListener.onChangeTimeCharge(map.getIntValue("type_val")); @@ -484,7 +503,7 @@ public class SocketRyClient { case Constants.SOCKET_BUY_GUARD://购买守护 buyGuardInSameRoom(map); break; - case Constants.SOCKET_LINK_MIC://连麦-old + case Constants.SOCKET_LINK_MIC://连麦 processLinkMic(map); break; case Constants.SOCKET_LINK_MIC_ANCHOR://主播连麦 @@ -600,7 +619,9 @@ public class SocketRyClient { List msg = model.getMsg(); if (msg.size() > 0) { // EventBus.getDefault().post(msg.get(0)); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.TRUMPET_NOTIFY).setMsgModel(msg.get(0))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.TRUMPET_NOTIFY) + .setMsgModel(msg.get(0))); } break; case Constants.RECOMMEND_CARD_NOTIFY://推荐卡消息通知 @@ -608,7 +629,9 @@ public class SocketRyClient { List recommendCardNotifyMsg = recommendCardNotifyModel.getMsg(); if (recommendCardNotifyMsg.size() > 0) { - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.RECOMMEND_CARD_NOTIFY).setMsgModel(recommendCardNotifyMsg.get(0))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.RECOMMEND_CARD_NOTIFY) + .setMsgModel(recommendCardNotifyMsg.get(0))); } break; case Constants.STAR_CHALLENGE_UPDATE://星级助力 @@ -625,21 +648,29 @@ public class SocketRyClient { case Constants.AI_AUTOMATIC_SPEECH_LIVE: //{"name_color":"#f19ec2","ai_name":"助手小小P","content":"@1 ","user_name":"1","icon":"https://downs.yaoulive.com/xzs_tab.png","system_bubble":"https://downs.yaoulive.com/xzs_qipao.9.png"} AiAutomaticSpeechModel aiAutomaticSpeechModel = GsonUtils.fromJson(map.getString("ct"), AiAutomaticSpeechModel.class); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.AI_AUTOMATIC_SPEECH).setAiAutomaticSpeechModel(aiAutomaticSpeechModel)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.AI_AUTOMATIC_SPEECH) + .setAiAutomaticSpeechModel(aiAutomaticSpeechModel)); break; case Constants.STAR_CHALLENGE_UPGRADE_NOTIFY: SocketModel starChallengeUpgradeNotify = GsonUtils.fromJson(socketMsg, SocketModel.class); List starChallengeUpgradeNotifyMsg = starChallengeUpgradeNotify.getMsg(); if (starChallengeUpgradeNotifyMsg.size() > 0) { - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.STAR_CHALLENGE_UPGRADE_NOTIFY).setMsgModel(starChallengeUpgradeNotifyMsg.get(0))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.STAR_CHALLENGE_UPGRADE_NOTIFY) + .setMsgModel(starChallengeUpgradeNotifyMsg.get(0))); } break; case Constants.LuckyAngel: - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LUCKY_ANGEL).setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LUCKY_ANGEL) + .setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); break; case Constants.Lucky100Check: - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LUCKY_100_CHECK).setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LUCKY_100_CHECK) + .setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); break; case Constants.PK_RANK_UPDATE: Log.i("PK排位", map.toString()); @@ -649,68 +680,117 @@ public class SocketRyClient { pkRankBean.setName(item.getString("new_rank_name")); pkRankBean.setImg(item.getString("new_rank_img")); pkRankBean.setNewRankNameEn(item.getString("new_rank_name_en")); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_UPDATE).setObject(pkRankBean)); + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_UPDATE) + .setObject(pkRankBean)); break; case Constants.CUSTOM_FULL_SERVICE_NOTIFY: Log.e("全服通知", map.toString()); CustomFullServiceNotifyEvent customFullServiceNotifyEvent = GsonUtils.fromJson(map.toString(), CustomFullServiceNotifyEvent.class); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.CUSTOM_FULL_SERVICE_NOTIFY).setCustomFullServiceNotifyEvent(customFullServiceNotifyEvent)); + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.CUSTOM_FULL_SERVICE_NOTIFY) + .setCustomFullServiceNotifyEvent(customFullServiceNotifyEvent)); break; case Constants.XYD_COMPLETE: // xydComplete(map); XydCompleteModel xydCompleteModel = GsonUtils.fromJson(map.toString(), XydCompleteModel.class); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.XYD_COMPLETE).setXydCompleteModel(xydCompleteModel).setLiveReceiveGiftBean(JSON.parseObject(map.toString(), LiveReceiveGiftBean.class))); + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.XYD_COMPLETE) + .setXydCompleteModel(xydCompleteModel) + .setLiveReceiveGiftBean(JSON.parseObject(map.toString(), LiveReceiveGiftBean.class))); break; case "GuardSpecialEffect": LiveReceiveGiftBean giftBean = JSON.parseObject(map.toString(), LiveReceiveGiftBean.class); giftBean.setMedal_name(map.getString("medal_name")); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GuardSpecialEffect).setLiveReceiveGiftBean(giftBean)); + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.GuardSpecialEffect) + .setLiveReceiveGiftBean(giftBean)); break; case Constants.WISH_LIST_PROGRESS: StringBuffer conString = new StringBuffer(); conString.append(WordUtil.isNewZh() ? map.getString("msg") : map.getString("msg_en")); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.WISH_LIST_PROGRESS).setWishListProgress(new WishModel().setWishlistProgress(map.getString("wishlist_progress")).setWishlistIcon(map.getString("wishlist_icon")).setWishlistName(map.getString("wishlist_name")).setWishlistNum(map.getString("wishlist_num")).setGiftType(map.getInteger("giftId")).setLuid(conString.toString())).setUname(map.getString("userName")).setLiveType(Integer.parseInt(map.getString("level")))); + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.WISH_LIST_PROGRESS) + .setWishListProgress(new WishModel() + .setWishlistProgress(map.getString("wishlist_progress")) + .setWishlistIcon(map.getString("wishlist_icon")) + .setWishlistName(map.getString("wishlist_name")) + .setWishlistNum(map.getString("wishlist_num")) + .setGiftType(map.getInteger("giftId")) + .setLuid(conString.toString())).setUname(map.getString("userName")).setLiveType(Integer.parseInt(map.getString("level")))); break; case Constants.LIVE_VOTE_CREATE: - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.VOTE_CREATE).setObject(map)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.VOTE_CREATE) + .setObject(map) + ); break; case Constants.LIVE_VOTE_END: - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.VOTE_END).setObject(map)); - EventBus.getDefault().post(new LiveAnchorEvent().setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_END).setObject(map)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.VOTE_END) + .setObject(map) + ); + EventBus.getDefault().post(new LiveAnchorEvent() + .setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_END) + .setObject(map) + ); break; case Constants.LIVE_VOTE_UPDATE: //通知给观众 - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.VOTE_UPDATE).setObject(map)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.VOTE_UPDATE) + .setObject(map) + ); //通知给主播 - EventBus.getDefault().post(new LiveAnchorEvent().setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_UPDATE).setObject(map)); + EventBus.getDefault().post(new LiveAnchorEvent() + .setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_UPDATE) + .setObject(map) + ); break; case Constants.LIVE_PK_END: - mListener.onEndPk(map.getLong("uid"), map.getLong("pkuid"), map.getLong("uid_score"), map.getLong("pkuid_score"), JSONObject.parseObject(map.getJSONObject("ct").getJSONObject("pk_top_users").toJSONString(), LivePKUserListBean.class)); + mListener.onEndPk(map.getLong("uid"), + map.getLong("pkuid"), + map.getLong("uid_score"), + map.getLong("pkuid_score"), + JSONObject.parseObject(map.getJSONObject("ct").getJSONObject("pk_top_users").toJSONString(), LivePKUserListBean.class) + ); break; case Constants.RED_PACKET: RedPacketModel redPacketModel = GsonUtils.fromJson(map.toString(), RedPacketModel.class); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET).setRedPacketModel(redPacketModel)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET) + .setRedPacketModel(redPacketModel)); break; case Constants.RED_PACKET_SUPER_JACKPOT: RedPacketInfoModel redPacketInfoModel = GsonUtils.fromJson(map.toString(), RedPacketInfoModel.class); - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET_SUPER_JACKPOT).setRedPacketInfoModel(redPacketInfoModel)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET_SUPER_JACKPOT) + .setRedPacketInfoModel(redPacketInfoModel)); break; case "GiftWallIlluminate": Log.e("GiftWallIlluminate", map.toString()); - Bus.get().post(new GiftWallIlluminateEvent().setNewNumber(map.getInteger("new_number")).setMaxNumber(map.getInteger("max_number"))); + Bus.get().post(new GiftWallIlluminateEvent() + .setNewNumber(map.getInteger("new_number")) + .setMaxNumber(map.getInteger("max_number"))); break; case SOCKET_LIVE_MSG_TO_USER: sendToUserMsg(map); break; case "SudGameCreateRoom": - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SUD_GAME_CREATE_ROOM).setAvatar(WordUtil.isNewZh() ? map.getString("sud_game_name") : map.getString("sud_game_name_en")).setCreateSudRoomModel(GsonUtils.fromJson(map.toString(), SudGameDateModel.class))); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.SUD_GAME_CREATE_ROOM) + .setAvatar(WordUtil.isNewZh() ? map.getString("sud_game_name") : map.getString("sud_game_name_en")) + .setCreateSudRoomModel(GsonUtils.fromJson(map.toString(), SudGameDateModel.class))); break; case "sendQuickGift": SendQuickGiftModel sendQuickGiftModel = GsonUtils.fromJson(map.toString(), SendQuickGiftModel.class); StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append(sendQuickGiftModel.getUserNicename()).append(WordUtil.isNewZh() ? " 送出了 " : " sent ").append(sendQuickGiftModel.getQuickGiftNumber()).append(WordUtil.isNewZh() ? " 個小PD " : " small pandas "); + stringBuffer.append(sendQuickGiftModel.getUserNicename()) + .append(WordUtil.isNewZh() ? " 送出了 " : " sent ") + .append(sendQuickGiftModel.getQuickGiftNumber()) + .append(WordUtil.isNewZh() ? " 個小PD " : " small pandas "); systemChatMessage2(stringBuffer.toString()); Bus.get().post(new QuickGiftingEvent().setHotNum(sendQuickGiftModel.getHotNum())); break; @@ -725,7 +805,9 @@ public class SocketRyClient { pkRankBean.setRedVal(item.getString("uid_win_continuity")); pkRankBean.setPkTopImgUrl(item.getString("pktt_img")); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_START).setObject(pkRankBean)); + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_START) + .setObject(pkRankBean)); break; case "guardMaturityDateRemind": GuardMaturityDateRemindModel maturityDateRemindModel = GsonUtils.fromJson(map.toString(), GuardMaturityDateRemindModel.class); @@ -738,6 +820,13 @@ public class SocketRyClient { case "SendMoneyLongEnd": Bus.get().post(new SendMoneyLongEndEvent()); break; + case Constants.SOCKET_LIVE_ANCHOR_PK_DIALOG: + item = map.getJSONObject("ct"); + //DialogUitl.showSimpleDialog(mContext,WordUtil.isNewZh()?item.getString("text"):item.getString("text_en"),null); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LIVE_DIALOG_ANCHOR_TIPS) + .setObject(WordUtil.isNewZh() ? item.getString("text") : item.getString("text_en"))); + break; } } @@ -900,6 +989,7 @@ public class SocketRyClient { chatBean.setBubble(map.getString("bubble")); chatBean.setMedal(map.getString("medal")); chatBean.setMedal_new(map.getString("medal_new")); + chatBean.setMedal_new_en(map.getString("medal_new_en")); chatBean.setVipType(map.getIntValue("vip_type")); chatBean.setVipType(map.getIntValue("vip_type")); chatBean.setMedal_honor(map.getString("medal_honor")); @@ -957,6 +1047,7 @@ public class SocketRyClient { chatBean.setBubble(obj.getString("bubble")); chatBean.setMedal(obj.getString("medal")); chatBean.setMedal_new(obj.getString("medal_new")); + chatBean.setMedal_new_en(map.getString("medal_new_en")); chatBean.setHot_num(obj.getString("hot_num")); UserBean.DressBean dressBean = new UserBean.DressBean(); dressBean.setAvatar_frame(obj.getString("avatar_frame")); @@ -977,7 +1068,8 @@ public class SocketRyClient { FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); u.setFansLevel(obj.getIntValue("medal_level")); u.setFansEnterRoomUrl(obj.getString("medal_backgroup_thumb")); - if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + if (fansMedalBean != null) + chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); mListener.onEnterRoom(new LiveEnterRoomBean(u, chatBean)); } } @@ -1009,7 +1101,8 @@ public class SocketRyClient { //增加粉丝徽章信息 chatBean.setMedalNmae(map.getString("medal_name")); FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); - if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + if (fansMedalBean != null) + chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); //聊天列表显示 玩家名 送 1 个 礼物名 if (CommonAppContext.lang.equals("chinese")) { @@ -1034,7 +1127,8 @@ public class SocketRyClient { mListener.onSendGift(receiveGiftBean, null); } //同一个直播间时才刷新pk - if (mLiveUid.equals(map.getString("pkuid1")) || mLiveUid.equals(map.getString("pkuid2"))) { + if (mLiveUid.equals(map.getString("pkuid1")) || + mLiveUid.equals(map.getString("pkuid2"))) { mListener.onSendGiftPk(map.getLongValue("pktotal2"), map.getLongValue("pktotal1"), livePKUserListBean); } } @@ -1069,6 +1163,7 @@ public class SocketRyClient { chatBean.setBubble(map.getString("bubble")); chatBean.setMedal(map.getString("medal")); chatBean.setMedal_new(map.getString("medal_new")); + chatBean.setMedal_new_en(map.getString("medal_new_en")); chatBean.setGood_nub(map.getString("good_num")); chatBean.setType(LiveChatBean.GIFT); if (map.get("guard_type") != null && !"".equals(map.get("guard_type")) && !"null".equals(map.get("guard_type"))) { @@ -1116,21 +1211,32 @@ public class SocketRyClient { chatBean.setBubble(map.getString("bubble")); chatBean.setMedal(map.getString("medal")); chatBean.setMedal_new(map.getString("medal_new")); + chatBean.setMedal_new_en(map.getString("medal_new_en")); chatBean.setGood_nub(map.getString("good_num")); chatBean.setType(LiveChatBean.GIFT); if (map.get("guard_type") != null && !"".equals(map.get("guard_type")) && !"null".equals(map.get("guard_type"))) { chatBean.setGuardType(map.getInteger("guard_type")); } - - if (WordUtil.isNewZh()) { - chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + receiveGiftBean.getGiftCount() + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftName()); + String special = ""; + if (sendBlindGiftEvent.getSpecialGift() == 1) { + if (WordUtil.isNewZh()) { + special = "送出" + receiveGiftBean.getGiftName() + sendBlindGiftEvent.getSpecialGiftName(); + } else { + special = "Send " + receiveGiftBean.getGiftName() + sendBlindGiftEvent.getSpecialGiftNameEn(); + } + chatBean.setContent(special); } else { - chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + " " + +receiveGiftBean.getGiftCount() + " " + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftnameen()); + if (WordUtil.isNewZh()) { + chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + receiveGiftBean.getGiftCount() + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftName() + special); + } else { + chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + " " + +receiveGiftBean.getGiftCount() + " " + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftnameen() + special); + } } //增加粉丝徽章信息 chatBean.setMedalNmae(map.getString("medal_name")); FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); - if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + if (fansMedalBean != null) + chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); receiveGiftBean.setLiveChatBean(chatBean); @@ -1158,7 +1264,11 @@ public class SocketRyClient { } if (map.getIntValue("drpk_status") == 1) { - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE).setPkScores(map.getJSONArray("userlist")).setUid(mLiveUid).setTime(0)); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE) + .setPkScores(map.getJSONArray("userlist")) + .setUid(mLiveUid) + .setTime(0)); // LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, 0); } @@ -1284,53 +1394,55 @@ public class SocketRyClient { private void processAnchorLinkMicPk(JSONObject map) { int action = map.getIntValue("action"); Log.i("Socket", "action = " + action + " json = " + map.toString()); - L.eSw("处理主播与主播PK逻辑action = " + action + " json = " + map.toString()); + L.eSw("RY RY RY RY "+map.toString()); switch (action) { case 1://收到对方主播PK回调 UserBean u = new UserBean(); u.setId(map.getString("uid")); u.setUserNiceName(map.getString("pkname")); u.setAvatar(map.getString("pkhead")); - u.setRandomPk("11".equals(map.getString("msgtype"))); - mListener.onLinkMicPkApply(u, map.getString("stream"), "11".equals(map.getString("msgtype"))?2:1); + mListener.onLinkMicPkApply(u, map.getString("stream"), 1); break; case 2://收到对方主播PK回调 - L.eSw("收到对方主播PK回调"); RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); - mListener.onLinkMicToPk(map.getString("uid"), map.getString("uhead"), map.getString("uhead")); - mListener.onLinkMicPkStart(map.getString("uid"), map.getString("uhead"), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); - if (livePushRyViewHolder != null) { - UserBean userBean = new UserBean(); - userBean.setId(map.getString("uid")); - userBean.setAvatar(map.getString("uhead")); - userBean.setUserNiceName(map.getString("uname")); - livePushRyViewHolder.setAnPkRtc(userBean); - } + mListener.onLinkMicToPk(map.getString("uid"), map.getString("pkhead"), map.getString("pkname")); + mListener.onLinkMicPkStart(map.getString("uid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); break; case 3://对方主播拒绝PK的回调 RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); mListener.onLinkMicPkRefuse(); break; case 4://所有人收到PK开始址的回调 - L.eSw("所有人收到PK开始址的回调"); // RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(map.getString("pkuid"))); mListener.onLinkMicPkStart(map.getString("pkuid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders")); break; case 5://PK时候断开连麦的回调 // if (rtcRoom != null) { - Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.DISCONNEXT_PK_TIME)); - //断开连麦 - HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout").execute(new HttpCallback() { + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.DISCONNEXT_PK_TIME)); + RCRTCEngine.getInstance().leaveOtherRoom(map.getString("pkuid"), true, new IRCRTCResultCallback() { @Override - public void onSuccess(int code, String msg, String[] info) { + public void onSuccess() { + Log.e("ry", map.getString("pkuid") + "退出多人成功a as"); + + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", map.getString("pkuid") + "退asa出多人失败" + rtcErrorCode); } }); + //断开连麦 + HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + } + }); // } - if (livePushRyViewHolder != null) { - livePushRyViewHolder.onLinkMicAnchorClose(); - } mListener.onLinkMicPkClose(1); if (RandomPkManager.getInstance().isRandomModel()) { RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_DEFAULT); @@ -1344,67 +1456,11 @@ public class SocketRyClient { break; case 9://pk结束的回调 mListener.onLinkMicPkEnd(map.getString("win_uid")); - EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END).setObject(map.getString("uid"))); - if (livePushRyViewHolder != null) { - livePushRyViewHolder.onLinkMicAnchorClose(); - } + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END)); break; case 10://系统发起PK回调 - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 2) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 2) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(map.getString("uid"), conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); - - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); - - LiveNetManager.get(mContext).getLiveInfo(map.getString("uid"), new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - mListener.onLinkMicToPk(map.getString("uid"), data.getAvatar(), map.getString("uhead")); - mListener.onLinkMicPkStart(map.getString("uid"), data.getAvatar(), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); - if (livePushRyViewHolder != null) { - UserBean userBean = new UserBean(); - userBean.setId(map.getString("uid")); - userBean.setAvatar(data.getAvatar()); - userBean.setUserNiceName(map.getString("uname")); - livePushRyViewHolder.setAnPkRtc(userBean); - } - } - - @Override - public void onError(String error) { - - } - } - ); - - /*JSONObject msg1 = new JSONObject(); + JSONObject msg1 = new JSONObject(); msg1.put("type", "autoLivePK"); msg1.put("uid", CommonAppConfig.getInstance().getUid()); msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); @@ -1442,7 +1498,7 @@ public class SocketRyClient { ToastUtil.show("invite " + map.getString("uid") + " lose :" + rtcErrorCode); } } - });*/ + }); break; } } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyLinkMicPkUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketRyLinkMicPkUtil.java index a7f947d55..6049239b0 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyLinkMicPkUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyLinkMicPkUtil.java @@ -7,7 +7,7 @@ import com.yunbao.common.Constants; import com.yunbao.common.bean.UserBean; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; @@ -73,7 +73,7 @@ public class SocketRyLinkMicPkUtil { TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); Message message1 = Message.obtain("g" + CommonAppConfig.getInstance().getUid(), conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message1, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message1, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(Message message) { @@ -136,7 +136,7 @@ public class SocketRyLinkMicPkUtil { TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); Message message = Message.obtain(pkUid, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(Message message) { diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java new file mode 100644 index 000000000..aec44def7 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -0,0 +1,1441 @@ +package com.yunbao.live.socket; + +import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; +import static com.yunbao.common.Constants.SOCKET_LIVE_MSG_TO_USER; +import static com.yunbao.live.activity.LiveSwAnchorActivity.isDRPK; +import static com.yunbao.live.views.LiveRoomViewHolder.getIsHot; + +import android.app.Activity; +import android.content.Context; +import android.os.Handler; +import android.os.Message; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.widget.LinearLayout; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.blankj.utilcode.util.GsonUtils; +import com.google.gson.Gson; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.CommonAppContext; +import com.yunbao.common.Constants; +import com.yunbao.common.bean.AiAutomaticSpeechModel; +import com.yunbao.common.bean.FansModel; +import com.yunbao.common.bean.GuardMaturityDateRemindModel; +import com.yunbao.common.bean.LinkMicUserBean; +import com.yunbao.common.bean.LiveInfoModel; +import com.yunbao.common.bean.LiveUserGiftBean; +import com.yunbao.common.bean.MsgModel; +import com.yunbao.common.bean.PkRankBean; +import com.yunbao.common.bean.RedPacketInfoModel; +import com.yunbao.common.bean.RedPacketModel; +import com.yunbao.common.bean.SendMoneyLongModel; +import com.yunbao.common.bean.SocketModel; +import com.yunbao.common.bean.SudGameDateModel; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.bean.WishModel; +import com.yunbao.common.bean.XydCompleteModel; +import com.yunbao.common.event.AllServerNotifyEvent; +import com.yunbao.common.event.AllServerNotifyFFGGGDJANEvent; +import com.yunbao.common.event.CustomFullServiceNotifyEvent; +import com.yunbao.common.event.GiftWallIlluminateEvent; +import com.yunbao.common.event.QuickGiftingEvent; +import com.yunbao.common.event.SendBlindGiftEvent; +import com.yunbao.common.event.SendMoneyLongEndEvent; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.MicUserManager; +import com.yunbao.common.manager.MicedUserManager; +import com.yunbao.common.manager.NewLevelManager; +import com.yunbao.common.manager.RandomPkManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; +import com.yunbao.live.adapter.LiveChatAdapter; +import com.yunbao.live.bean.LiveBuyGuardMsgBean; +import com.yunbao.live.bean.LiveChatBean; +import com.yunbao.live.bean.LiveDanMuBean; +import com.yunbao.live.bean.LiveEnterRoomBean; +import com.yunbao.live.bean.LiveGiftPrizePoolWinBean; +import com.yunbao.live.bean.LiveLuckGiftWinBean; +import com.yunbao.live.bean.LivePKUserListBean; +import com.yunbao.live.bean.LiveReceiveGiftBean; +import com.yunbao.live.bean.NewAllServerNotifyGuardEvent; +import com.yunbao.live.bean.SendQuickGiftModel; +import com.yunbao.live.event.LiveAnchorEvent; +import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.views.LiveEndViewHolder; +import com.yunbao.live.views.LivePlayKsyViewHolder; +import com.yunbao.live.views.LivePlaySwViewHolder; +import com.yunbao.live.views.LivePushSwViewHolder; +import com.yunbao.live.views.LiveRoomViewHolder; + +import org.greenrobot.eventbus.EventBus; + +import java.lang.ref.WeakReference; +import java.util.List; + +import io.agora.beautyapi.faceunity.agora.SWManager; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.IRongCoreCallback; +import io.rong.imlib.IRongCoreEnum; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.chatroom.base.RongChatRoomClient; +import io.rong.imlib.model.Conversation; +import io.rong.message.TextMessage; + +public class SocketSwClient { + + private final String TAG = "socket"; + private String mLiveUid; + private String mStream; + public static SocketSwClient.SocketHandler mSocketHandler; + private Context mContext; + + public SocketSwClient(String mLiveUid, SocketMessageListener listener, Activity mContext) { + this.mContext = mContext; + mSocketHandler = new SocketSwClient.SocketHandler(listener); + mSocketHandler.setLiveUid(mLiveUid); + RongChatRoomClient.getInstance().joinChatRoom("g" + mLiveUid, -1, new IRongCoreCallback.OperationCallback() { + @Override + public void onSuccess() { + Log.i("tx", "加入成功"); + + } + + @Override + public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) { + Log.i("tx", "加入" + "失败" + coreErrorCode); + if (WordUtil.isNewZh()) { + ToastUtil.show("網絡不佳無法連接,請重新進入"); + } else { + ToastUtil.show("The network is not connected, please re-enter"); + } + } + }); + } + + public void setLivePushSwViewHolder(LivePushSwViewHolder livePushSwViewHolder) { + if (mSocketHandler != null) { + mSocketHandler.setLivePushSwViewHolder(livePushSwViewHolder); + } + } + + public void disConnect() { +// V2TIMManager.getInstance(). + mLiveUid = null; + mStream = null; + mSocketHandler = null; + } + + public class SocketHandler extends Handler { + + private SocketMessageListener mListener; + private LivePushSwViewHolder livePushSwViewHolder; + private String mLiveUid; + + public SocketHandler(SocketMessageListener listener) { + mListener = new WeakReference<>(listener).get(); + } + + public void setLiveUid(String liveUid) { + mLiveUid = liveUid; + } + + public void setLivePushSwViewHolder(LivePushSwViewHolder livePushSwViewHolder) { + this.livePushSwViewHolder = livePushSwViewHolder; + } + + @Override + public void handleMessage(Message msg) { + if (mListener == null) { + return; + } + try { + switch (msg.what) { + case Constants.SOCKET_WHAT_CONN: + mListener.onConnect((Boolean) msg.obj); + break; + case Constants.SOCKET_WHAT_BROADCAST: + processBroadcast((String) msg.obj); + break; + case Constants.SOCKET_WHAT_DISCONN: + mListener.onDisConnect(); + break; + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + + public void processBroadcast(String socketMsg) { + L.e("收到socket--->" + socketMsg); + + Log.i("SocketRyClient", "socketMsg" + socketMsg); + + if (Constants.SOCKET_STOP_PLAY.equals(socketMsg)) { + mListener.onSuperCloseLive();//超管关闭房间 + return; + } + if (socketMsg.contains("LivePK_UnreadCount")) { + return; + } + SocketReceiveBean received = JSON.parseObject(socketMsg, SocketReceiveBean.class); + + JSONObject map = received.getMsg().getJSONObject(0); + + switch (map.getString("_method_")) { + //用户连麦 + case Constants.LIAN_MAI: + int actions = map.getIntValue("action"); + L.eSw("用户连麦:actions"+actions); + //主播邀请用户连麦消息 + if (actions == 1) { + EventBus.getDefault().post("inviteMic"); + //主播同意用户连麦申请 + } else if (actions == 4) { + EventBus.getDefault().post("UsertoRY"); + } else if (actions == 5) { + JSONObject mic_data = map.getJSONObject("ct"); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_MIC_LIST).setObject(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(), LinkMicUserBean.class))); + MicedUserManager.get().upDataMicUserList(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(), LinkMicUserBean.class)); + } else if (actions == 6) { + if (WordUtil.isNewZh()) { + ToastUtil.show("主播已關閉當前語音連麥功能"); + } else { + ToastUtil.show("The host has disabled the voice connection function"); + } + EventBus.getDefault().post("endMic"); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CLOSE).setObject(map.toJavaObject(LinkMicUserBean.class))); + } else if (actions == 8) { + //提下買,退出 + if (WordUtil.isNewZh()) { + ToastUtil.show("您已被移出多人語音連麥"); + } else { + ToastUtil.show("You have been removed from Multi-Voice Connection"); + } + EventBus.getDefault().post("endMic"); + } else if (actions == 3) { + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC).setObject(map.toJavaObject(LinkMicUserBean.class))); + MicUserManager.get().upDataMicUser(map); + } else if (actions == 7) {//取消连麦 + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CANCEL)); + MicUserManager.get().removeMiscUser(map); + } + break; + case Constants.UP_USER_LIST: + mListener.onUpUserList(map.getJSONObject("ct")); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_AUDIENCE_LIST).setObject(JSON.parseArray(map.getJSONObject("ct").getString("userlist"), LiveUserGiftBean.class))); + break; + case Constants.CARD: +// LiveLinkMicPresenter.setHD(map.getString("ct")); + break; + case Constants.SOCKET_SYSTEM://系统消息 + if (map.getString("ct").contains("甜蜜不停")) { + break; + } + UserBean us = CommonAppConfig.getInstance().getUserBean(); + if (map.getString("uid") != null && us != null && map.getString("uid").equals(us.getId())) { + int num = LiveAudienceActivity.fansNum + 1; + LiveRoomViewHolder.setFansNum(num); + } + if (map.getString("ct").contains("堅決維護青少年群體精神文明健康") || map.getString("ct").contains("click to register if you like. pdlive conducts")) { + systemChatMessage(map.getString("ct")); + } else { + if (!WordUtil.isNewZh() && map.getString("ct").contains("退出比賽") && map.getString("ct").contains("獲得勝利")) { + String ctTmp = map.getString("ct"); + ctTmp = ctTmp.replace("由於", "Due to").replace("退出比賽", "withdrawing from the competition").replace("獲得勝利", "won"); + map.put("ct", ctTmp); + } + systemChatMessage2(map.getString("ct")); + } + + int action21 = map.getIntValue("action"); + //主播離開 + if (action21 == 13 && map.getString("ct").contains("離開")) { + if (LivePlayKsyViewHolder.leave != null) { + LivePlayKsyViewHolder.leave.setVisibility(View.VISIBLE); + } + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.VISIBLE); + } + } else if (action21 == 13 && map.getString("ct").contains("回來")) { + if (LivePlayKsyViewHolder.leave != null) { + LivePlayKsyViewHolder.leave.setVisibility(View.GONE); + } + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.GONE); + } + } + break; + case Constants.SOCKET_KICK://踢人 + systemChatMessage2(map.getString("ct")); + mListener.onKick(map.getString("touid")); + break; + case Constants.SOCKET_SHUT_UP://禁言 + String ct = map.getString("ct"); + systemChatMessage2(ct); + mListener.onShutUp(map.getString("touid"), ct); + break; + case Constants.SOCKET_SEND_MSG://文字消息,点亮,用户进房间,这种混乱的设计是因为服务器端逻辑就是这样设计的,客户端无法自行修改 + wordLightEnterRoom(map, received); + L.e("收到socket---> 文字消息" + socketMsg); + break; + case Constants.SOCKET_LIGHT://飘心 + mListener.onLight(); + break; + case Constants.SOCKET_SEND_GIFT://送礼物 + sendGiftInSameRoom(map); + break; + +// case Constants.SOCKET_SEND_GIFT://送礼物 +// ////////pk +// break; + case Constants.SOCKET_LIVE_DRPK_RANDOM: + case Constants.SOCKET_LIVE_DRPK://多人PK + L.eSw("map"+new Gson().toJson(map)); + int action3 = map.getIntValue("action"); + //收到多人PK邀请 + if (action3 == 1) { + UserBean u = new UserBean(); + u.setUserNiceName(map.getString("uname")); + u.setId(map.getString("uid")); + mListener.onLinkDRMicPkApply(u); + } + //收到对方同意多人PK邀请 + else if (action3 == 2) { + if("0".equals(map.getString("msgtype"))){ + return; + } + UserBean u = new UserBean(); +// u.setUserNiceName(map.getString("uname")); + u.setId(map.getString("pkuid")); + L.eSw("action3 == 2:"+u.getId()); + L.eSw("收到对方同意多人PK邀请"); + mListener.onLinkDRMicPkApplyOk(u); + SWManager.get().setDimensions(3);//退出直播间,将分别率设置为 VD_840x480 + } else if (action3 == 6) {//开始Pk + if (LiveRoomViewHolder.mHandler != null) { + LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); + } +// LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, map.getIntValue("drpk_time")); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE).setPkScores(map.getJSONArray("userlist")).setUid(mLiveUid).setTime(map.getIntValue("drpk_time"))); + if (livePushSwViewHolder == null) { + // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); + } + } else if (action3 == 5) { +// endDRGif(); + LiveRoomViewHolder.d_pk_view.setVisibility(View.GONE); + if (LiveSwAnchorActivity.mLiveAnchorViewHolder != null) { + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); + params.topMargin = 0; + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LEAVE_DR_ROOM)); + isDRPK = 0; + } else { + // LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview(); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW)); + } + SWManager.get().setDimensions(0);//退出直播间,将分别率设置为 VD_840x480 + //創建了多人房間 + } else if (action3 == 3) { + L.eSw("創建了多人房間action3 == 3"); + /* if (LiveAudienceActivity.getmLivePlayViewHolder() != null) { + LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); + }*/ + if(livePushSwViewHolder==null){ + if("4".equals(map.getString("msgtype"))){ + return; + } + UserBean u = new UserBean(); +// u.setUserNiceName(map.getString("uname")); + u.setId(map.getString("uid")); + if(StringUtil.isEmpty(u.getId())){ + return; + } + L.eSw("通知用户 action3 == 3:"+u.getId()); + mListener.onLinkDRMicPKToUser(u); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); + isDRPK = 1; + } + } else if (action3 == 10) { + //显示pk分数 + if (!map.getString("uid").equals(CommonAppConfig.getInstance().getUid())) { + // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); + } + } + + break; + case Constants.SOCKET_ALL_SERVER_NOTIFY://全服通知 + int action2 = map.getIntValue("action"); + if (action2 == 71) { + LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); + receiveGiftBean.setVipName(map.getString("ct")); + receiveGiftBean.setSendtype(map.getIntValue("action")); + receiveGiftBean.setAllServerNotify(true); + mListener.onSys(receiveGiftBean); + } else if (action2 == 61) {//赠送礼物 + sendGiftByNotify(map); + } else if (action2 == 62) {//购买守护 +// buyGuardByNotify(map); +// }else if (action2 == 63){ + } else if (action2 == 63) {//购买vip + buyVipByNotify(map); + } else if (action2 == 64) {//购买靓号 + buyLiangNameByNotify(map); + } else if (action2 == 65) {//购买坐骑 + buyZuoJiByNotify(map); + } else if (action2 == 66) {//购买贵族 + buyVipByNotify(map); + } else if (action2 == 88) { + JSONObject mCt = map.getJSONObject("ct"); + String boxType = map.getString("box_type"); + String boxTypeName = ""; + if (TextUtils.equals(boxType, "1")) { + boxTypeName = WordUtil.isNewZh() ? "迷你盲盒" : "Mini blind box"; + } else if (TextUtils.equals(boxType, "2")) { + boxTypeName = WordUtil.isNewZh() ? "典藏盲盒" : "Collection blind box"; + } else { + boxTypeName = WordUtil.isNewZh() ? "PD盲盒" : "PD blind box"; + } + AllServerNotifyEvent allServerNotifyEvent = new AllServerNotifyEvent().setBlindBoxId(map.getString("blind_box_id")).setBoxType(boxType).setBoxTypeName(boxTypeName).setDressName(WordUtil.isNewZh() ? map.getString("dress_name") : TextUtils.isEmpty(map.getString("dress_nameen")) ? map.getString("dress_name") : map.getString("dress_nameen")).setGiftNotification(map.getString("gift_notification")).setGiftName(WordUtil.isNewZh() ? mCt.getString("giftname") : mCt.getString("giftnameen")).setUserNiceName(map.getString("uname")).setGiftIcon(map.getString("gifticon")).setAnchorName(map.getString("ancherName")).setDisplaySrc(map.getString("display_src")); + Log.e("AllServerNotifyEvent", allServerNotifyEvent.toString()); + Log.e("AllServerNotifyEvent", map.toJSONString()); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX).setAllServerNotifyEvent(allServerNotifyEvent)); + } else if (action2 == 89) {//红包 + JSONObject mCt = map.getJSONObject("ct"); + AllServerNotifyEvent allServerNotifyEvent = new AllServerNotifyEvent().setUserNiceName(mCt.getString("user_nicename")).setGiftName(WordUtil.isNewZh() ? map.getString("giftname") : map.getString("giftname_en")).setGiftIcon(mCt.getString("gifticon")).setRedPacket(true); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX).setAllServerNotifyEvent(allServerNotifyEvent)); + } else if (action2 == 90) { + NewAllServerNotifyGuardEvent notifyGuardEvent = GsonUtils.fromJson(map.toString(), NewAllServerNotifyGuardEvent.class); + Bus.get().post(notifyGuardEvent); + buyGuardInSameRoom(map); + } else if (action2 == 91) { + AllServerNotifyFFGGGDJANEvent notifyFFGGGDJANEvent = GsonUtils.fromJson(map.toString(), AllServerNotifyFFGGGDJANEvent.class); + Bus.get().post(notifyFFGGGDJANEvent); + } + break; + case Constants.SOCKET_SEND_BARRAGE://发弹幕 + LiveDanMuBean liveDanMuBean2 = new LiveDanMuBean(); + liveDanMuBean2.setAvatar(map.getString("uhead")); + liveDanMuBean2.setUserNiceName(map.getString("uname")); + liveDanMuBean2.setContent(map.getString("ct")); + if (map.containsKey("fansLevel")) { + liveDanMuBean2.setFensLevel(map.getInteger("fansLevel")); + } + mListener.onSendDanMu(liveDanMuBean2); + break; + case Constants.SOCKET_LEAVE_ROOM://离开房间 + UserBean u = JSON.parseObject(map.getString("ct"), UserBean.class); + mListener.onLeaveRoom(u); + break; + case Constants.SOCKET_LIVE_END://主播关闭直播 + int action = map.getIntValue("action"); + if (action == 18) { + mListener.onLiveEnd(); + LiveEndViewHolder.upData(map.getString("votes"), map.getString("length"), map.getIntValue("nums"), map.getString("uname")); + } else if (action == 19) { + mListener.onAnchorInvalid(); + } + //主播强制下播 + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_END).setVotes(map.getString("votes")).setLength(map.getString("length")).setNums(map.getIntValue("nums")).setUname(map.getString("uname"))); + break; + case Constants.SOCKET_CHANGE_LIVE://主播切换计时收费类型 + mListener.onChangeTimeCharge(map.getIntValue("type_val")); + break; + case Constants.SOCKET_UPDATE_VOTES: + mListener.onUpdateVotes(map.getString("uid"), map.getString("votes"), map.getIntValue("isfirst")); + break; + case Constants.SOCKET_FAKE_FANS: + JSONObject obj = map.getJSONObject("ct"); + String s = obj.getJSONObject("data").getJSONArray("info").getJSONObject(0).getString("list"); + L.e("僵尸粉--->" + s); + List list = JSON.parseArray(s, LiveUserGiftBean.class); + mListener.addFakeFans(list); + break; + case Constants.SOCKET_SET_ADMIN://设置或取消管理员 + systemChatMessage2(map.getString("ct")); + mListener.onSetAdmin(map.getString("touid"), map.getIntValue("action")); + break; + case Constants.SUPER_VISION://设置或取消管理员 + systemChatMessage2(map.getString("ct")); + break; + case Constants.SOCKET_BUY_GUARD://购买守护 + buyGuardInSameRoom(map); + break; + case Constants.SOCKET_LINK_MIC://连麦-old + processLinkMic(map); + break; + case Constants.SOCKET_LINK_MIC_ANCHOR://主播连麦 + processLinkMicAnchor(map); + break; + case Constants.SOCKET_LINK_MIC_PK://主播PK + processAnchorLinkMicPk(map); + break; + case Constants.SOCKET_RED_PACK://红包消息 + String uid = map.getString("uid"); + if (TextUtils.isEmpty(uid)) { + return; + } + LiveChatBean liveChatBean = new LiveChatBean(); + liveChatBean.setType(LiveChatBean.RED_PACK); + liveChatBean.setId(uid); + String name = uid.equals(mLiveUid) ? mContext.getString(R.string.live_anchor) : map.getString("uname"); + liveChatBean.setContent(name + map.getString("ct")); + mListener.onRedPack(liveChatBean); + break; + + case Constants.SOCKET_LUCK_WIN://幸运礼物中奖 + mListener.onLuckGiftWin(map.toJavaObject(LiveLuckGiftWinBean.class)); + break; + + case Constants.SOCKET_PRIZE_POOL_WIN://奖池中奖 + mListener.onPrizePoolWin(map.toJavaObject(LiveGiftPrizePoolWinBean.class)); + break; + case Constants.SOCKET_PRIZE_POOL_UP://奖池升级 + mListener.onPrizePoolUp(map.getString("uplevel")); + break; + case Constants.SOCKET_HOUR://小时榜 + liveChatBean = new LiveChatBean(); + liveChatBean.setId("-1"); + liveChatBean.setType(LiveChatAdapter.MSG_HOUR_RANK_CHANGE); + liveChatBean.setContent(map.getJSONObject("ct").getString("text")); + mListener.onHourRank(liveChatBean, map.getJSONObject("ct").getJSONObject("new_rank")); + break; + //游戏socket + case Constants.SOCKET_GAME_ZJH://游戏 智勇三张 + if (CommonAppConfig.GAME_ENABLE) { + mListener.onGameZjh(map); + } + break; + case Constants.SOCKET_GAME_HD://游戏 海盗船长 + if (CommonAppConfig.GAME_ENABLE) { + mListener.onGameHd(map); + } + break; + case Constants.SOCKET_GAME_ZP://游戏 幸运转盘 + if (CommonAppConfig.GAME_ENABLE) { + mListener.onGameZp(map); + } + break; + case Constants.SOCKET_GAME_NZ://游戏 开心牛仔 + if (CommonAppConfig.GAME_ENABLE) { + mListener.onGameNz(map); + } + break; + case Constants.SOCKET_GAME_EBB://游戏 二八贝 + if (CommonAppConfig.GAME_ENABLE) { + mListener.onGameEbb(map); + } + break; + case Constants.SOCKET_SEND_ACTIVE_MSG://新增,活动聊天显示 + sendActiveMsg(map, received); + break; + case Constants.SOCKET_PRANKTURNTABLE://新增,整蛊消息 + mListener.prankTurntable(map.getString("msgtype"), map.getIntValue("time"), JSON.parseObject(map.getString("ct"))); + String msgtype = map.getString("msgtype"); + JSONObject jsonObject = JSON.parseObject(map.getString("ct")); +// if ("1".equals(msgtype)) {//新年大作战活动 + LiveChatBean chatBean = new LiveChatBean(); + chatBean.setId(jsonObject.getString("uid")); + chatBean.setUserNiceName(jsonObject.getString("user_nicename")); + if ("1".equals(map.getString("msgtype"))) { + chatBean.setType(-3); + } else { + chatBean.setType(-4); + } + chatBean.setContent(jsonObject.getString("content")); + chatBean.setBubble(jsonObject.getString("display_src")); + chatBean.setMedal(jsonObject.getString("hope_nicename"));//做为拯救人名字 + chatBean.setAnchorName(jsonObject.getString("anchor_nicename")); + mListener.onChat(chatBean, 1); +// } + break; + case Constants.SOCKET_USEHOTCARD://新增,热度卡消息 +// mListener.prankTurntable(map.getString("msgtype"), map.getIntValue("time"), JSON.parseObject(map.getString("ct"))); + JSONObject jsonObject2 = JSON.parseObject(map.getString("ct")); + LiveChatBean chatBean2 = new LiveChatBean(); + chatBean2.setType(-6); + chatBean2.setBubble(jsonObject2.getString("system_bubble")); + chatBean2.setId(jsonObject2.getString("user_id")); + chatBean2.setUserNiceName(jsonObject2.getString("user_name")); + chatBean2.setHot_num(jsonObject2.getString("hot_num")); + chatBean2.setHot_card(jsonObject2.getString("hot_card")); + getIsHot(); + mListener.onChat(chatBean2, 1); + break; + case Constants.LOVE_CHECK://甜蜜 + JSONObject jsonObject3 = JSON.parseObject(map.getString("ct")); + LiveChatBean chatBean3 = new LiveChatBean(); + chatBean3.setType(-7); + chatBean3.setBubble(jsonObject3.getString("system_bubble")); + chatBean3.setId(jsonObject3.getString("user_id")); + chatBean3.setUserNiceName(jsonObject3.getString("user_name")); + chatBean3.setHot_num(jsonObject3.getString("gift_name")); + mListener.onChat(chatBean3, 1); + break; + case Constants.TRUMPET_NOTIFY://全站喇叭 + SocketModel model = GsonUtils.fromJson(socketMsg, SocketModel.class); + List msg = model.getMsg(); + if (msg.size() > 0) { +// EventBus.getDefault().post(msg.get(0)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.TRUMPET_NOTIFY).setMsgModel(msg.get(0))); + } + break; + case Constants.RECOMMEND_CARD_NOTIFY://推荐卡消息通知 + SocketModel recommendCardNotifyModel = GsonUtils.fromJson(socketMsg, SocketModel.class); + List recommendCardNotifyMsg = recommendCardNotifyModel.getMsg(); + if (recommendCardNotifyMsg.size() > 0) { + + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.RECOMMEND_CARD_NOTIFY).setMsgModel(recommendCardNotifyMsg.get(0))); + } + break; + case Constants.STAR_CHALLENGE_UPDATE://星级助力 +// SocketModel starChallengeModel = GsonUtils.fromJson(socketMsg, SocketModel.class); +// List starChallengeMsg = starChallengeModel.getMsg(); +// if (starChallengeMsg.size() > 0) { +// +// Bus.get().post(new LiveAudienceEvent() +// .setType(LiveAudienceEvent.LiveAudienceType.START_MESSAGE) +// .setMsgModel(starChallengeMsg.get(0))); +// } + break; + case Constants.AI_AUTOMATIC_SPEECH: + case Constants.AI_AUTOMATIC_SPEECH_LIVE: + //{"name_color":"#f19ec2","ai_name":"助手小小P","content":"@1 ","user_name":"1","icon":"https://downs.yaoulive.com/xzs_tab.png","system_bubble":"https://downs.yaoulive.com/xzs_qipao.9.png"} + AiAutomaticSpeechModel aiAutomaticSpeechModel = GsonUtils.fromJson(map.getString("ct"), AiAutomaticSpeechModel.class); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.AI_AUTOMATIC_SPEECH).setAiAutomaticSpeechModel(aiAutomaticSpeechModel)); + break; + case Constants.STAR_CHALLENGE_UPGRADE_NOTIFY: + SocketModel starChallengeUpgradeNotify = GsonUtils.fromJson(socketMsg, SocketModel.class); + List starChallengeUpgradeNotifyMsg = starChallengeUpgradeNotify.getMsg(); + if (starChallengeUpgradeNotifyMsg.size() > 0) { + + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.STAR_CHALLENGE_UPGRADE_NOTIFY).setMsgModel(starChallengeUpgradeNotifyMsg.get(0))); + } + break; + case Constants.LuckyAngel: + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LUCKY_ANGEL).setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); + break; + case Constants.Lucky100Check: + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LUCKY_100_CHECK).setMsgModel(GsonUtils.fromJson(map.getJSONObject("ct").toString(), MsgModel.class))); + break; + case Constants.PK_RANK_UPDATE: + Log.i("PK排位", map.toString()); + JSONObject item = map.getJSONObject("ct"); + PkRankBean pkRankBean = new PkRankBean(); + pkRankBean.setId(Integer.parseInt(item.getString("new_rank_id"))); + pkRankBean.setName(item.getString("new_rank_name")); + pkRankBean.setImg(item.getString("new_rank_img")); + pkRankBean.setNewRankNameEn(item.getString("new_rank_name_en")); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_UPDATE).setObject(pkRankBean)); + break; + case Constants.CUSTOM_FULL_SERVICE_NOTIFY: + Log.e("全服通知", map.toString()); + CustomFullServiceNotifyEvent customFullServiceNotifyEvent = GsonUtils.fromJson(map.toString(), CustomFullServiceNotifyEvent.class); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.CUSTOM_FULL_SERVICE_NOTIFY).setCustomFullServiceNotifyEvent(customFullServiceNotifyEvent)); + break; + case Constants.XYD_COMPLETE: + +// xydComplete(map); + XydCompleteModel xydCompleteModel = GsonUtils.fromJson(map.toString(), XydCompleteModel.class); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.XYD_COMPLETE).setXydCompleteModel(xydCompleteModel).setLiveReceiveGiftBean(JSON.parseObject(map.toString(), LiveReceiveGiftBean.class))); + break; + case "GuardSpecialEffect": + LiveReceiveGiftBean giftBean = JSON.parseObject(map.toString(), LiveReceiveGiftBean.class); + giftBean.setMedal_name(map.getString("medal_name")); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GuardSpecialEffect).setLiveReceiveGiftBean(giftBean)); + break; + case Constants.WISH_LIST_PROGRESS: + StringBuffer conString = new StringBuffer(); + conString.append(WordUtil.isNewZh() ? map.getString("msg") : map.getString("msg_en")); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.WISH_LIST_PROGRESS).setWishListProgress(new WishModel().setWishlistProgress(map.getString("wishlist_progress")).setWishlistIcon(map.getString("wishlist_icon")).setWishlistName(map.getString("wishlist_name")).setWishlistNum(map.getString("wishlist_num")).setGiftType(map.getInteger("giftId")).setLuid(conString.toString())).setUname(map.getString("userName")).setLiveType(Integer.parseInt(map.getString("level")))); + break; + case Constants.LIVE_VOTE_CREATE: + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.VOTE_CREATE).setObject(map)); + break; + case Constants.LIVE_VOTE_END: + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.VOTE_END).setObject(map)); + EventBus.getDefault().post(new LiveAnchorEvent().setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_END).setObject(map)); + break; + case Constants.LIVE_VOTE_UPDATE: + //通知给观众 + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.VOTE_UPDATE).setObject(map)); + //通知给主播 + EventBus.getDefault().post(new LiveAnchorEvent().setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_UPDATE).setObject(map)); + break; + case Constants.LIVE_PK_END: + + mListener.onEndPk(map.getLong("uid"), map.getLong("pkuid"), map.getLong("uid_score"), map.getLong("pkuid_score"), JSONObject.parseObject(map.getJSONObject("ct").getJSONObject("pk_top_users").toJSONString(), LivePKUserListBean.class)); + break; + case Constants.RED_PACKET: + RedPacketModel redPacketModel = GsonUtils.fromJson(map.toString(), RedPacketModel.class); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET).setRedPacketModel(redPacketModel)); + break; + case Constants.RED_PACKET_SUPER_JACKPOT: + RedPacketInfoModel redPacketInfoModel = GsonUtils.fromJson(map.toString(), RedPacketInfoModel.class); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.RED_PACKET_SUPER_JACKPOT).setRedPacketInfoModel(redPacketInfoModel)); + break; + case "GiftWallIlluminate": + Log.e("GiftWallIlluminate", map.toString()); + Bus.get().post(new GiftWallIlluminateEvent().setNewNumber(map.getInteger("new_number")).setMaxNumber(map.getInteger("max_number"))); + break; + case SOCKET_LIVE_MSG_TO_USER: + sendToUserMsg(map); + break; + case "SudGameCreateRoom": + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SUD_GAME_CREATE_ROOM).setAvatar(WordUtil.isNewZh() ? map.getString("sud_game_name") : map.getString("sud_game_name_en")).setCreateSudRoomModel(GsonUtils.fromJson(map.toString(), SudGameDateModel.class))); + break; + case "sendQuickGift": + SendQuickGiftModel sendQuickGiftModel = GsonUtils.fromJson(map.toString(), SendQuickGiftModel.class); + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append(sendQuickGiftModel.getUserNicename()).append(WordUtil.isNewZh() ? " 送出了 " : " sent ").append(sendQuickGiftModel.getQuickGiftNumber()).append(WordUtil.isNewZh() ? " 個小PD " : " small pandas "); + systemChatMessage2(stringBuffer.toString()); + Bus.get().post(new QuickGiftingEvent().setHotNum(sendQuickGiftModel.getHotNum())); + break; + case Constants.LIVE_PK_RANDOM_START: + item = map.getJSONObject("ct"); + item.getString("text"); + item.getString("pktt_img"); + item.getString("uid_win_continuity"); + item.getString("pkuid_win_continuity"); + pkRankBean = new PkRankBean(); + pkRankBean.setBlueVal(item.getString("pkuid_win_continuity")); + pkRankBean.setRedVal(item.getString("uid_win_continuity")); + pkRankBean.setPkTopImgUrl(item.getString("pktt_img")); + + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_RANK_START).setObject(pkRankBean)); + break; + case "guardMaturityDateRemind": + GuardMaturityDateRemindModel maturityDateRemindModel = GsonUtils.fromJson(map.toString(), GuardMaturityDateRemindModel.class); + Bus.get().post(maturityDateRemindModel); + break; + case "SendMoneyLong": + SendMoneyLongModel sendMoneyLongModel = GsonUtils.fromJson(map.toString(), SendMoneyLongModel.class); + Bus.get().post(sendMoneyLongModel); + break; + case "SendMoneyLongEnd": + Bus.get().post(new SendMoneyLongEndEvent()); + break; + + } + } + + private void buyGuardInSameRoom(JSONObject map) { + if (TextUtils.isEmpty(map.getString("ancherName")) || TextUtils.isEmpty(map.getString("uname"))) + return; + String guardName = WordUtil.isNewZh() ? "星之守護" : "Star Guardian"; + switch (map.getIntValue("guard_type")) { + case 1: + guardName = WordUtil.isNewZh() ? "星之守護" : "Star Guardian"; + break; + case 2: + guardName = WordUtil.isNewZh() ? "王之守護" : "King Guardian"; + break; + case 3: + guardName = WordUtil.isNewZh() ? "神之守護" : "God Guardian"; + break; + } + String content = WordUtil.isNewZh() ? "%s在%s的直播間開通了%s" : "%s has been opened in %s live broadcast room %s"; + content = String.format(content, map.getString("uname"), map.getString("ancherName"), guardName); + LiveBuyGuardMsgBean buyGuardMsgBean = new LiveBuyGuardMsgBean(); + buyGuardMsgBean.setUid(map.getString("uid")); + buyGuardMsgBean.setUserName(content); + buyGuardMsgBean.setVotes(map.getString("votestotal")); + buyGuardMsgBean.setGuardNum(map.getIntValue("guard_nums")); + buyGuardMsgBean.setGuardType(map.getIntValue("guard_type")); + mListener.onBuyGuard(buyGuardMsgBean); + } + + private void buyGuardByNotify(JSONObject map) { + if (mLiveUid.equals(map.getString("liveuid"))) { +// buyGuardInSameRoom(map); + //同一直播间,玩家自己开通,也能看到全服通知 + String userId = CommonAppConfig.getInstance().getUid(); + String uid = map.getString("uid"); + if (userId.equals(uid)) { + LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); + receiveGiftBean.setUserNiceName(map.getString("uname")); + receiveGiftBean.setAncherName(map.getString("ancherName")); + receiveGiftBean.setmLiveUId(mLiveUid); + receiveGiftBean.setRoomnum(map.getString("liveuid")); + receiveGiftBean.setmTypeBuyGuard(true); + receiveGiftBean.setUid(uid); + receiveGiftBean.setGuardType(map.getString("guard_type")); + receiveGiftBean.setSendtype(map.getIntValue("action")); + mListener.onSendGift(receiveGiftBean, null); + } + } else { + LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); + receiveGiftBean.setUserNiceName(map.getString("uname")); + receiveGiftBean.setAncherName(map.getString("ancherName")); + receiveGiftBean.setmLiveUId(mLiveUid); + receiveGiftBean.setRoomnum(map.getString("liveuid")); + receiveGiftBean.setmTypeBuyGuard(true); + receiveGiftBean.setUid(map.getString("uid")); + receiveGiftBean.setGuardType(map.getString("guard_type")); + receiveGiftBean.setSendtype(map.getIntValue("action")); + mListener.onSendGift(receiveGiftBean, null); + } + } + + + private void buyZuoJiByNotify(JSONObject map) { + LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); + receiveGiftBean.setUserNiceName(map.getString("nickname")); + receiveGiftBean.setCarName(map.getString("carname")); + receiveGiftBean.setSendtype(map.getIntValue("action")); + mListener.onBuyZuoji(receiveGiftBean); + } + + + private void buyLiangNameByNotify(JSONObject map) { + LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); + receiveGiftBean.setUserNiceName(map.getString("nickname")); + receiveGiftBean.setLiangName(map.getString("liangname")); + receiveGiftBean.setSendtype(map.getIntValue("action")); + mListener.onBuyLiangName(receiveGiftBean); + } + + private void buyVipByNotify(JSONObject map) { + LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); + receiveGiftBean.setUserNiceName(map.getString("nicename")); + receiveGiftBean.setVipName(map.getString("ct")); + receiveGiftBean.setAvatar(map.getString("notice")); + receiveGiftBean.setAllServerNotify(true); + receiveGiftBean.setmLiveUId(map.getString("anchorUid")); + receiveGiftBean.setGifUrl(map.getString("special_src")); + receiveGiftBean.setVipTime(map.getString("viplength")); + receiveGiftBean.setRoomnum(map.getString("anchorUid")); + receiveGiftBean.setAncherName(map.getString("ancherName")); + receiveGiftBean.setNobilityid(map.getString("nobilityid")); + receiveGiftBean.setNobilityname(map.getString("nobilityname")); + receiveGiftBean.setOpentype(map.getString("opentype")); + receiveGiftBean.setSendtype(map.getIntValue("action")); + receiveGiftBean.setSendtype(map.getIntValue("action")); + receiveGiftBean.setUname(map.getString("uname")); + receiveGiftBean.setUhead(map.getString("uhead")); + if (map.getString("notice").equals("1")) { + LiveRoomViewHolder.paygzGif(map.getString("special_src"), map.getString("anchorUid")); + } + mListener.onBuyVip(receiveGiftBean); + } + + private void sendActiveMsg(JSONObject map, SocketReceiveBean received) { + String msgtype = map.getString("msgtype"); + if ("1".equals(msgtype)) {//新年大作战活动 + LiveChatBean chatBean = new LiveChatBean(); + chatBean.setId(map.getString("uid")); + chatBean.setMedalLevelImageUrl(map.getString("monster_str"));//昵称暂时做为活动图片地址 + chatBean.setContent(map.getString("url"));//暂时做为活动链接地址 + chatBean.setUserNiceName(map.getString("activename")); + chatBean.setType(6); + mListener.onChat(chatBean, 0); + } + } + + /** + * 七日留存新用户主播端弹幕显示接口 + */ + private void sendToUserMsg(JSONObject map) { + LiveChatBean bean = new LiveChatBean(); + bean.setId(map.getString("uid")); + bean.setAtUserID(map.getString("toUserID")); + bean.setContent(map.getString("ct")); + bean.setType(LiveChatBean.TYPE_TO_USER_MSG); + bean.setUserNiceName(map.getString("user_nicename")); + bean.setToUid(CommonAppConfig.getInstance().getUid()); + mListener.onChat(bean, 1); + } + + private void wordLightEnterRoom(JSONObject map, SocketReceiveBean received) { + String msgtype = map.getString("msgtype"); + if ("2".equals(msgtype)) {//发言,点亮 + if ("409002".equals(received.getRetcode())) { + ToastUtil.show(WordUtil.isNewZh() ? "你已經被禁言" : "You\'ve been banned"); + return; + } + + //禁言别人,自己发言只能自己看到 + if ("409100".equals(received.getRetcode())) { + String uid = map.getString("uid"); + if (uid == null || !uid.equals(CommonAppConfig.getInstance().getUid())) { + return; + } + } + LiveChatBean chatBean = new LiveChatBean(); + chatBean.setId(map.getString("uid")); + chatBean.setUserNiceName(map.getString("uname")); + chatBean.setLevel(map.getIntValue("level")); + chatBean.setAnchor(map.getIntValue("isAnchor") == 1); + chatBean.setManager(map.getIntValue("usertype") == Constants.SOCKET_USER_TYPE_ADMIN); + chatBean.setContent(map.getString("ct")); + int heart = map.getIntValue("heart"); + chatBean.setHeart(heart); + if (heart > 0) { + chatBean.setType(LiveChatBean.LIGHT); + } + chatBean.setLiangName(map.getString("liangname")); + chatBean.setBubble(map.getString("bubble")); + chatBean.setMedal(map.getString("medal")); + chatBean.setMedal_new(map.getString("medal_new")); + chatBean.setVipType(map.getIntValue("vip_type")); + chatBean.setVipType(map.getIntValue("vip_type")); + chatBean.setMedal_honor(map.getString("medal_honor")); + chatBean.setGood_nub(map.getString("good_num")); + chatBean.setNobleId(map.getString("noble_id"));//貴族ID + chatBean.setStartColor(map.getString("startColor"));//昵称开始颜色 + chatBean.setEndColor(map.getString("endColor"));//昵称结束颜色 + chatBean.setContentColor(map.getString("contentColor"));//文字内容颜色 + chatBean.setAtUserName(map.getString("atUserName"));//@名字 + chatBean.setAtUserID(map.getString("atUserID"));//@ID + if (map.containsKey("guard_type") && !map.getString("guard_type").equals("undefined")) { + chatBean.setGuardType(map.getIntValue("guard_type")); + } + try { + //增加粉丝徽章信息 + chatBean.setMedalNmae(map.getString("medal_name")); + FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); + if (fansMedalBean != null) + chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + } catch (Exception e) { + e.printStackTrace(); + } + + if (!"".equals(map.getString("prankIcon")) && map.getString("prankIcon") != null) { + chatBean.setPrankIcon(map.getString("prankIcon")); + chatBean.setType(-5); + } + mListener.onChat(chatBean, 1); + } else if ("0".equals(msgtype)) {//用户进入房间 + JSONObject obj = JSON.parseObject(map.getString("ct")); + LiveUserGiftBean u = GsonUtils.fromJson(obj.toJSONString(), LiveUserGiftBean.class); + UserBean.Vip vip = new UserBean.Vip(); + int vipType = obj.getIntValue("vip_type"); + vip.setType(vipType); + u.setVip(vip); + UserBean.Car car = new UserBean.Car(); + car.setId(obj.getIntValue("car_id")); + car.setSwf(obj.getString("car_swf")); + car.setSwftime(obj.getFloatValue("car_swftime")); + car.setWords(obj.getString("car_words")); + u.setCar(car); + UserBean.Liang liang = new UserBean.Liang(); + String liangName = obj.getString("liangname"); + liang.setName(liangName); + u.setLiang(liang); + LiveChatBean chatBean = new LiveChatBean(); + chatBean.setType(LiveChatBean.ENTER_ROOM); + chatBean.setId(u.getId()); + chatBean.setMedal_honor(map.getString("medal_honor")); + chatBean.setGood_nub(map.getString("good_num")); + chatBean.setUserNiceName(u.getUserNiceName()); + chatBean.setLevel(u.getLevel()); + chatBean.setVipType(vipType); + chatBean.setLiangName(liangName); + chatBean.setBubble(obj.getString("bubble")); + chatBean.setMedal(obj.getString("medal")); + chatBean.setMedal_new(obj.getString("medal_new")); + chatBean.setHot_num(obj.getString("hot_num")); + UserBean.DressBean dressBean = new UserBean.DressBean(); + dressBean.setAvatar_frame(obj.getString("avatar_frame")); + u.setDress(dressBean); + + chatBean.setManager(obj.getIntValue("usertype") == Constants.SOCKET_USER_TYPE_ADMIN); + chatBean.setContent(mContext.getString(R.string.live_enter_room)); + chatBean.setGuardType(obj.getIntValue("guard_type")); + chatBean.setNobleId(obj.getString("noble_id"));//貴族ID + chatBean.setStartColor(obj.getString("startColor"));//昵称开始颜色 + chatBean.setEndColor(obj.getString("endColor"));//昵称结束颜色 + chatBean.setContentColor(obj.getString("contentColor"));//文字内容颜色 + chatBean.setNobleIcon(obj.getString("noble_icon"));//貴族圖標 + chatBean.setBubbleSrc(obj.getString("bubbleSrc"));//氣泡 + //增加粉丝徽章信息 + chatBean.setMedalNmae(obj.getString("medal_name")); + chatBean.setUserNiceName(obj.getString("user_nicename"));//名字 + FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); + u.setFansLevel(obj.getIntValue("medal_level")); + u.setFansEnterRoomUrl(obj.getString("medal_backgroup_thumb")); + if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + mListener.onEnterRoom(new LiveEnterRoomBean(u, chatBean)); + } + } + + //送礼物 全服通知 + private void sendGiftByNotify(JSONObject map) { + LiveReceiveGiftBean receiveGiftBean = JSON.parseObject(map.getString("ct"), LiveReceiveGiftBean.class); + receiveGiftBean.setAvatar(map.getString("uhead")); + receiveGiftBean.setUserNiceName(map.getString("uname")); + receiveGiftBean.setRoomnum(map.getString("roomnum")); + receiveGiftBean.setAncherName(map.getString("ancherName")); + receiveGiftBean.setHot_num(map.getString("hot_num")); + receiveGiftBean.setSendtype(map.getIntValue("action")); + receiveGiftBean.setmLiveUId(mLiveUid); + receiveGiftBean.setmTypeBuyGuard(false); + //全服通知时,不通知主播 + receiveGiftBean.setAllServerNotify(true); + LiveChatBean chatBean = new LiveChatBean(); + chatBean.setUserNiceName(receiveGiftBean.getUserNiceName()); + chatBean.setLevel(receiveGiftBean.getLevel()); + chatBean.setBubble(map.getString("bubble")); + chatBean.setMedal(map.getString("medal")); + chatBean.setId(map.getString("uid")); + chatBean.setMedal_honor(map.getString("medal_honor")); + chatBean.setGood_nub(map.getString("good_num")); + chatBean.setLiangName(map.getString("liangname")); + chatBean.setVipType(map.getIntValue("vip_type")); + chatBean.setType(LiveChatBean.GIFT); + //增加粉丝徽章信息 + chatBean.setMedalNmae(map.getString("medal_name")); + FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); + if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + //聊天列表显示 玩家名 送 1 个 礼物名 + + if (CommonAppContext.lang.equals("chinese")) { + chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + receiveGiftBean.getGiftCount() + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftName()); + } else { + chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + " " + +receiveGiftBean.getGiftCount() + " " + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftnameen()); + } + + receiveGiftBean.setLiveChatBean(chatBean); + if (map.getIntValue("ifpk") == 1) { + if (!TextUtils.isEmpty(mLiveUid)) { + //获取PK排名数据 + LivePKUserListBean livePKUserListBean = JSON.parseObject(receiveGiftBean.getPkTopUsers(), LivePKUserListBean.class); + if (mLiveUid.equals(map.getString("roomnum"))) { + if (!mLiveUid.equals(map.getString("roomnum"))) { + mListener.onSendGift(receiveGiftBean, null); + } + //同一个直播间时才刷新pk + mListener.onSendGiftPk(map.getLongValue("pktotal1"), map.getLongValue("pktotal2"), livePKUserListBean); + } else { + if (!mLiveUid.equals(map.getString("roomnum"))) { + mListener.onSendGift(receiveGiftBean, null); + } + //同一个直播间时才刷新pk + if (mLiveUid.equals(map.getString("pkuid1")) || mLiveUid.equals(map.getString("pkuid2"))) { + mListener.onSendGiftPk(map.getLongValue("pktotal2"), map.getLongValue("pktotal1"), livePKUserListBean); + } + } + } + } else { + if (!mLiveUid.equals(map.getString("roomnum"))) { + mListener.onSendGift(receiveGiftBean, null); + } + } + } + + private void xydComplete(JSONObject map) { + LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); + receiveGiftBean.setAvatar(map.getString("uhead") + ""); + receiveGiftBean.setUserNiceName(map.getString("uname")); + receiveGiftBean.setRoomnum(map.getString("roomnum")); + receiveGiftBean.setAncherName(map.getString("ancherName")); + receiveGiftBean.setHot_num(map.getString("hot_num")); + receiveGiftBean.setDrpk_status(map.getString("drpk_status")); + receiveGiftBean.setGitType(map.getInteger("swftype ")); + receiveGiftBean.setmLiveUId(mLiveUid); + receiveGiftBean.setmTypeBuyGuard(false); + receiveGiftBean.setAllServerNotify(false); + receiveGiftBean.setGifUrl(map.getString("svg")); + LiveChatBean chatBean = new LiveChatBean(); + chatBean.setUserNiceName(receiveGiftBean.getUserNiceName()); + chatBean.setLevel(receiveGiftBean.getLevel()); + chatBean.setMedal_honor(map.getString("medal_honor")); + chatBean.setId(map.getString("uid")); + chatBean.setLiangName(map.getString("liangname")); + chatBean.setVipType(map.getIntValue("vip_type")); + chatBean.setBubble(map.getString("bubble")); + chatBean.setMedal(map.getString("medal")); + chatBean.setMedal_new(map.getString("medal_new")); + chatBean.setGood_nub(map.getString("good_num")); + chatBean.setType(LiveChatBean.GIFT); + if (map.get("guard_type") != null && !"".equals(map.get("guard_type")) && !"null".equals(map.get("guard_type"))) { + chatBean.setGuardType(map.getInteger("guard_type")); + } + if (CommonAppContext.lang.equals("chinese")) { + chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + receiveGiftBean.getGiftCount() + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftName()); + } else { + chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + " " + +receiveGiftBean.getGiftCount() + " " + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftnameen()); + + } + mListener.onSendGift(receiveGiftBean, null); + } + + // 玩家自己送礼物 + private void sendGiftInSameRoom(JSONObject map) { + String ctJson = map.getString("ct"); + SendBlindGiftEvent sendBlindGiftEvent = JSON.parseObject(ctJson, SendBlindGiftEvent.class); + LiveReceiveGiftBean receiveGiftBean = JSON.parseObject(map.getString("ct"), LiveReceiveGiftBean.class); + sendBlindGiftEvent.setUserNiceName(map.getString("uname")); + receiveGiftBean.setAvatar(map.getString("uhead") + ""); + receiveGiftBean.setUserNiceName(map.getString("uname")); + receiveGiftBean.setRoomnum(map.getString("roomnum")); + receiveGiftBean.setAncherName(map.getString("ancherName")); + receiveGiftBean.setHot_num(map.getString("hot_num")); + receiveGiftBean.setDrpk_status(map.getString("drpk_status")); + receiveGiftBean.setNamingCoin(map.getString("naming_live_name")); + receiveGiftBean.setNamingLiveName(map.getString("naming_live_name")); + receiveGiftBean.setNamingUid(map.getString("naming_uid")); + receiveGiftBean.setNamingLiveuid(map.getString("naming_liveuid")); + receiveGiftBean.setmLiveUId(mLiveUid); + receiveGiftBean.setmTypeBuyGuard(false); + receiveGiftBean.setAllServerNotify(false); + sendBlindGiftEvent.setGiftname_en(map.getString("giftname_en")); + //获取PK排名数据 + LivePKUserListBean livePKUserListBean = JSON.parseObject(receiveGiftBean.getPkTopUsers(), LivePKUserListBean.class); + + LiveChatBean chatBean = new LiveChatBean(); + chatBean.setUserNiceName(receiveGiftBean.getUserNiceName()); + chatBean.setLevel(receiveGiftBean.getLevel()); + chatBean.setMedal_honor(map.getString("medal_honor")); + chatBean.setId(map.getString("uid")); + chatBean.setLiangName(map.getString("liangname")); + chatBean.setVipType(map.getIntValue("vip_type")); + chatBean.setBubble(map.getString("bubble")); + chatBean.setMedal(map.getString("medal")); + chatBean.setMedal_new(map.getString("medal_new")); + chatBean.setGood_nub(map.getString("good_num")); + chatBean.setType(LiveChatBean.GIFT); + if (map.get("guard_type") != null && !"".equals(map.get("guard_type")) && !"null".equals(map.get("guard_type"))) { + chatBean.setGuardType(map.getInteger("guard_type")); + } + + if (WordUtil.isNewZh()) { + chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + receiveGiftBean.getGiftCount() + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftName()); + } else { + chatBean.setContent(mContext.getString(R.string.live_send_gift_1) + " " + +receiveGiftBean.getGiftCount() + " " + mContext.getString(R.string.live_send_gift_2) + receiveGiftBean.getGiftnameen()); + } + //增加粉丝徽章信息 + chatBean.setMedalNmae(map.getString("medal_name")); + FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); + if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); + + receiveGiftBean.setLiveChatBean(chatBean); + + if (map.getIntValue("ifpk") == 1) { + try { + if (!TextUtils.isEmpty(mLiveUid)) { + if (mLiveUid.equals(map.getString("roomnum"))) { + mListener.onSendGift(receiveGiftBean, sendBlindGiftEvent); + mListener.onSendGiftPk(map.getLongValue("pktotal1"), map.getLongValue("pktotal2"), livePKUserListBean); + } else { + mListener.onSendGiftPk(map.getLongValue("pktotal2"), map.getLongValue("pktotal1"), livePKUserListBean); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + } else { + Log.i("tvvs", receiveGiftBean.getLiveChatBean().getContent()); + if (!TextUtils.isEmpty(sendBlindGiftEvent.getAction()) && TextUtils.equals("blind_box", sendBlindGiftEvent.getAction())) { + mListener.onSendGift(receiveGiftBean, sendBlindGiftEvent); + } else { + mListener.onSendGift(receiveGiftBean, null); + } + + } + if (map.getIntValue("drpk_status") == 1) { + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LEAVE_PK_SCORE).setPkScores(map.getJSONArray("userlist")).setUid(mLiveUid).setTime(0)); +// LiveRoomViewHolder.UpPkBar(map.getJSONArray("userlist"), mLiveUid, 0); + } + + } + + /** + * 接收到系统消息,显示在聊天栏中 + */ + private void systemChatMessage(String content) { + LiveChatBean bean = new LiveChatBean(); + bean.setContent(content); + bean.setType(LiveChatBean.SYSTEM); + mListener.onChat(bean, 1); + } + + /** + * 接收到系统消息,显示在聊天栏中 + */ + private void systemChatMessage2(String content) { + LiveChatBean bean = new LiveChatBean(); + bean.setContent(content); + bean.setType(LiveChatBean.SYSTEM2); + mListener.onChat(bean, 1); + } + + /** + * 处理观众与主播连麦逻辑 + */ + private void processLinkMic(JSONObject map) { + int action = map.getIntValue("action"); + switch (action) { + case 1://主播收到观众连麦的申请 + UserBean u = new UserBean(); + u.setId(map.getString("uid")); + u.setUserNiceName(map.getString("uname")); + u.setAvatar(map.getString("uhead")); + u.setSex(map.getIntValue("sex")); + u.setLevel(map.getIntValue("level")); + mListener.onAudienceApplyLinkMic(u); + break; + case 2://观众收到主播同意连麦的消息 + if (map.getString("touid").equals(CommonAppConfig.getInstance().getUid())) { + mListener.onAnchorAcceptLinkMic(); + } + break; + case 3://观众收到主播拒绝连麦的消息 + if (map.getString("touid").equals(CommonAppConfig.getInstance().getUid())) { + mListener.onAnchorRefuseLinkMic(); + } + break; + case 4://所有人收到连麦观众发过来的流地址 + String uid = map.getString("uid"); + if (!TextUtils.isEmpty(uid) && !uid.equals(CommonAppConfig.getInstance().getUid())) { + mListener.onAudienceSendLinkMicUrl(uid, map.getString("uname"), map.getString("playurl")); + } + break; + case 5://连麦观众自己断开连麦 + mListener.onAudienceCloseLinkMic(map.getString("uid"), map.getString("uname")); + break; + case 6://主播断开已连麦观众的连麦 + mListener.onAnchorCloseLinkMic(map.getString("touid"), map.getString("uname")); + break; + case 7://已申请连麦的观众收到主播繁忙的消息 + if (map.getString("touid").equals(CommonAppConfig.getInstance().getUid())) { + mListener.onAnchorBusy(); + } + break; + case 8://已申请连麦的观众收到主播无响应的消息 + if (map.getString("touid").equals(CommonAppConfig.getInstance().getUid())) { + mListener.onAnchorNotResponse(); + } + break; + case 9://所有人收到已连麦的观众退出直播间消息 + mListener.onAudienceLinkMicExitRoom(map.getString("touid")); + break; + } + } + + /** + * 处理主播与主播连麦逻辑 + * + * @param map + */ + private void processLinkMicAnchor(JSONObject map) { + int action = map.getIntValue("action"); + switch (action) { + case 1://收到其他主播连麦的邀请的回调 + UserBean u = new UserBean(); + u.setId(map.getString("uid")); + u.setUserNiceName(map.getString("uname")); + u.setAvatar(map.getString("uhead")); + u.setSex(map.getIntValue("sex")); + u.setLevel(map.getIntValue("level")); + u.setLevelAnchor(map.getIntValue("level_anchor")); + mListener.onLinkMicAnchorApply(u, map.getString("stream")); + break; + case 3://对方主播拒绝连麦的回调 + mListener.onLinkMicAnchorRefuse(); + break; + case 4://所有人收到对方主播的播流地址的回调 + mListener.onLinkMicAnchorPlayUrl(map.getString("pkuid"), map.getString("pkpull")); + break; + case 5://断开连麦的回调 + mListener.onLinkMicAnchorClose(); + break; + case 7://对方主播正在忙的回调 + mListener.onLinkMicAnchorBusy(); + break; + case 8://对方主播无响应的回调 + mListener.onLinkMicAnchorNotResponse(); + break; + case 9://对方主播正在游戏 + mListener.onlinkMicPlayGaming(); + break; + } + } + + /** + * 处理主播与主播PK逻辑 + * + * @param map + */ + private void processAnchorLinkMicPk(JSONObject map) { + int action = map.getIntValue("action"); + Log.i("Socket", "action = " + action + " json = " + map.toString()); + L.eSw("处理主播与主播PK逻辑action = " + action + " json = " + map.toString()); + switch (action) { + case 1://收到对方主播PK回调 + UserBean u = new UserBean(); + u.setId(map.getString("uid")); + u.setUserNiceName(map.getString("pkname")); + u.setAvatar(map.getString("pkhead")); + u.setRandomPk("11".equals(map.getString("msgtype"))); + mListener.onLinkMicPkApply(u, map.getString("stream"), "11".equals(map.getString("msgtype"))?2:1); + break; + case 2://收到对方主播PK回调 + L.eSw("收到对方主播PK回调"); + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + mListener.onLinkMicToPk(map.getString("uid"), map.getString("uhead"), map.getString("uhead")); + mListener.onLinkMicPkStart(map.getString("uid"), map.getString("uhead"), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); + if (livePushSwViewHolder != null) { + UserBean userBean = new UserBean(); + userBean.setId(map.getString("uid")); + userBean.setAvatar(map.getString("uhead")); + userBean.setUserNiceName(map.getString("uname")); + livePushSwViewHolder.setAnPkRtc(userBean); + } + break; + case 3://对方主播拒绝PK的回调 + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); + mListener.onLinkMicPkRefuse(); + break; + case 4://所有人收到PK开始址的回调 + L.eSw("所有人收到PK开始址的回调"); + // RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(map.getString("pkuid"))); + mListener.onLinkMicPkStart(map.getString("pkuid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders")); + break; + case 5://PK时候断开连麦的回调 +// if (rtcRoom != null) { + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.DISCONNEXT_PK_TIME)); + //断开连麦 + HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + } + }); +// } + if (livePushSwViewHolder != null) { + livePushSwViewHolder.onLinkMicAnchorClose(); + } + mListener.onLinkMicPkClose(1); + if (RandomPkManager.getInstance().isRandomModel()) { + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_DEFAULT); + } + break; + case 7://对方主播正在忙的回调 + mListener.onLinkMicPkBusy(); + break; + case 8://对方主播无响应的回调 + mListener.onLinkMicPkNotResponse(); + break; + case 9://pk结束的回调 + mListener.onLinkMicPkEnd(map.getString("win_uid")); + EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_PK_END).setObject(map.getString("uid"))); + if (livePushSwViewHolder != null) { + livePushSwViewHolder.onLinkMicAnchorClose(); + } + break; + case 10://系统发起PK回调 + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 2) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 2) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(map.getString("uid"), conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + + LiveNetManager.get(mContext).getLiveInfo(map.getString("uid"), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + mListener.onLinkMicToPk(map.getString("uid"), data.getAvatar(), map.getString("uhead")); + mListener.onLinkMicPkStart(map.getString("uid"), data.getAvatar(), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); + if (livePushSwViewHolder != null) { + UserBean userBean = new UserBean(); + userBean.setId(map.getString("uid")); + userBean.setAvatar(data.getAvatar()); + userBean.setUserNiceName(map.getString("uname")); + livePushSwViewHolder.setAnPkRtc(userBean); + } + } + + @Override + public void onError(String error) { + + } + } + ); + + /*JSONObject msg1 = new JSONObject(); + msg1.put("type", "autoLivePK"); + msg1.put("uid", CommonAppConfig.getInstance().getUid()); + msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); + msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()); + IMRTCManager.getInstance().requestJoinOtherRoom(map.getString("uid"), true, msg1.toString(), new IRCRTCResultCallback() { + @Override + public void onSuccess() { + if (WordUtil.isNewZh()) { + ToastUtil.show("邀请 " + map.getString("uid") + " 发送成功"); + } else { + ToastUtil.show("invite " + map.getString("uid") + " successful"); + } + runOnUiThread(new Runnable() { + @Override + public void run() { + dismiss(); + } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + runOnUiThread(new Runnable() { + @Override + public void run() { + dismiss(); + } + }); + //todo 安卓端状态码说明文档:https://docs.rongcloud.cn/v4/views/rtc/call/code/android.html + Log.e("ry", rtcErrorCode + "aaaaaa" + CommonAppConfig.getInstance().getUid() + "VDSSSS" + map.getString("uid")); + if (WordUtil.isNewZh()) { + ToastUtil.show("邀请 " + map.getString("uid") + " 发送失败 :" + rtcErrorCode); + } else { + ToastUtil.show("invite " + map.getString("uid") + " lose :" + rtcErrorCode); + } + } + });*/ + break; + } + } + } +} diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java new file mode 100644 index 000000000..9c7281eb9 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java @@ -0,0 +1,210 @@ +package com.yunbao.live.socket; + +import android.util.Log; + +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.Constants; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; + +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; +import io.rong.message.TextMessage; + +public class SocketSwLinkMicPkUtil { + /** + * 发起PK申请 + * + * @param pkUid 对方主播的uid + * @param stream 自己直播间的stream + */ + public static void linkMicPkApply(SocketSwClient client, String pkUid, String stream) { + if (client == null) { + return; + } + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + } + + + /** + * 主播接受对方主播的Pk请求 + * + * @param pkUid 对方主播的uid + */ + public static void linkMicPkAccept(SocketSwClient client, String pkUid, String url, String name) { + HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("pkuid", pkUid) + .params("type", "1") + .params("sign", "1") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msgs, String[] info) { + if (code == 0) { + + HttpClient.getInstance().get("Livepk.setPK", "Livepk.setPK") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("pkuid", pkUid) + .params("type", "1") + .params("sign", "1") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msgs, String[] info) { + if (code == 0) { + Log.e("ry",name+"啊啊"+url); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", Constants.SOCKET_LINK_MIC_PK) + .param("action", 4) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", pkUid) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("pkhead", url) + .param("pkname", name); + msg1.create(); + + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + Message message1 = Message.obtain("g" + CommonAppConfig.getInstance().getUid(), conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message1, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + } + + } + }); + } + } + }); + + + } + + /** + * 主播接受对方主播的Pk请求 + * + * @param pkUid 对方主播的uid + */ + public static void linkMicDRPkAccept(String pkUid) { + + + } + + /** + * 主播拒绝其他主播的连麦请求 + */ + public static void linkMicPkRefuse(SocketSwClient client, String pkUid) { + if (client == null) { + return; + } + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_LINK_MIC_PK) + .param("action", 3) + .param("msgtype", 0) + .param("uid", u.getId()) + .param("uname", u.getUserNiceName()) + .param("pkuid", pkUid) + .param("ct", ""); + + msg.create(); + + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(pkUid, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + + } + + + /** + * 主播断开连麦 + */ + public static void linkMicAnchorClose(SocketSwClient client, String pkUid) { + if (client == null) { + return; + } + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } +// client.send(new SocketSendBean() +// .param("_method_", Constants.SOCKET_LINK_MIC_PK) +// .param("action", 5) +// .param("msgtype", 0) +// .param("uid", u.getId()) +// .param("ct", "") +// .param("pkuid", pkUid) +// .param("uname", u.getUserNiceName())); + + + } + + /** + * 当收到主播连麦的请求时候主播正在忙 + */ + public static void linkMicPkBusy(SocketClient client, String pkUid) { + if (client == null) { + return; + } +// client.send(new SocketSendBean() +// .param("_method_", Constants.SOCKET_LINK_MIC_PK) +// .param("action", 7) +// .param("msgtype", 10) +// .param("pkuid", pkUid)); + } + + /** + * 当收到主播连麦的请求时候主播无响应 + */ + public static void linkMicPkNotResponse(SocketSwClient client, String pkUid) { + if (client == null) { + return; + } +// client.send(new SocketSendBean() +// .param("_method_", Constants.SOCKET_LINK_MIC_PK) +// .param("action", 8) +// .param("msgtype", 10) +// .param("pkuid", pkUid)); + } + + +} diff --git a/live/src/main/java/com/yunbao/live/utils/LiveRoomVoteManager.java b/live/src/main/java/com/yunbao/live/utils/LiveRoomVoteManager.java index 8407e8dca..297ce9e17 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveRoomVoteManager.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveRoomVoteManager.java @@ -19,10 +19,8 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; -import java.util.HashMap; -import java.util.Map; import java.util.Timer; import java.util.TimerTask; @@ -60,7 +58,7 @@ public class LiveRoomVoteManager { mAnchorVoteHide.setOnClickListener(v -> hideAnchorVote()); mVoteShow.setOnClickListener(v -> hideAnchorVote()); mClose.setOnClickListener(v -> close()); - if (mContext instanceof LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity) { isAnchor = true; } else { isAnchor = false; diff --git a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java index 0a3d60e56..508d1aeae 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java @@ -104,7 +104,6 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { initLittlePanda(); } - @Override protected int getLayoutId() { return R.layout.view_live_audience; diff --git a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java index 727b38003..42336041f 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java @@ -37,6 +37,7 @@ import com.yunbao.live.R; import com.yunbao.live.activity.LiveAnchorActivity; import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.SearchRecommendBodyAdapter; import com.yunbao.live.event.JumpUserHomeEvent; import com.yunbao.common.event.LiveRoomChangeEvent; @@ -234,9 +235,10 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList ((LiveAnchorActivity) mContext).superBackPressed(); } else if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); - } else if (mContext instanceof LiveRyAnchorActivity) { + } else if (mContext instanceof LiveSwAnchorActivity) { + ((LiveSwAnchorActivity) mContext).superBackPressed(); + }else if(mContext instanceof LiveRyAnchorActivity){ ((LiveRyAnchorActivity) mContext).superBackPressed(); - } Bus.get().post(new CloseEvent()); } @@ -266,9 +268,8 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList ((LiveAnchorActivity) mContext).superBackPressed(); } else if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); - } else if (mContext instanceof LiveRyAnchorActivity) { - ((LiveRyAnchorActivity) mContext).superBackPressed(); - + } else if (mContext instanceof LiveSwAnchorActivity) { + ((LiveSwAnchorActivity) mContext).superBackPressed(); } Bus.get().post(new CloseEvent()); } @@ -365,9 +366,10 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList ((LiveAnchorActivity) mContext).superBackPressed(); } else if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); - } else if (mContext instanceof LiveRyAnchorActivity) { + } else if (mContext instanceof LiveSwAnchorActivity) { + ((LiveSwAnchorActivity) mContext).superBackPressed(); + }else if(mContext instanceof LiveRyAnchorActivity){ ((LiveRyAnchorActivity) mContext).superBackPressed(); - } Bus.get().post(new CloseEvent()); } @@ -424,7 +426,7 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -448,7 +450,9 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList ((LiveAnchorActivity) mContext).superBackPressed(); } else if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); - } else if (mContext instanceof LiveRyAnchorActivity) { + } else if (mContext instanceof LiveSwAnchorActivity) { + ((LiveSwAnchorActivity) mContext).superBackPressed(); + }else if(mContext instanceof LiveRyAnchorActivity){ ((LiveRyAnchorActivity) mContext).superBackPressed(); } } diff --git a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java index 75e3aaa8b..3d25e452b 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveNewReadyRyViewHolder.java @@ -65,7 +65,6 @@ import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.dialog.LiveAnchorEditCallMeDialog; import com.yunbao.live.dialog.LiveAnchorSayPopDialog; import com.yunbao.live.dialog.LiveFaceUnityDialogFragment; -import com.yunbao.live.dialog.LiveFaceUnityDialogNewFragment; import com.yunbao.live.dialog.LiveNewRoomClassDialogFragment; import com.yunbao.live.dialog.LiveNewRoomTypeDialogFragment; import com.yunbao.live.dialog.LiveTimeDialogFragment; @@ -77,7 +76,10 @@ import org.greenrobot.eventbus.ThreadMode; import java.io.File; import java.util.Locale; -import io.agora.beautyapi.faceunity.agora.SWManager; +import cn.rongcloud.rtc.api.RCRTCEngine; +import cn.rongcloud.rtc.api.stream.RCRTCCameraOutputStream; +import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; +import cn.rongcloud.rtc.base.RCRTCParamsType; public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnClickListener { @@ -305,6 +307,7 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl } private void setSelectClarity(int selectClarity) { + this.selectClarity = selectClarity; IMLoginManager.get(mContext).setSelectClarity(selectClarity); switch (selectClarity) { @@ -324,7 +327,35 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl if (liveOpenCustomPopup != null) { liveOpenCustomPopup.setSelectClarity(selectClarity); } - SWManager.get().setDimensions(selectClarity); + //設置開播分辨率 + RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; + int minRate = 200; + int maxRate = 900; + switch (selectClarity) { + case 0: + rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; + minRate = 200; + maxRate = 900; + break; + case 1: + rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; + minRate = 250; + maxRate = 2200; + break; + case 2: + rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; + minRate = 400; + maxRate = 4000; + break; + } + RCRTCVideoStreamConfig config = + RCRTCVideoStreamConfig.Builder.create() + .setMinRate(minRate) + .setMaxRate(maxRate) + .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_15) + .setVideoResolution(rcrtcVideoResolution) + .build(); + RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); Log.e("切换分辨率", "时间戳" + System.currentTimeMillis()); //重新发布一下流 Bus.get().post(new LivePushRyEvent()); @@ -536,7 +567,8 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl } else if (i == R.id.btn_locaiton) { switchLocation(); } else if (i == R.id.btn_horizontally) { - SWManager.get().setMirrorMode(); + RCRTCCameraOutputStream cameraStream = RCRTCEngine.getInstance().getDefaultVideoStream(); + cameraStream.setPreviewMirror(!cameraStream.isPreviewMirror()); } else if (i == R.id.btn_robot) { new XPopup.Builder(mContext) .asCustom(new LiveRobotSettingCustomPopup(mContext)) @@ -580,20 +612,6 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl } } - public void setFaceUnityNew(boolean init){ - LiveFaceUnityDialogNewFragment fragment = new LiveFaceUnityDialogNewFragment(mContext); - fragment.setManager(manager); - fragment.setDismissShowUi(mRootView); - if (mContext instanceof LiveRyAnchorActivity) { - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "FaceUnity"); - mRootView.setVisibility(View.INVISIBLE); - if (init) { - fragment.dismiss(); - } - } - } - - /** * 打开心愿单窗口 */ @@ -923,7 +941,7 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl return; } String title = mEditTitle.getText().toString().trim(); - LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile, IMLoginManager.get(mContext).getSelectClarity() + 1, new HttpCallback() { + LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile, IMLoginManager.get(mContext).getSelectClarity() + 1, false,new HttpCallback() { @Override public void onSuccess(int code, String msg, final String[] info) { if (code == 0 && info.length > 0) { diff --git a/live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java new file mode 100644 index 000000000..ff5bd9ede --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java @@ -0,0 +1,963 @@ +package com.yunbao.live.views; + +import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.WISH_LIST_UPDATE; + +import android.app.Dialog; +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.os.Build; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.text.Html; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.core.content.ContextCompat; + +import com.lxj.xpopup.XPopup; +import com.lxj.xpopup.core.BasePopupView; +import com.lxj.xpopup.interfaces.XPopupCallback; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.Constants; +import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.bean.LiveAnchorCallMeModel; +import com.yunbao.common.bean.LiveAnchorSayModel; +import com.yunbao.common.bean.LiveClassBean; +import com.yunbao.common.bean.LiveRoomTypeBean; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.event.LivePushRyEvent; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.LiveHttpConsts; +import com.yunbao.common.http.LiveHttpUtil; +import com.yunbao.common.interfaces.CommonCallback; +import com.yunbao.common.interfaces.ImageResultCallback; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.ProcessImageUtil; +import com.yunbao.common.utils.RouteUtil; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.views.AbsViewHolder; +import com.yunbao.common.views.LiveClarityCustomPopup; +import com.yunbao.common.views.LiveNewWishListPopup; +import com.yunbao.common.views.LiveOpenCustomPopup; +import com.yunbao.common.views.LiveRobotSettingCustomPopup; +import com.yunbao.common.views.weight.ViewClicksAntiShake; +import com.yunbao.faceunity.FaceManager; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; +import com.yunbao.live.dialog.LiveAnchorEditCallMeDialog; +import com.yunbao.live.dialog.LiveAnchorSayPopDialog; +import com.yunbao.live.dialog.LiveFaceUnityDialogFragment; +import com.yunbao.live.dialog.LiveFaceUnityDialogNewFragment; +import com.yunbao.live.dialog.LiveNewRoomClassDialogFragment; +import com.yunbao.live.dialog.LiveNewRoomTypeDialogFragment; +import com.yunbao.live.dialog.LiveTimeDialogFragment; +import com.yunbao.live.event.LiveAudienceEvent; + +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.io.File; +import java.util.Locale; + +import io.agora.beautyapi.faceunity.agora.SWManager; + +public class LiveNewReadySwViewHolder extends AbsViewHolder implements View.OnClickListener { + + private ConstraintLayout mAvatar, mRootView; + private TextView mCoverText; + private EditText mEditTitle; + private ProcessImageUtil mImageUtil; + private File mAvatarFile; + private TextView mLiveClass, anchorAgreement; + private TextView mLiveTypeTextView, liveClarity;//房间类型TextView + private TextView mLiveWishListTextView;//心愿单TextView + private int mLiveClassID;//直播频道id + private int mLiveType;//房间类型 + private int mLiveTypeVal;//房间密码,门票收费金额 + private int mLiveTimeCoin;//计时收费金额 + private boolean mOpenLocation = true; + private int mLiveSdk; + private LiveClassBean classBean; + private FaceManager manager; + private TextView faceTextView;//提示人脸未检测到的TextView + private ImageView imgClarity, selectorProtocol; + private int selectClarity = 1; + private LiveOpenCustomPopup liveOpenCustomPopup; + private boolean selector = true; + private String mLiveUid; + + public LiveNewReadySwViewHolder(Context context, ViewGroup parentView, int liveSdk) { + super(context, parentView, liveSdk); + } + + @Override + protected void processArguments(Object... args) { + if (args.length > 0) { + mLiveSdk = (int) args[0]; + } + } + + @Override + protected int getLayoutId() { + return R.layout.view_new_live_ready; + } + + @Override + public void init() { + mRootView = (ConstraintLayout) findViewById(R.id.traceroute_rootview); + imgClarity = (ImageView) findViewById(R.id.img_clarity); + selectorProtocol = (ImageView) findViewById(R.id.selector_protocol); + liveClarity = (TextView) findViewById(R.id.live_clarity); + anchorAgreement = (TextView) findViewById(R.id.anchor_agreement); + mRootView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + InputMethodManager imm = (InputMethodManager) + mContext.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + }); + + mAvatar = (ConstraintLayout) findViewById(R.id.avatar); + mAvatar.setOnClickListener(this); + UserBean u = CommonAppConfig.getInstance().getUserBean(); + ImgLoader.displayDrawable(mContext, u.getAvatar(), new ImgLoader.DrawableCallback() { + @Override + public void onLoadSuccess(Drawable drawable) { + mAvatar.setBackground(drawable); + } + + @Override + public void onLoadFailed() { + + } + }); + mCoverText = (TextView) findViewById(R.id.cover_text); + mEditTitle = (EditText) findViewById(R.id.edit_title); + findViewById(R.id.btn_room_type).setOnClickListener(this); + mOpenLocation = true; + mLiveClass = (TextView) findViewById(R.id.live_class); + mLiveTypeTextView = (TextView) findViewById(R.id.text_room_type); + mLiveWishListTextView = (TextView) findViewById(R.id.text_wishlist); + faceTextView = (TextView) findViewById(R.id.faceTextView); + + mImageUtil = ((LiveActivity) mContext).getProcessImageUtil(); + mImageUtil.setImageResultCallback(new ImageResultCallback() { + + @Override + public void beforeCamera() { + ((LiveSwAnchorActivity) mContext).beforeCamera(); + } + + @Override + public void onSuccess(File file) { + if (file != null) { + ImgLoader.displayFileDrawable(mContext, file, new ImgLoader.DrawableCallback() { + @Override + public void onLoadSuccess(Drawable drawable) { + mAvatar.setBackground(drawable); + } + + @Override + public void onLoadFailed() { + + } + }); + if (mAvatarFile == null) { + mCoverText.setText(mContext.getString(R.string.live_cover_2)); + mCoverText.setBackground(ContextCompat.getDrawable(mContext, R.drawable.bg_live_cover)); + } + mAvatarFile = file; + } + } + + @Override + public void onFailure() { + } + }); + findViewById(R.id.btn_camera).setOnClickListener(this); + findViewById(R.id.btn_live_class).setOnClickListener(this); + findViewById(R.id.btn_close).setOnClickListener(this); + findViewById(R.id.btn_beauty).setOnClickListener(this); + findViewById(R.id.btn_robot).setOnClickListener(this); + findViewById(R.id.btn_start_live).setOnClickListener(this); + findViewById(R.id.btn_wishlist).setOnClickListener(this); + findViewById(R.id.btn_horizontally).setOnClickListener(this); + findViewById(R.id.anchor_agreement_layout).setOnClickListener(this); + findViewById(R.id.btn_live_anchor_say).setOnClickListener(this); + findViewById(R.id.btn_live_anchor_call_me).setOnClickListener(this); + + if (manager != null) { + manager.setFaceStatusChanged(new FaceManager.FaceStatusChanged() { + final Handler handler = new Handler(Looper.getMainLooper()); + + @Override + public void onFaceChanged(int num) { + handler.post(() -> { + if (num == 0) { + faceTextView.setVisibility(View.VISIBLE); + } else { + faceTextView.setVisibility(View.GONE); + } + }); + } + }); + //新美颜 + setFaceUnity(true); + + } + //设置清晰度 +// DeviceUtils.getMemory(mContext); //获取可用内存 +// DeviceUtils.getNetSpeed(mContext);//获取当前上传网速 +// Log.e("网速和内存", "内存:" + + " 网速:" + DeviceUtils.getNetSpeed(mContext)); + + IMLoginManager.get(mContext).setSelectClarity(selectClarity); + setSelectClarity(IMLoginManager.get(mContext).getSelectClarity()); + ViewClicksAntiShake + .clicksAntiShake( + findViewById(R.id.btn_live_clarity), () -> { + + LiveClarityCustomPopup liveClarityCustomPopup = + new LiveClarityCustomPopup(mContext, + IMLoginManager.get(mContext).getSelectClarity(), + IMLoginManager.get(mContext).getClarity() ? 0 : LiveClarityCustomPopup.BAN_1080, false); + new XPopup.Builder(mContext) + .setPopupCallback(new XPopupCallback() { + @Override + public void onCreated(BasePopupView popupView) { + + } + + @Override + public void beforeShow(BasePopupView popupView) { + + } + + @Override + public void onShow(BasePopupView popupView) { + + } + + @Override + public void onDismiss(BasePopupView popupView) { + setSelectClarity(liveClarityCustomPopup.getSelectClarity()); + } + + @Override + public void beforeDismiss(BasePopupView popupView) { + + } + + @Override + public boolean onBackPressed(BasePopupView popupView) { + return false; + } + + @Override + public void onKeyBoardStateChanged(BasePopupView popupView, int height) { + + } + + @Override + public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { + + } + + @Override + public void onClickOutside(BasePopupView popupView) { + + } + }) + .asCustom(liveClarityCustomPopup) + .show(); + }); + String keywordHtml2 = "" + mContext.getString(R.string.anchor_hint) + ""; + String contextHtml = "" + mContext.getString(R.string.anchor_agreement) + ""; + anchorAgreement.setText(Html.fromHtml(contextHtml + keywordHtml2)); + selectorProtocol.setPressed(true); + selectorProtocol.setSelected(true); + selector = selectorProtocol.isSelected(); + selectorProtocol.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + selector = !selector; + selectorProtocol.setSelected(selector); + } + }); + } + + private void setSelectClarity(int selectClarity) { + this.selectClarity = selectClarity; + IMLoginManager.get(mContext).setSelectClarity(selectClarity); + switch (selectClarity) { + case 0: + imgClarity.setImageResource(R.mipmap.icon_sd); + liveClarity.setText(R.string.standard_clear); + break; + case 1: + imgClarity.setImageResource(R.mipmap.icon_hd); + liveClarity.setText(R.string.high_definition); + break; + case 2: + imgClarity.setImageResource(R.mipmap.icon_fhd); + liveClarity.setText(R.string.ultra_hd); + break; + } + if (liveOpenCustomPopup != null) { + liveOpenCustomPopup.setSelectClarity(selectClarity); + } + SWManager.get().setDimensions(selectClarity); + Log.e("切换分辨率", "时间戳" + System.currentTimeMillis()); + //重新发布一下流 + Bus.get().post(new LivePushRyEvent()); + } + + public void setManager(FaceManager manager) { + this.manager = manager; + } + + + @Override + public void onClick(View v) { + if (!canClick()) { + return; + } + int i = v.getId(); + if (i == R.id.avatar) { + setAvatar(); + + } else if (i == R.id.btn_camera) { + toggleCamera(); + } else if (i == R.id.btn_close) { + close(); + } else if (i == R.id.btn_live_class) { + chooseLiveClass(); + } else if (i == R.id.btn_beauty) { + //beauty();//momo美颜 + setFaceUnity(false); //新娱美颜 + } else if (i == R.id.btn_wishlist) { + //点击心愿单 + openWishListWindow(); + } else if (i == R.id.btn_room_type) { + chooseLiveType(); + } else if (i == R.id.btn_start_live) { + if (!selector) { + ToastUtil.show(mContext.getString(R.string.anchor_agreement_hint)); + return; + } + if (mLiveClassID == 0) { + ToastUtil.show(WordUtil.getNewString(R.string.live_choose_live_class)); + return; + } +// startLive(); + liveOpenCustomPopup = new LiveOpenCustomPopup(mContext, IMLoginManager.get(mContext).getSelectClarity(), classBean, liveRoomTypeBean) + .setSayStatus(IMLoginManager.get(mContext).getAnchorSayStatus()) + .setCallMeStatus(IMLoginManager.get(mContext).getAnchorCallStatus()) + .setCallBack(new LiveOpenCustomPopup.LiveOpenCallBack() { + @Override + + public void startLive(LiveRoomTypeBean liveRoomTypeModel, LiveClassBean classModel) { + if (classModel != null) { + classBean = classModel; + mLiveClassID = classBean.getId(); + } + liveRoomTypeBean = liveRoomTypeModel; + mLiveType = liveRoomTypeModel.getId(); + startLiveInit(); + liveOpenCustomPopup = null; + } + + @Override + public void selectClarity(int selectClarity) { + LiveClarityCustomPopup liveClarityCustomPopup = + new LiveClarityCustomPopup(mContext, + IMLoginManager.get(mContext).getSelectClarity(), + IMLoginManager.get(mContext).getClarity() ? 0 : LiveClarityCustomPopup.BAN_1080, false); + new XPopup.Builder(mContext) + .setPopupCallback(new XPopupCallback() { + @Override + public void onCreated(BasePopupView popupView) { + + } + + @Override + public void beforeShow(BasePopupView popupView) { + + } + + @Override + public void onShow(BasePopupView popupView) { + + } + + @Override + public void onDismiss(BasePopupView popupView) { + setSelectClarity(liveClarityCustomPopup.getSelectClarity()); + } + + @Override + public void beforeDismiss(BasePopupView popupView) { + + } + + @Override + public boolean onBackPressed(BasePopupView popupView) { + return false; + } + + @Override + public void onKeyBoardStateChanged(BasePopupView popupView, int height) { + + } + + @Override + public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { + + } + + @Override + public void onClickOutside(BasePopupView popupView) { + + } + }) + .asCustom(liveClarityCustomPopup) + .show(); + } + + @Override + public void openRobot() { + LiveRobotSettingCustomPopup liveRobotSettingCustomPopup = new LiveRobotSettingCustomPopup(mContext); + new XPopup.Builder(mContext) + .setPopupCallback(new XPopupCallback() { + @Override + public void onCreated(BasePopupView popupView) { + + } + + @Override + public void beforeShow(BasePopupView popupView) { + + } + + @Override + public void onShow(BasePopupView popupView) { + + } + + @Override + public void onDismiss(BasePopupView popupView) { + if (liveOpenCustomPopup != null) { + liveOpenCustomPopup.initDate(); + } + } + + @Override + public void beforeDismiss(BasePopupView popupView) { + + } + + @Override + public boolean onBackPressed(BasePopupView popupView) { + return false; + } + + @Override + public void onKeyBoardStateChanged(BasePopupView popupView, int height) { + + } + + @Override + public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { + + } + + @Override + public void onClickOutside(BasePopupView popupView) { + + } + }) + .asCustom(liveRobotSettingCustomPopup) + .show(); + } + + @Override + public void openLiveRoomType(LiveRoomTypeBean liveRoomTypeModel) { + liveRoomTypeBean = liveRoomTypeModel; + mLiveType = liveRoomTypeModel.getId(); + chooseLiveType(); + } + + @Override + public void openLiveClass(LiveClassBean classModel) { + if (classModel != null) { + classBean = classModel; + mLiveClassID = classBean.getId(); + } + chooseLiveClass(); + } + + @Override + public void openWishlist() { + //点击心愿单 + openWishListWindow(); + } + + @Override + public void openAnchorSay() { + openAnchorSayDialog(); + } + + @Override + public void openCallMe() { + openAnchorCallMeDialog(); + } + }); + new XPopup.Builder(mContext) + .asCustom(liveOpenCustomPopup) + .show(); + } else if (i == R.id.btn_locaiton) { + switchLocation(); + } else if (i == R.id.btn_horizontally) { + SWManager.get().setMirrorMode(); + } else if (i == R.id.btn_robot) { + new XPopup.Builder(mContext) + .asCustom(new LiveRobotSettingCustomPopup(mContext)) + .show(); + } else if (i == R.id.anchor_agreement_layout) { + String ct = Locale.getDefault().getLanguage(); + IMLoginModel model = IMLoginManager.get(mContext).getUserInfo(); + StringBuffer url = new StringBuffer(); + url.append(CommonAppConfig.HOST); + if (TextUtils.equals(ct, "zh")) { + url.append("/index.php?g=portal&m=page&a=index&id=671"); + } else { + url.append("/index.php?g=portal&m=page&a=index&id=672"); + } + url.append("&uid=") + .append(model.getId()) + .append("&token=") + .append(model.getToken()).append("&isZh=") + .append(WordUtil.isNewZh() ? "1" : 0); + RouteUtil.forwardLiveZhuangBanActivity(url.toString(), false); + } else if (i == R.id.btn_live_anchor_say) { + openAnchorSayDialog(); + } else if (i == R.id.btn_live_anchor_call_me) { + openAnchorCallMeDialog(); + } + } + + /** + * 新娱美颜 + */ + public void setFaceUnity(boolean init) { + LiveFaceUnityDialogFragment fragment = new LiveFaceUnityDialogFragment(mContext); + fragment.setManager(manager); + fragment.setDismissShowUi(mRootView); + if (mContext instanceof LiveSwAnchorActivity) { + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "FaceUnity"); + mRootView.setVisibility(View.INVISIBLE); + if (init) { + fragment.dismiss(); + } + } + } + + public void setFaceUnityNew(boolean init){ + LiveFaceUnityDialogNewFragment fragment = new LiveFaceUnityDialogNewFragment(mContext); + fragment.setManager(manager); + fragment.setDismissShowUi(mRootView); + if (mContext instanceof LiveSwAnchorActivity) { + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "FaceUnity"); + mRootView.setVisibility(View.INVISIBLE); + if (init) { + fragment.dismiss(); + } + } + } + + + /** + * 打开心愿单窗口 + */ + public void openWishListWindow() { +// LiveNewWishListDialogFragment fragment = new LiveNewWishListDialogFragment(); +// +// if (mContext instanceof LiveRyAnchorActivity) { +// fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "RY"); +// +// } + new XPopup.Builder(mContext) + .enableDrag(false) + .asCustom(new LiveNewWishListPopup((LiveSwAnchorActivity) mContext)) + .show(); + } + + public void openAnchorSayDialog() { + new LiveAnchorSayPopDialog(mContext).setLiveUid(mLiveUid).setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(LiveAnchorSayModel bean, int position) { + if (liveOpenCustomPopup != null) { + liveOpenCustomPopup.setSayStatus(bean.getLivePreview().getIsShow() == 1); + } + } + }).showDialog(); + } + + public void openAnchorCallMeDialog() { + new LiveAnchorEditCallMeDialog(mContext).setLiveUid(mLiveUid).setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(LiveAnchorCallMeModel bean, int position) { + if (liveOpenCustomPopup != null) { + liveOpenCustomPopup.setCallMeStatus(bean.getIsShow() == 1); + } + } + }).showDialog(); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void updateStart(LiveAudienceEvent event) { + if (event.getType() == WISH_LIST_UPDATE) { + if (liveOpenCustomPopup != null) { + liveOpenCustomPopup.initDate(); + } + } + } + + /** + * 打开 关闭位置 + */ + private void switchLocation() { + if (mOpenLocation) { + new DialogUitl.Builder(mContext) + .setContent(mContext.getString(R.string.live_location_close_3)) + .setCancelable(true) + .setConfirmString(mContext.getString(R.string.live_location_close_2)) + .setClickCallback(new DialogUitl.SimpleCallback() { + + @Override + public void onConfirmClick(Dialog dialog, String content) { + toggleLocation(); + } + }) + .build() + .show(); + } else { + toggleLocation(); + } + } + + private void toggleLocation() { + mOpenLocation = !mOpenLocation; + } + + /** + * 设置头像 + */ + private void setAvatar() { + if (mLiveSdk == Constants.LIVE_SDK_TX) { + mImageUtil.getImageByAlumb(); + } else { + DialogUitl.showStringArrayDialog(mContext, new Integer[]{ + R.string.camera, R.string.alumb}, new DialogUitl.StringArrayDialogCallback() { + @Override + public void onItemClick(String text, int tag) { + if (tag == R.string.camera) { + mImageUtil.getImageByCamera(); + } else { + mImageUtil.getImageByAlumb(); + } + } + }); + } + } + + /** + * 切换镜头 + */ + private void toggleCamera() { + ((LiveSwAnchorActivity) mContext).toggleCamera(); + } + + /** + * 关闭 + */ + private void close() { + ((LiveSwAnchorActivity) mContext).endLives(); + } + + /** + * 选择直播频道 + */ + private void chooseLiveClass() { + /* try { + Intent intent = new Intent(mContext, LiveChooseClassActivity.class); + intent.putExtra(Constants.CLASS_ID, mLiveClassID); + mImageUtil.startActivityForResult(intent, mActivityResultCallback); + }catch (Exception e){ + + }*/ + + Bundle bundle = new Bundle(); + bundle.putInt(Constants.CLASS_ID, mLiveClassID); + LiveNewRoomClassDialogFragment fragment = new LiveNewRoomClassDialogFragment(); + fragment.setArguments(bundle); + fragment.setCallback(new CommonCallback() { + @Override + public void callback(LiveClassBean bean) { + classBean = bean; + mLiveClassID = classBean.getId(); + mLiveClass.setText(bean.getName()); + if (liveOpenCustomPopup != null) { + liveOpenCustomPopup.setClassBean(classBean); + } + } + }); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); + + } + + /** + * 设置美颜 + */ + private void beauty() { + ((LiveSwAnchorActivity) mContext).beauty(); + // Intent intent = new Intent(mContext, Beauty360Activity3.class); + // mContext.startActivity(intent); + + } + + /** + * 选择直播类型 + */ + private LiveRoomTypeBean liveRoomTypeBean = new LiveRoomTypeBean(0, mContext.getString(R.string.live_room_public)); + + private void chooseLiveType() { + Bundle bundle = new Bundle(); + bundle.putInt(Constants.CHECKED_ID, mLiveType); + LiveNewRoomTypeDialogFragment fragment = new LiveNewRoomTypeDialogFragment(); + fragment.setArguments(bundle); + fragment.setCallback(new CommonCallback() { + @Override + public void callback(LiveRoomTypeBean bean) { + liveRoomTypeBean = bean; + switch (bean.getId()) { + case Constants.LIVE_TYPE_NORMAL: + onLiveTypeNormal(bean); + break; + case Constants.LIVE_TYPE_PWD: + onLiveTypePwd(bean); + break; + case Constants.LIVE_TYPE_PAY: + onLiveTypePay(bean); + break; + case Constants.LIVE_TYPE_TIME: + onLiveTypeTime(bean); + break; + } + if (liveOpenCustomPopup != null) { + liveOpenCustomPopup.setLiveRoomTypeBean(liveRoomTypeBean); + } + } + }); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); + } + + /** + * 普通房间 + */ + private void onLiveTypeNormal(LiveRoomTypeBean bean) { + mLiveType = bean.getId(); + mLiveTypeTextView.setText(bean.getName()); + mLiveTypeVal = 0; + mLiveTimeCoin = 0; + } + + /** + * 密码房间 + */ + private void onLiveTypePwd(final LiveRoomTypeBean bean) { + DialogUitl.showSimpleInputDialog(mContext, mContext.getString(R.string.live_set_pwd), DialogUitl.INPUT_TYPE_NUMBER_PASSWORD, 8, new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + if (TextUtils.isEmpty(content)) { + ToastUtil.show(mContext.getString(R.string.live_set_pwd_empty)); + } else { + mLiveType = bean.getId(); + mLiveTypeTextView.setText(WordUtil.isNewZh() ? "密碼房" : "password room"); + if (StringUtil.isInt(content)) { + mLiveTypeVal = Integer.parseInt(content); + } + mLiveTimeCoin = 0; + dialog.dismiss(); + } + } + }); + } + + /** + * 付费房间 + */ + private void onLiveTypePay(final LiveRoomTypeBean bean) { + DialogUitl.showSimpleInputDialog(mContext, mContext.getString(R.string.live_set_fee), DialogUitl.INPUT_TYPE_NUMBER, 8, new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + if (TextUtils.isEmpty(content)) { + ToastUtil.show(mContext.getString(R.string.live_set_fee_empty)); + } else { + mLiveType = bean.getId(); + mLiveTypeTextView.setText(bean.getName()); + if (StringUtil.isInt(content)) { + mLiveTypeVal = Integer.parseInt(content); + } + mLiveTimeCoin = 0; + dialog.dismiss(); + } + } + }); + } + + /** + * 计时房间 + */ + private void onLiveTypeTime(final LiveRoomTypeBean bean) { + LiveTimeDialogFragment fragment = new LiveTimeDialogFragment(); + Bundle bundle = new Bundle(); + bundle.putInt(Constants.CHECKED_COIN, mLiveTimeCoin); + fragment.setArguments(bundle); + fragment.setCommonCallback(new CommonCallback() { + @Override + public void callback(Integer coin) { + mLiveType = bean.getId(); + mLiveTypeTextView.setText(bean.getName()); + mLiveTypeVal = coin; + mLiveTimeCoin = coin; + } + }); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveTimeDialogFragment"); + } + + public void hide() { + if (mContentView != null && mContentView.getVisibility() == View.VISIBLE) { + mContentView.setVisibility(View.INVISIBLE); + } + } + + + public void show() { + if (mContentView != null && mContentView.getVisibility() != View.VISIBLE) { + mContentView.setVisibility(View.VISIBLE); + } + } + + /** + * 点击开始直播按钮 + */ + private void startLiveInit() { + if (isWifiProxy(mContext) || checkVPN((ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE))) { + ToastUtil.show(WordUtil.isNewZh()?"檢測開啓了VPN或者代理,請先關閉VPN或者代理再開播。": + "It is detected that VPN or proxy is turned on. Please turn off VPN or proxy before starting the broadcast."); + } else { + boolean startPreview = ((LiveSwAnchorActivity) mContext).isStartPreview(); +// if (!startPreview) { +// ToastUtil.show(R.string.please_wait); +// return; +// } + if (mLiveClassID == 0) { + ToastUtil.show(WordUtil.getNewString(R.string.live_choose_live_class)); + return; + } + createRoom(); + } + } + + private boolean isWifiProxy(Context context) { + final boolean IS_ICS_OR_LATER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; + String proxyAddress; + int proxyPort; + if (IS_ICS_OR_LATER) { + proxyAddress = System.getProperty("http.proxyHost"); + String portStr = System.getProperty("http.proxyPort"); + proxyPort = Integer.parseInt((portStr != null ? portStr : "-1")); + } else { + proxyAddress = android.net.Proxy.getHost(context); + proxyPort = android.net.Proxy.getPort(context); + } + return (!TextUtils.isEmpty(proxyAddress)) && (proxyPort != -1); + } + + private boolean checkVPN(ConnectivityManager connMgr) { + //don't know why always returns null: + NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_VPN); + boolean isVpnConn = networkInfo == null ? false : networkInfo.isConnected(); + return isVpnConn; + } + + /** + * 请求创建直播间接口,开始直播 + */ + boolean isHttpBack = false; + + private void createRoom() { + if (!isHttpBack) { + isHttpBack = true; + if (mLiveClassID == 0) { + ToastUtil.show(WordUtil.getNewString(R.string.live_choose_live_class)); + return; + } + String title = mEditTitle.getText().toString().trim(); + LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile, IMLoginManager.get(mContext).getSelectClarity() + 1,true, new HttpCallback() { + @Override + public void onSuccess(int code, String msg, final String[] info) { + if (code == 0 && info.length > 0) { + L.e("开播", "createRoom------->" + info[0]); + isHttpBack = false; + final CommonAppConfig appConfig = CommonAppConfig.getInstance(); + UserBean u = appConfig.getUserBean(); + ((LiveSwAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); + } else { + ToastUtil.show(msg); + } + } + + @Override + public void onError() { + super.onError(); + isHttpBack = false; + } + }); + } else { + ToastUtil.show("請求中,請勿重複點擊"); + } + } + + public void release() { + mImageUtil = null; + } + + @Override + public void onDestroy() { + LiveHttpUtil.cancel(LiveHttpConsts.CREATE_ROOM); + } + + public void setLiveUid(String mLiveUid) { + this.mLiveUid = mLiveUid; + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java index a379ef3e7..24614a852 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java @@ -11,25 +11,16 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.RelativeLayout; -import com.alibaba.fastjson.JSONObject; -import com.google.gson.Gson; import com.tencent.live2.V2TXLiveDef; import com.tencent.live2.V2TXLivePlayer; import com.tencent.live2.impl.V2TXLivePlayerImpl; import com.tencent.rtmp.ui.TXCloudVideoView; -import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.UserBean; import com.yunbao.common.glide.ImgLoader; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.HttpClient; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; import com.yunbao.common.utils.ScreenDimenUtil; import com.yunbao.live.R; -import com.yunbao.live.bean.DrPkbean; - -import java.util.ArrayList; -import java.util.List; /** * Created by cxf on 2018/10/10. @@ -77,7 +68,7 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder { @Override protected int getLayoutId() { - return R.layout.view_live_play_ksy; + return R.layout.view_live_play_sw; } @Override @@ -272,6 +263,36 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder { LivePlayKsyViewHolder.landscape =landscape; } + @Override + public void endPk() { + + } + + @Override + public void endpk(String liveUid) { + + } + + @Override + public void initSwEngine(String liveUid) { + + } + + @Override + public void removeDetailView() { + + } + + @Override + public void setPkView(String liveUid) { + + } + + @Override + public void claerDrPkInfoView() { + + } + @Override public ViewGroup getSmallContainer() { diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayListener.java b/live/src/main/java/com/yunbao/live/views/LivePlayListener.java index befa67854..39359037b 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayListener.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayListener.java @@ -12,7 +12,7 @@ public interface LivePlayListener extends LiveActivityLifeCallback { * * @param data 房间信息 */ - void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk); + void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk,boolean isSw); /** * 用户滑动移除该页面 diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 37fd85f13..52ba0d341 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -1,10 +1,8 @@ package com.yunbao.live.views; import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; -import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import android.Manifest; -import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.graphics.Color; @@ -15,28 +13,23 @@ import android.os.Looper; import android.text.TextUtils; import android.util.Log; import android.view.Gravity; -import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; -import com.alibaba.fastjson.JSONObject; import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.ui.StyledPlayerView; import com.google.android.exoplayer2.video.VideoSize; -import com.google.gson.Gson; import com.lxj.xpopup.XPopup; import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; import com.lzy.okserver.OkDownload; -import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.UserBean; import com.yunbao.common.dialog.LiveFontSizeSettingDialog; @@ -57,9 +50,8 @@ import com.yunbao.common.views.LiveClarityCustomPopup; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; -import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.event.LiveAudienceEvent; -import com.yunbao.live.socket.SocketSendBean; +import com.yunbao.live.utils.LiveExoPlayerManager; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -78,6 +70,7 @@ import cn.rongcloud.rtc.api.RCRTCRoomConfig; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; +import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback; import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleDataCallback; import cn.rongcloud.rtc.api.callback.IRCRTCVideoInputFrameListener; import cn.rongcloud.rtc.api.stream.RCRTCInputStream; @@ -94,11 +87,6 @@ import cn.rongcloud.rtc.base.RCRTCRoomType; import cn.rongcloud.rtc.base.RCRTCStreamType; import cn.rongcloud.rtc.base.RTCErrorCode; import cn.rongcloud.rtc.core.RendererCommon; -import io.agora.beautyapi.faceunity.agora.SWAuManager; -import io.rong.imlib.IRongCallback; -import io.rong.imlib.RongIMClient; -import io.rong.imlib.model.Conversation; -import io.rong.message.TextMessage; public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @@ -107,12 +95,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private ViewGroup mSmallContainer; private ViewGroup mLeftContainer; private ViewGroup mRightContainer; - private ViewGroup mPkContainer; + private RelativeLayout mPkContainer; public StyledPlayerView mVideoView; - private FrameLayout playFrameLayout; - private FrameLayout playFrameLayout1; - private View mLoading, mLoading2; private ImageView mCover; private boolean mPaused;//是否切后台了 @@ -131,29 +116,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { static int vHeight;//视频高 private TextView debugView; - //private LiveExoPlayerManager mPlayer; + private LiveExoPlayerManager mPlayer; private boolean isPk = false; private boolean userJoinLinkMic = false;//用户是否已加入房间 //0未申请1申请中2连麦中 RCRTCRoom rcrtcRoom; String purl, srcUrl; - SWAuManager swAuManager; - String liveUid; - - private LinearLayout dr_pk_view; - private FrameLayout dr1_preview; - private FrameLayout dr2_preview; - private FrameLayout dr3_preview; - private FrameLayout dr4_preview; - - private View detailsView1, detailsView2, detailsView3, detailsView4; - private LinearLayout detailsLinearLayout1, detailsLinearLayout2, detailsLinearLayout3, detailsLinearLayout4; - private LinearLayout linearGrade1, linearGrade2, linearGrade3, linearGrade4; - private TextView textPkName1, textPkName2, textPkName3, textPkName4; - private TextView textGrade1, textGrade2, textGrade3, textGrade4; - private ImageView imageGrade1, imageGrade2, imageGrade3, imageGrade4; - public int getLandscape() { return landscape; @@ -164,9 +133,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { contexts = context; landscape = landscapes; Log.i("收收收", landscape + ""); - L.eSw("liveUid:" + liveUid); } + @Override protected int getLayoutId() { return R.layout.view_live_play_ksy; @@ -178,12 +147,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { EventBus.getDefault().register(this); Bus.getOn(this); mRoot = (ViewGroup) findViewById(R.id.root); - playFrameLayout = (FrameLayout) findViewById(R.id.playView); - playFrameLayout1 = (FrameLayout) findViewById(R.id.playView1); mSmallContainer = (ViewGroup) findViewById(R.id.small_container); mLeftContainer = (ViewGroup) findViewById(R.id.left_container); mRightContainer = (ViewGroup) findViewById(R.id.right_container); - mPkContainer = (FrameLayout) findViewById(R.id.pk_container); + mPkContainer = (RelativeLayout) findViewById(R.id.pk_container); mVideoView = (StyledPlayerView) findViewById(R.id.video_view); ry_view = (FrameLayout) findViewById(R.id.ry_view); leave = (ImageView) findViewById(R.id.leave); @@ -198,269 +165,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params.height = vHeight; mPkContainer.requestLayout(); + mPlayer = new LiveExoPlayerManager(mContext); + mPlayer.setMainView(mVideoView); + mPlayer.setListener(new ExoPlayerListener()); debugView = new TextView(mContext); debugView.setBackgroundColor(Color.WHITE); - dr_pk_view = (LinearLayout) findViewById(R.id.dr_pk_view); - dr1_preview = (FrameLayout) findViewById(R.id.dr1_preview); - dr2_preview = (FrameLayout) findViewById(R.id.dr2_preview); - dr3_preview = (FrameLayout) findViewById(R.id.dr3_preview); - dr4_preview = (FrameLayout) findViewById(R.id.dr4_preview); - dr_pk_view.setVisibility(View.GONE); - } - - public void initSwEngine(String liveUid) { - this.liveUid = liveUid; - //初始化声网SDK - swAuManager = SWAuManager.get(); - swAuManager.setAudienceContainer(ry_view); - swAuManager.initRtcEngine((Activity) mContext); - swAuManager.setupRemoteVideo(Integer.parseInt(liveUid)); - //进入主播房间 - swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); - } - - /** - * 开启单人PK - * - * @param Uid - */ - public void setPkView(String Uid) { - L.eSw("setPkView Uid " + Uid); - mPkContainer.setVisibility(View.VISIBLE); - swAuManager.updateMyChannelView((FrameLayout) mLeftContainer, Integer.parseInt(liveUid)); - ry_view.removeAllViews(); - //加入对方主播房间 - swAuManager.setPkContainer1((FrameLayout) mRightContainer); - swAuManager.joinExRoomEx(Integer.parseInt(Uid), CommonAppConfig.SWToken, SWAuManager.getChannelName(Uid)); - } - - List drMicUserList = new ArrayList<>(); - - boolean isAdd = true; - - @Override - public void setDrMicInfo(UserBean u) { - isAdd = true; - L.eSw("setDrMicInfo:-----------------" + u.getId() + " drMicUserList" + new Gson().toJson(drMicUserList)); - for (int i = 0; i < drMicUserList.size(); i++) { - if (u.getId().equals(drMicUserList.get(i).getId()) || u.getId().equals(liveUid)) { - isAdd = false; - } - } - L.eSw("setDrMicInfo:---------------isAdd--" + isAdd); - //加载多人PK(连麦)主播视图 - if (isAdd) { - dr_pk_view.setVisibility(View.VISIBLE); - drMicUserList.add(u); - if (drMicUserList.size() == 1) { - L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 1"); - ry_view.removeAllViews(); - swAuManager.updateMyChannelView((FrameLayout) dr1_preview, Integer.parseInt(liveUid)); - swAuManager.joinChannelDrEx(dr2_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); - dr1_preview.setVisibility(View.VISIBLE); - dr2_preview.setVisibility(View.VISIBLE); - dr3_preview.setVisibility(View.GONE); - dr4_preview.setVisibility(View.GONE); - } else if (drMicUserList.size() == 2) { - L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 2"); - dr4_preview.setVisibility(View.VISIBLE); - swAuManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); - } else if (drMicUserList.size() == 3) { - L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 3"); - dr4_preview.setVisibility(View.VISIBLE); - dr3_preview.setVisibility(View.VISIBLE); - swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drMicUserList.get(1).getId()); - swAuManager.joinChannelDrEx(dr3_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drMicUserList.get(1).getId(), SWAuManager.getChannelName(drMicUserList.get(1).getId())); - swAuManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drMicUserList.get(2).getId(), SWAuManager.getChannelName(drMicUserList.get(2).getId())); - } - } - - HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", liveUid).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (info.length > 0) { - JSONObject obj = JSONObject.parseObject(info[0]); - List drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - int removeIndex = -1; - for (int i = 0; i < drPkbeans.size(); i++) { - if (liveUid.equals(String.valueOf(drPkbeans.get(i).getId()))) { - removeIndex = i; - } - } - if (removeIndex != -1) { - drPkbeans.remove(removeIndex); - } - setDrPkView(drPkbeans); - } - } - }); - } - - public void claerDrPkInfoView() { - if (detailsView1 != null) { - dr1_preview.removeView(detailsView1); - } - if (detailsView2 != null) { - dr2_preview.removeView(detailsView2); - } - if (detailsView3 != null) { - dr3_preview.removeView(detailsView3); - } - if (detailsView4 != null) { - dr4_preview.removeView(detailsView4); - } - } - - public void setDrPkView(List drPkbeanList) { - if (detailsView1 != null) { - dr1_preview.removeView(detailsView1); - } - - /*new Handler().postDelayed(new Runnable() { - @Override - public void run() { - - detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); - linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); - imageGrade1 = detailsView1.findViewById(R.id.image_grade1); - textGrade1 = detailsView1.findViewById(R.id.text_grade1); - textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - dr1_preview.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.GONE); - - for (int j = 0; j < drPkbeanList.size(); j++) { - if (j == 0) { - L.eSw("j == 0:" + j); - //设置多人PK数据 - if (detailsView2 != null) { - dr2_preview.removeView(detailsView2); - } - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(String.valueOf(drPkbeanList.get(0).getId())); - textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); - dr2_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.GONE); - } else if (j == 1) { - L.eSw("j == 1:" + j); - if (detailsView4 != null) { - dr4_preview.removeView(detailsView4); - } - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(String.valueOf(drPkbeanList.get(1).getId())); - textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); - dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.GONE); - } else if (j == 2) { - L.eSw("j == 2:" + j); - - if (detailsView4 != null) { - dr4_preview.removeView(detailsView4); - } - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(String.valueOf(drPkbeanList.get(2).getId())); - textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); - dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.GONE); - - if (detailsView3 != null) { - dr3_preview.removeView(detailsView3); - } - detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); - linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); - textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); - imageGrade3 = detailsView3.findViewById(R.id.image_grade3); - textGrade3 = detailsView3.findViewById(R.id.text_grade3); - imageGrade3.setTag(String.valueOf(drPkbeanList.get(1).getId())); - textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); - dr3_preview.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.VISIBLE); - linearGrade3.setVisibility(View.GONE); - } - } - } - }, 2000);*/ - } - - - /** - * 退出单人pk - * - * @param pkUid - */ - public void endpk(String pkUid) { - L.eSw("endpk " + pkUid); - mPkContainer.setVisibility(View.GONE); - swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), SWAuManager.getChannelName(pkUid)); - swAuManager.updateMyChannelView(ry_view, Integer.parseInt(liveUid)); - ry_view.setVisibility(View.VISIBLE); - mLeftContainer.removeAllViews(); - mRightContainer.removeAllViews(); - } - - /** - * 退出所有连麦主播的房間 - */ - public void endPk() { - dr_pk_view.setVisibility(View.GONE); - dr1_preview.setVisibility(View.GONE); - dr2_preview.setVisibility(View.GONE); - dr3_preview.setVisibility(View.GONE); - dr4_preview.setVisibility(View.GONE); - dr1_preview.removeAllViews(); - dr2_preview.removeAllViews(); - dr3_preview.removeAllViews(); - dr4_preview.removeAllViews(); - //退出所有连麦主播的房間 - for (int i = 0; i < drMicUserList.size(); i++) { - swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drMicUserList.get(i).getId()); - } - drMicUserList = new ArrayList<>(); - //將當前主播畫面放大 - swAuManager.updateMyChannelView((FrameLayout) ry_view, Integer.parseInt(liveUid)); - } - - /** - * 将用户设置成主播,与主播连麦 - */ - private void joinLiveMic() { - L.eSw("joinLiveMic"); - HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm").params("roomid", LiveActivity.mLiveUid).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.e("ry", code + "热热热"); - if (code == 0) { - swAuManager.setMicAn(true); - } - } - }); - } - - private void endLiveMic() { - L.eSw("endLiveMic"); - swAuManager.setMicAn(false); } @Override @@ -497,6 +207,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Log.i(TAG, "setLiveBeanLandscape: " + landscape + " isPk: " + isPk); this.landscape = landscape; this.videoLandscape = landscape; + if (mPlayer != null) { + mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); + } + if (landscape == 2) { Log.i(TAG, "还原9:16"); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); @@ -505,11 +219,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - /* RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = RelativeLayout.LayoutParams.MATCH_PARENT; params1.topMargin = 0; ry_view.setLayoutParams(params1); - ry_view.requestLayout();*/ + ry_view.requestLayout(); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = RelativeLayout.LayoutParams.MATCH_PARENT; params2.topMargin = 0; @@ -525,12 +239,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = vHeight; params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); params1.addRule(RelativeLayout.ALIGN_TOP); ry_view.setLayoutParams(params1); - ry_view.requestLayout();*/ + ry_view.requestLayout(); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = DpUtil.dp2px(270); params2.topMargin = DpUtil.dp2px(120); @@ -561,7 +275,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { */ @Override public void resumePlay() { - + if (!mPlayer.isPlaying()) { + new Handler(Looper.getMainLooper()) + .postDelayed(() -> { + mPlayer.replay(); + // ToastUtil.show("强制播放" + val); + }, 100); + } } /** @@ -575,6 +295,30 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { PLAY_MODEL = playModel; waitNextUrl = null; Log.i(TAG, "play" + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape" + videoLandscape); + if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { + mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); + if (landscape == VIDEO_VERTICAL && !isPk) { + url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); + } else if (landscape == VIDEO_HORIZONTAL || isPk) { + url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); + } + } else if (!url.contains(videoFps[0] + ".flv")) { + mPlayer.setViewResizeMode(false); + } + Log.e("purl121", url); + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + if (mPlayer.isPlaying()) { + mPlayer.stop(); + mPlayer.clearUrl(); + } + mPlayer.startUrl(url); purl = url; onPrepared(); } @@ -585,12 +329,14 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { PLAY_MODEL = playModel; Log.i(TAG, "switchStream: " + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape = " + videoLandscape + " ispk = " + isPk + " bean = " + roomModel.getEnterRoomInfo().getIsconnection()); if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { + mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); if (landscape == VIDEO_VERTICAL && !isPk) { url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); } else if (landscape == VIDEO_HORIZONTAL || isPk) { url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); } } else if (!url.contains(videoFps[0] + ".flv")) { + mPlayer.setViewResizeMode(false); } Log.e("purl121", url); @@ -602,6 +348,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { if (TextUtils.isEmpty(url) || mVideoView == null) { return; } + mPlayer.switchUrl(url); purl = url; } @@ -614,6 +361,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Log.i(TAG, "switchStreamPk: isPk1" + isPk + " tmp = " + !tmpPk + " isPk2 = " + this.isPk); if (this.isPk && tmpPk) return; if (isPk && !tmpPk || this.isPk) { + mPlayer.setViewResizeMode(false); String url; if (PLAY_MODEL != -1) { url = srcUrl.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); @@ -623,6 +371,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { if (!tmpPk) { waitNextUrl = url; } + mPlayer.switchUrl(srcUrl); tmpPk = true; } else if (!isPk) { tmpPk = false; @@ -633,12 +382,14 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } else { waitNextUrl = null; } + mPlayer.switchUrl(srcUrl); } } @Override public void clearFrame() { super.clearFrame(); + mPlayer.clearFrame(); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); params.height = ViewGroup.LayoutParams.WRAP_CONTENT; params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); @@ -646,12 +397,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - /* RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = ViewGroup.LayoutParams.WRAP_CONTENT; params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); params1.addRule(RelativeLayout.ALIGN_TOP); ry_view.setLayoutParams(params1); - ry_view.requestLayout();*/ + ry_view.requestLayout(); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = DpUtil.dp2px(270); params2.topMargin = DpUtil.dp2px(120); @@ -659,13 +410,31 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mCover.requestLayout(); } + @Override + public void endPk() { + + } + + @Override + public void endpk(String liveUid) { + + } + + @Override + public void initSwEngine(String liveUid) { + + } + @Override public void release() { mEnd = true; mStarted = false; + if (mPlayer != null) { + mPlayer.stop(); + mPlayer.release(); + } Bus.getOff(this); EventBus.getDefault().unregister(this); - //swAuManager.exitChannelAll(); L.e(TAG, "release------->"); } @@ -678,6 +447,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mCover.setVisibility(View.VISIBLE); } } + if (mPlayer != null) { + mPlayer.stop(); + } stopPlay2(); } @@ -690,14 +462,22 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void setViewUP(int i) { if (mVideoView == null) return; Log.e("PK状态", "" + i); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; + params.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); - - /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = vHeight; params1.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top); params1.addRule(RelativeLayout.ALIGN_TOP); - ry_view.requestLayout();*/ + ry_view.requestLayout(); isPk = true; + if (mPlayer.getUrl().contains("848_24.flv") || mPlayer.getUrl().contains("1280_24.flv")) { + tmpPk = false; + switchStreamPk(true); + } } /** @@ -714,6 +494,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } else { height = ViewGroup.LayoutParams.WRAP_CONTENT; } + mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); if (landscape == 2) { Log.i(TAG, "onPrepared:还原9:16 land=" + videoLandscape); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); @@ -723,11 +504,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = height; params1.topMargin = 0; ry_view.setLayoutParams(params1); - ry_view.requestLayout();*/ + ry_view.requestLayout(); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = height; params2.topMargin = 0; @@ -745,7 +526,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.setLayoutParams(params); mVideoView.requestLayout(); - /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); params1.height = height; params1.topMargin = 0; params1.addRule(RelativeLayout.ALIGN_TOP); @@ -753,7 +534,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); } ry_view.setLayoutParams(params1); - ry_view.requestLayout();*/ + ry_view.requestLayout(); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); params2.height = height; params2.topMargin = DpUtil.dp2px(120); @@ -802,6 +583,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { // } } + @Override + public void setDrMicInfo(UserBean u) { + + } public void removeDetailView() { // if (detailsView != null) { @@ -810,6 +595,16 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { // } } + @Override + public void setPkView(String liveUid) { + + } + + @Override + public void claerDrPkInfoView() { + + } + @Override public ViewGroup getSmallContainer() { return mSmallContainer; @@ -918,26 +713,15 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mVideoView.requestLayout(); } - boolean isShow = false; @Subscribe(threadMode = ThreadMode.MAIN) public void onUpdata(String str) { if ("UsertoRY".equals(str)) { - //todo 新增dis监听 - if (isShow) { - return; - } - isShow = true; - DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback2() { - @Override - public void onCancelClick() { - isShow = false; - } - + DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback() { @Override public void onConfirmClick(Dialog dialog, String content) { UsertoRY(); - isShow = false; + dialog = null; } }); @@ -950,39 +734,126 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { confirm = "accept"; cancel = "cancel"; } - DialogUitl.Builder builder = new DialogUitl.Builder(mContext).setContent(content).setTitle(mLiveBean.getUserNiceName()).setConfirmString(confirm).setCancelString(cancel).setView(R.layout.dialog_live_mic_invite).setClickCallback(new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - String[] permissions; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - permissions = new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.RECORD_AUDIO}; - } else { - permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}; - } - LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { + DialogUitl.Builder builder = new DialogUitl.Builder(mContext) + .setContent(content) + .setTitle(mLiveBean.getUserNiceName()) + .setConfirmString(confirm) + .setCancelString(cancel) + .setView(R.layout.dialog_live_mic_invite) + .setClickCallback(new DialogUitl.SimpleCallback() { @Override - public void run() { - // UsertoRY(); - //将自己设置成给主播,和主播连麦 - L.eSw("将自己设置成给主播,和主播连麦"); - joinLiveMic(); + public void onConfirmClick(Dialog dialog, String content) { + String[] permissions; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + permissions = new String[]{ + Manifest.permission.READ_MEDIA_IMAGES, + Manifest.permission.RECORD_AUDIO + }; + } else { + permissions = new String[]{ + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.RECORD_AUDIO + }; + } + LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { + @Override + public void run() { + UsertoRY(); + + } + }); } }); - } - }); builder.build().show(); } else if ("endMic".equals(str)) { - L.eSw("endMic.equals(str))" + str); - // 开始切换为观众身份 - //声网-将用户身份切换只观众 - endLiveMic(); + if (rcrtcRoom != null) { + // 开始切换为观众身份 + RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { + + /** + * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 + * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 + */ + @Override + public void onKicked() { + + } + + @Override + public void onSuccess() { + Log.e("ry", "下麦成功"); + // 该用户切换为观众成功,可以以观众身份进行音视频 + //退出rtc播放 + leaveRoom(); + } + + /** + * 当切换失败且不影响当前角色继续音视频时回调 + * @param errorCode 失败错误码 + */ + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "下麦失败" + errorCode); + leaveRoom(); + } + + private void leaveRoom() { + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + @Override + public void onSuccess() { + userJoinLinkMic = false; + Log.e("ry", "退出多人房间成功"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + if (WordUtil.isNewZh()) { + ToastUtil.show("已成功退出語音連麥"); + } else { + ToastUtil.show("You have successfully exited the voice connection"); + } + if (mPlayer.getNowPlayer() != null) { + mPlayer.play(); + Log.e("ry", mPlayer.isPlaying() + "purl" + purl); + if (!mPlayer.isPlaying()) { + mPlayer.switchUrl(purl); + } + ry_view.removeAllViews(); + ry_view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; + onPrepared(); + rcrtcRoom = null; + MicStatusManager.getInstance().clear(); + + resumePlay(); + } + + if (onMicCallback != null) { + onMicCallback.onMikUpdate(); + } + } + }); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", errorCode + "退出多人房间成功"); + userJoinLinkMic = false; + } + }); + + } + }); + } } else if ("Debug".equals(str)) { if (EasyFloat.isShow("Debug")) { EasyFloat.dismiss("Debug"); return; } - EasyFloat.with(mContext).setDragEnable(true).setTag("Debug").setLayout(debugView).show(); + EasyFloat.with(mContext) + .setDragEnable(true) + .setTag("Debug") + .setLayout(debugView) + .show(); } } @@ -1000,71 +871,79 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { break; } - LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR), ban, true); - new XPopup.Builder(mContext).setPopupCallback(new XPopupCallback() { - @Override - public void onCreated(BasePopupView popupView) { + LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, + IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR), + ban, + true); + new XPopup.Builder(mContext) + .setPopupCallback(new XPopupCallback() { + @Override + public void onCreated(BasePopupView popupView) { - } + } - @Override - public void beforeShow(BasePopupView popupView) { + @Override + public void beforeShow(BasePopupView popupView) { - } + } - @Override - public void onShow(BasePopupView popupView) { + @Override + public void onShow(BasePopupView popupView) { - } + } - @Override - public void onDismiss(BasePopupView popupView) { - int selectClarity = liveClarityCustomPopup.getSelectClarity(); - if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR)) - return; - if (selectClarity == PLAY_MODEL_ANCHOR) { - switchStream(srcUrl, PLAY_MODEL_DEF); - setAudiencePlayModel(selectClarity); - } else { - switchStream(srcUrl, selectClarity); - } - IMLoginManager.get(mContext).put(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, selectClarity); - showToast(); - } + @Override + public void onDismiss(BasePopupView popupView) { + int selectClarity = liveClarityCustomPopup.getSelectClarity(); + if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR)) + return; + if (selectClarity == PLAY_MODEL_ANCHOR) { + switchStream(srcUrl, PLAY_MODEL_DEF); + setAudiencePlayModel(selectClarity); + } else { + switchStream(srcUrl, selectClarity); + } + IMLoginManager.get(mContext).put(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, selectClarity); + showToast(); + } - private void showToast() { - if (WordUtil.isNewZh()) { - DialogUitl.showToast(mContext, "設置成功\n" + "正在為你轉換中", 3000); - } else { - DialogUitl.showToast(mContext, "successful\n" + "It's being converted for you", 3000); - } - } + private void showToast() { + if (WordUtil.isNewZh()) { + DialogUitl.showToast(mContext, "設置成功\n" + + "正在為你轉換中", 3000); + } else { + DialogUitl.showToast(mContext, "successful\n" + + "It's being converted for you", 3000); + } + } - @Override - public void beforeDismiss(BasePopupView popupView) { + @Override + public void beforeDismiss(BasePopupView popupView) { - } + } - @Override - public boolean onBackPressed(BasePopupView popupView) { - return false; - } + @Override + public boolean onBackPressed(BasePopupView popupView) { + return false; + } - @Override - public void onKeyBoardStateChanged(BasePopupView popupView, int height) { + @Override + public void onKeyBoardStateChanged(BasePopupView popupView, int height) { - } + } - @Override - public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { + @Override + public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { - } + } - @Override - public void onClickOutside(BasePopupView popupView) { + @Override + public void onClickOutside(BasePopupView popupView) { - } - }).asCustom(liveClarityCustomPopup).show(); + } + }) + .asCustom(liveClarityCustomPopup) + .show(); } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.FONT_SIZE) { int fount = 0; try { @@ -1075,17 +954,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { new LiveFontSizeSettingDialog(mContext, fount).setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(Integer bean, int position) { - EventBus.getDefault().post(new LiveAudienceEvent().setNums(bean).setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE)); + EventBus.getDefault().post(new LiveAudienceEvent() + .setNums(bean) + .setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE)); } }).showDialog(); - } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.PK_TWO_START) { - //将当前主播画面换个画布展示 - String pkUid = (String) event.getObject(); - setPkView(pkUid); - - } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_PK_END) { - String pkUid = (String) event.getObject(); - //endpk(pkUid); } } @@ -1094,17 +967,19 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { */ public List userinputStreamList = new ArrayList<>(); + public void UsertoRY() { userinputStreamList.clear(); Log.e("ry", "主播同意了UsertoRY"); if (userJoinLinkMic) {//已经在房间内,不再joinRoom直接去连麦 - //subscribeMic(rcrtcRoom); - joinLiveMic(); + subscribeMic(rcrtcRoom); return; } - /*RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() + RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO - .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO).setLiveRole(RCRTCLiveRole.AUDIENCE).build(); + .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) + .setLiveRole(RCRTCLiveRole.AUDIENCE) + .build(); RCRTCEngine.getInstance().joinRoom(LiveActivity.mLiveUid, roomConfig, new IRCRTCResultDataCallback() { @@ -1113,6 +988,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { userJoinLinkMic = true; rcrtcRoom = data; subscribeMic(data); + } @Override @@ -1137,7 +1013,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } - });*/ + }); } @@ -1153,7 +1029,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Log.i(TAG, "资源流 type: " + stream.getMediaType()); if (stream.getMediaType() == RCRTCMediaType.VIDEO) { //暂停播放 - + mPlayer.stop(); //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 @@ -1285,7 +1161,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { break; } // 示例代码使用480x640分辨率演示 - RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig.Builder.create() + RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig + .Builder.create() //设置分辨率 .setVideoResolution(rcrtcVideoResolution) //设置帧率 @@ -1293,7 +1170,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { //设置最小码率,480P下推荐200 .setMinRate(minRate) //设置最大码率,480P下推荐900 - .setMaxRate(maxRate).build(); + .setMaxRate(maxRate) + .build(); RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); // 创建视图渲染视图 // RCRTCVideoView videoView = new RCRTCVideoView(contexts); @@ -1351,7 +1229,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { ((RCRTCVideoInputStream) stream).setVideoFrameListener(new IRCRTCVideoInputFrameListener() { @Override public void onFrame(RCRTCRemoteVideoFrame videoFrame) { - String debugText = " 2、安卓主播开播, 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" + "rotation:" + videoFrame.getRotation() + "\n" + "timestampNs:" + videoFrame.getTimestampNs() + "\n" + "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n"; + String debugText = " 2、安卓主播开播, 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" + + "rotation:" + videoFrame.getRotation() + "\n" + + "timestampNs:" + videoFrame.getTimestampNs() + "\n" + + "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + + "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n"; //Log.d("ry", "onFrame: " + debugText); new Handler(Looper.getMainLooper()).post(() -> { debugView.setText(debugText); @@ -1381,12 +1263,14 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); audioManager.setSpeakerphoneOn(true); - HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm").params("roomid", LiveActivity.mLiveUid).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.e("ry", code + "热热热"); - } - }); + HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm") + .params("roomid", LiveActivity.mLiveUid) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.e("ry", code + "热热热"); + } + }); } @Override @@ -1421,12 +1305,16 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private void showLoadingDialog() { if (PLAY_MODEL == PLAY_MODEL_480) return; - new DialogUitl.Builder(mContext).setTitle("網絡提示").setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。").setView(R.layout.dialog_simple_tip).setClickCallback(new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - dialog.dismiss(); - } - }).build().show(); + new DialogUitl.Builder(mContext) + .setTitle("網絡提示") + .setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。") + .setView(R.layout.dialog_simple_tip) + .setClickCallback(new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + dialog.dismiss(); + } + }).build().show(); PLAY_MODEL = PLAY_MODEL_480; String url = srcUrl; if (videoLandscape == VIDEO_VERTICAL) { @@ -1434,6 +1322,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } else if (videoLandscape == VIDEO_HORIZONTAL) { url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); } + mPlayer.switchUrl(url); } private class ExoPlayerListener implements Player.Listener { @@ -1483,6 +1372,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { loadingListener.onPlayer(); } if (waitNextUrl != null) { + mPlayer.switchUrl(waitNextUrl); waitNextUrl = null; } } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java new file mode 100644 index 000000000..2dbe65889 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -0,0 +1,1504 @@ +package com.yunbao.live.views; + +import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; + +import android.Manifest; +import android.app.Activity; +import android.app.Dialog; +import android.content.Context; +import android.graphics.Color; +import android.media.AudioManager; +import android.os.Build; +import android.os.Handler; +import android.os.Looper; +import android.text.TextUtils; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.alibaba.fastjson.JSONObject; +import com.google.android.exoplayer2.PlaybackException; +import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.ui.StyledPlayerView; +import com.google.android.exoplayer2.video.VideoSize; +import com.google.gson.Gson; +import com.lxj.xpopup.XPopup; +import com.lxj.xpopup.core.BasePopupView; +import com.lxj.xpopup.interfaces.XPopupCallback; +import com.lzf.easyfloat.EasyFloat; +import com.lzy.okserver.OkDownload; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.bean.EnterRoomNewModel; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.dialog.LiveFontSizeSettingDialog; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.MicStatusManager; +import com.yunbao.common.utils.ScreenDimenUtil; +import com.yunbao.common.utils.SpUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.views.LiveClarityCustomPopup; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveActivity; +import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.bean.DrPkbean; +import com.yunbao.live.event.LiveAudienceEvent; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +import cn.rongcloud.rtc.api.RCRTCEngine; +import cn.rongcloud.rtc.api.RCRTCRemoteUser; +import cn.rongcloud.rtc.api.RCRTCRoom; +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; +import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleDataCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCVideoInputFrameListener; +import cn.rongcloud.rtc.api.stream.RCRTCInputStream; +import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; +import cn.rongcloud.rtc.api.stream.RCRTCOutputStream; +import cn.rongcloud.rtc.api.stream.RCRTCVideoInputStream; +import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; +import cn.rongcloud.rtc.api.stream.RCRTCVideoView; +import cn.rongcloud.rtc.base.RCRTCMediaType; +import cn.rongcloud.rtc.base.RCRTCParamsType; +import cn.rongcloud.rtc.base.RCRTCRemoteVideoFrame; +import cn.rongcloud.rtc.base.RCRTCStreamType; +import cn.rongcloud.rtc.base.RTCErrorCode; +import cn.rongcloud.rtc.core.RendererCommon; +import io.agora.beautyapi.faceunity.agora.SWAuManager; + +public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { + + private static final String TAG = "LivePlayViewHolder"; + private ViewGroup mRoot; + private ViewGroup mSmallContainer; + private ViewGroup mLeftContainer; + private ViewGroup mRightContainer; + private ViewGroup mPkContainer; + public StyledPlayerView mVideoView; + + private FrameLayout playFrameLayout; + private FrameLayout playFrameLayout1; + + private View mLoading, mLoading2; + private ImageView mCover; + private boolean mPaused;//是否切后台了 + private boolean mStarted;//是否开始了播放 + private boolean mEnd;//是否结束了播放 + public static ImageView leave; + + private boolean mPausedPlay;//是否被动暂停了播放 + public int landscape; //1h 2s + public Context contexts; + public FrameLayout ry_view; + + private static final int VIDEO_VERTICAL = 2; + private static final int VIDEO_HORIZONTAL = 1; + int videoLandscape = -1; // 视频方向,2=竖屏,1=横屏 + + static int vHeight;//视频高 + private TextView debugView; + //private LiveExoPlayerManager mPlayer; + private boolean isPk = false; + private boolean userJoinLinkMic = false;//用户是否已加入房间 + + //0未申请1申请中2连麦中 + RCRTCRoom rcrtcRoom; + String purl, srcUrl; + SWAuManager swAuManager; + String liveUid; + + private LinearLayout dr_pk_view; + private FrameLayout dr1_preview; + private FrameLayout dr2_preview; + private FrameLayout dr3_preview; + private FrameLayout dr4_preview; + + private View detailsView1, detailsView2, detailsView3, detailsView4; + private LinearLayout detailsLinearLayout1, detailsLinearLayout2, detailsLinearLayout3, detailsLinearLayout4; + private LinearLayout linearGrade1, linearGrade2, linearGrade3, linearGrade4; + private TextView textPkName1, textPkName2, textPkName3, textPkName4; + private TextView textGrade1, textGrade2, textGrade3, textGrade4; + private ImageView imageGrade1, imageGrade2, imageGrade3, imageGrade4; + + + public int getLandscape() { + return landscape; + } + + public LivePlaySwViewHolder(Context context, ViewGroup parentView, int landscapes) { + super(context, parentView); + contexts = context; + landscape = landscapes; + Log.i("收收收", landscape + ""); + L.eSw("liveUid:" + liveUid); + } + + @Override + protected int getLayoutId() { + return R.layout.view_live_play_sw; + } + + @Override + public void init() { + Log.i(TAG, "init: 初始化播放器ViewHolder"); + EventBus.getDefault().register(this); + Bus.getOn(this); + mRoot = (ViewGroup) findViewById(R.id.root); + playFrameLayout = (FrameLayout) findViewById(R.id.playView); + playFrameLayout1 = (FrameLayout) findViewById(R.id.playView1); + mSmallContainer = (ViewGroup) findViewById(R.id.small_container); + mLeftContainer = (ViewGroup) findViewById(R.id.left_container); + mRightContainer = (ViewGroup) findViewById(R.id.right_container); + mPkContainer = (FrameLayout) findViewById(R.id.pk_container); + mVideoView = (StyledPlayerView) findViewById(R.id.video_view); + ry_view = (FrameLayout) findViewById(R.id.ry_view); + leave = (ImageView) findViewById(R.id.leave); + mLoading = findViewById(R.id.loading); + mLoading2 = findViewById(R.id.loading2); + mCover = (ImageView) findViewById(R.id.cover); + ScreenDimenUtil util = ScreenDimenUtil.getInstance(); + int mScreenWdith = util.getScreenWdith(); + vHeight = mScreenWdith * 720 / 960; + + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mPkContainer.getLayoutParams(); + params.height = vHeight; + mPkContainer.requestLayout(); + + debugView = new TextView(mContext); + debugView.setBackgroundColor(Color.WHITE); + + dr_pk_view = (LinearLayout) findViewById(R.id.dr_pk_view); + dr1_preview = (FrameLayout) findViewById(R.id.dr1_preview); + dr2_preview = (FrameLayout) findViewById(R.id.dr2_preview); + dr3_preview = (FrameLayout) findViewById(R.id.dr3_preview); + dr4_preview = (FrameLayout) findViewById(R.id.dr4_preview); + dr_pk_view.setVisibility(View.GONE); + } + + public void initSwEngine(String liveUid) { + this.liveUid = liveUid; + //初始化声网SDK + swAuManager = SWAuManager.get(); + swAuManager.setAudienceContainer(ry_view); + swAuManager.initRtcEngine((Activity) mContext); + swAuManager.setupRemoteVideo(Integer.parseInt(liveUid)); + //进入主播房间 + swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); + } + + /** + * 开启单人PK + * + * @param Uid + */ + public void setPkView(String Uid) { + L.eSw("setPkView Uid " + Uid); + mPkContainer.setVisibility(View.VISIBLE); + swAuManager.updateMyChannelView((FrameLayout) mLeftContainer, Integer.parseInt(liveUid)); + ry_view.removeAllViews(); + //加入对方主播房间 + swAuManager.setPkContainer1((FrameLayout) mRightContainer); + swAuManager.joinExRoomEx(Integer.parseInt(Uid), CommonAppConfig.SWToken, SWAuManager.getChannelName(Uid)); + } + + List drMicUserList = new ArrayList<>(); + + boolean isAdd = true; + + @Override + public void setDrMicInfo(UserBean u) { + isAdd = true; + L.eSw("setDrMicInfo:-----------------" + u.getId() + " drMicUserList" + new Gson().toJson(drMicUserList)); + for (int i = 0; i < drMicUserList.size(); i++) { + if (u.getId().equals(drMicUserList.get(i).getId()) || u.getId().equals(liveUid)) { + isAdd = false; + } + } + L.eSw("setDrMicInfo:---------------isAdd--" + isAdd); + //加载多人PK(连麦)主播视图 + if (isAdd) { + dr_pk_view.setVisibility(View.VISIBLE); + drMicUserList.add(u); + if (drMicUserList.size() == 1) { + L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 1"); + ry_view.removeAllViews(); + swAuManager.updateMyChannelView((FrameLayout) dr1_preview, Integer.parseInt(liveUid)); + swAuManager.joinChannelDrEx(dr2_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); + dr1_preview.setVisibility(View.VISIBLE); + dr2_preview.setVisibility(View.VISIBLE); + dr3_preview.setVisibility(View.GONE); + dr4_preview.setVisibility(View.GONE); + } else if (drMicUserList.size() == 2) { + L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 2"); + dr4_preview.setVisibility(View.VISIBLE); + swAuManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); + } else if (drMicUserList.size() == 3) { + L.eSw("setDrMicInfo:-----------------drMicUserList.size() == 3"); + dr4_preview.setVisibility(View.VISIBLE); + dr3_preview.setVisibility(View.VISIBLE); + swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drMicUserList.get(1).getId()); + swAuManager.joinChannelDrEx(dr3_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drMicUserList.get(1).getId(), SWAuManager.getChannelName(drMicUserList.get(1).getId())); + swAuManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drMicUserList.get(2).getId(), SWAuManager.getChannelName(drMicUserList.get(2).getId())); + } + } + + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", liveUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + List drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (liveUid.equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; + } + } + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); + } + setDrPkView(drPkbeans); + } + } + }); + } + + public void claerDrPkInfoView() { + if (detailsView1 != null) { + dr1_preview.removeView(detailsView1); + } + if (detailsView2 != null) { + dr2_preview.removeView(detailsView2); + } + if (detailsView3 != null) { + dr3_preview.removeView(detailsView3); + } + if (detailsView4 != null) { + dr4_preview.removeView(detailsView4); + } + } + + public void setDrPkView(List drPkbeanList) { + if (detailsView1 != null) { + dr1_preview.removeView(detailsView1); + } + + /*new Handler().postDelayed(new Runnable() { + @Override + public void run() { + + detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); + linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); + imageGrade1 = detailsView1.findViewById(R.id.image_grade1); + textGrade1 = detailsView1.findViewById(R.id.text_grade1); + textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); + imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); + dr1_preview.addView(detailsView1); + detailsLinearLayout1.setVisibility(View.VISIBLE); + linearGrade1.setVisibility(View.GONE); + + for (int j = 0; j < drPkbeanList.size(); j++) { + if (j == 0) { + L.eSw("j == 0:" + j); + //设置多人PK数据 + if (detailsView2 != null) { + dr2_preview.removeView(detailsView2); + } + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(String.valueOf(drPkbeanList.get(0).getId())); + textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); + dr2_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.GONE); + } else if (j == 1) { + L.eSw("j == 1:" + j); + if (detailsView4 != null) { + dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(String.valueOf(drPkbeanList.get(1).getId())); + textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); + dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.GONE); + } else if (j == 2) { + L.eSw("j == 2:" + j); + + if (detailsView4 != null) { + dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(String.valueOf(drPkbeanList.get(2).getId())); + textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); + dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.VISIBLE); + linearGrade4.setVisibility(View.GONE); + + if (detailsView3 != null) { + dr3_preview.removeView(detailsView3); + } + detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); + linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); + textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); + imageGrade3 = detailsView3.findViewById(R.id.image_grade3); + textGrade3 = detailsView3.findViewById(R.id.text_grade3); + imageGrade3.setTag(String.valueOf(drPkbeanList.get(1).getId())); + textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); + dr3_preview.addView(detailsView3); + detailsLinearLayout3.setVisibility(View.VISIBLE); + linearGrade3.setVisibility(View.GONE); + } + } + } + }, 2000);*/ + } + + + /** + * 退出单人pk + * + * @param pkUid + */ + public void endpk(String pkUid) { + L.eSw("endpk " + pkUid); + mPkContainer.setVisibility(View.GONE); + swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), SWAuManager.getChannelName(pkUid)); + swAuManager.updateMyChannelView(ry_view, Integer.parseInt(liveUid)); + ry_view.setVisibility(View.VISIBLE); + mLeftContainer.removeAllViews(); + mRightContainer.removeAllViews(); + } + + /** + * 退出所有连麦主播的房間 + */ + public void endPk() { + dr_pk_view.setVisibility(View.GONE); + dr1_preview.setVisibility(View.GONE); + dr2_preview.setVisibility(View.GONE); + dr3_preview.setVisibility(View.GONE); + dr4_preview.setVisibility(View.GONE); + dr1_preview.removeAllViews(); + dr2_preview.removeAllViews(); + dr3_preview.removeAllViews(); + dr4_preview.removeAllViews(); + //退出所有连麦主播的房間 + for (int i = 0; i < drMicUserList.size(); i++) { + swAuManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drMicUserList.get(i).getId()); + } + drMicUserList = new ArrayList<>(); + //將當前主播畫面放大 + swAuManager.updateMyChannelView((FrameLayout) ry_view, Integer.parseInt(liveUid)); + } + + /** + * 将用户设置成主播,与主播连麦 + */ + private void joinLiveMic() { + L.eSw("joinLiveMic"); + HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm").params("roomid", LiveActivity.mLiveUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.e("ry", code + "热热热"); + if (code == 0) { + swAuManager.setMicAn(true); + } + } + }); + } + + private void endLiveMic() { + L.eSw("endLiveMic"); + swAuManager.setMicAn(false); + } + + @Override + public void hideCover() { +// if (mCover != null) { +// if (mCover.getVisibility()==View.VISIBLE){ +//// new Handler().postDelayed(new Runnable() { +//// @Override +//// public void run() { +//// +//// } +//// },200); +// mCover.setVisibility(View.GONE); +// mLoading2.setVisibility(View.GONE); +// } +// +// +// } + } + + @Override + public void setCover(String coverUrl) { +// if (mCover != null) { +// mCover.setVisibility(View.VISIBLE); +// mLoading2.setVisibility(View.VISIBLE); +// ImgLoader.displayBlurLive(mContext, coverUrl, mCover, 400, 600); +// +// } + }// + + @Override + public synchronized void setLiveBeanLandscape(int landscape) { +// landscape=1; + Log.i(TAG, "setLiveBeanLandscape: " + landscape + " isPk: " + isPk); + this.landscape = landscape; + this.videoLandscape = landscape; + if (landscape == 2) { + Log.i(TAG, "还原9:16"); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = RelativeLayout.LayoutParams.MATCH_PARENT; + params.topMargin = 0; + mVideoView.setLayoutParams(params); + mVideoView.requestLayout(); + + /* RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = RelativeLayout.LayoutParams.MATCH_PARENT; + params1.topMargin = 0; + ry_view.setLayoutParams(params1); + ry_view.requestLayout();*/ + RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params2.height = RelativeLayout.LayoutParams.MATCH_PARENT; + params2.topMargin = 0; + mCover.setLayoutParams(params2); + mCover.requestLayout(); + + } else { + Log.i(TAG, "还原16:9"); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.setLayoutParams(params); + mVideoView.requestLayout(); + + /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = vHeight; + params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params1.addRule(RelativeLayout.ALIGN_TOP); + ry_view.setLayoutParams(params1); + ry_view.requestLayout();*/ + RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params2.height = DpUtil.dp2px(270); + params2.topMargin = DpUtil.dp2px(120); + mCover.setLayoutParams(params2); + mCover.requestLayout(); + } + } + + @Override + public void setLiveEnterRoomNewModel(EnterRoomNewModel data) { + super.setLiveEnterRoomNewModel(data); + isPk = data.getEnterRoomInfo().getIsconnection().equals("1"); + if (isPk) { + setLiveBeanLandscape(1); + } + } + + /** + * 暂停播放 + */ + @Override + public void pausePlay() { + + } + + /** + * 暂停播放后恢复 + */ + @Override + public void resumePlay() { + + } + + /** + * 开始播放 + * + * @param url 流地址 + */ + @Override + public void play(String url, int playModel) { + srcUrl = url; + PLAY_MODEL = playModel; + waitNextUrl = null; + Log.i(TAG, "play" + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape" + videoLandscape); + purl = url; + onPrepared(); + } + + @Override + public void switchStream(String url, int playModel) { + srcUrl = url; + PLAY_MODEL = playModel; + Log.i(TAG, "switchStream: " + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape = " + videoLandscape + " ispk = " + isPk + " bean = " + roomModel.getEnterRoomInfo().getIsconnection()); + if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { + if (landscape == VIDEO_VERTICAL && !isPk) { + url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); + } else if (landscape == VIDEO_HORIZONTAL || isPk) { + url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); + } + } else if (!url.contains(videoFps[0] + ".flv")) { + } + Log.e("purl121", url); + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + purl = url; + } + + boolean tmpPk = false; + String waitNextUrl = null; + + @Override + public void switchStreamPk(boolean isPk) { + super.switchStreamPk(isPk); + Log.i(TAG, "switchStreamPk: isPk1" + isPk + " tmp = " + !tmpPk + " isPk2 = " + this.isPk); + if (this.isPk && tmpPk) return; + if (isPk && !tmpPk || this.isPk) { + String url; + if (PLAY_MODEL != -1) { + url = srcUrl.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); + } else { + url = srcUrl.replace(".flv", videoRatioHorizontal[1] + videoFps[0] + ".flv"); + } + if (!tmpPk) { + waitNextUrl = url; + } + tmpPk = true; + } else if (!isPk) { + tmpPk = false; + if (landscape == VIDEO_VERTICAL && PLAY_MODEL != -1) { + waitNextUrl = srcUrl.replace(".flv", videoRatioVertical[PLAY_MODEL] + videoFps[0] + ".flv"); + } else if (landscape == VIDEO_HORIZONTAL && PLAY_MODEL != -1) { + waitNextUrl = srcUrl.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); + } else { + waitNextUrl = null; + } + } + } + + @Override + public void clearFrame() { + super.clearFrame(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = ViewGroup.LayoutParams.WRAP_CONTENT; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.setLayoutParams(params); + mVideoView.requestLayout(); + + /* RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = ViewGroup.LayoutParams.WRAP_CONTENT; + params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params1.addRule(RelativeLayout.ALIGN_TOP); + ry_view.setLayoutParams(params1); + ry_view.requestLayout();*/ + RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params2.height = DpUtil.dp2px(270); + params2.topMargin = DpUtil.dp2px(120); + mCover.setLayoutParams(params2); + mCover.requestLayout(); + } + + @Override + public void release() { + mEnd = true; + mStarted = false; + Bus.getOff(this); + EventBus.getDefault().unregister(this); + //swAuManager.exitChannelAll(); + L.e(TAG, "release------->"); + } + + @Override + public void stopPlay() { + Log.i(TAG, "stopPlay: "); + if (mCover != null) { + mCover.setAlpha(1f); + if (mCover.getVisibility() != View.VISIBLE) { + mCover.setVisibility(View.VISIBLE); + } + } + stopPlay2(); + } + + @Override + public void stopPlay2() { + + } + + @Override + public void setViewUP(int i) { + if (mVideoView == null) return; + Log.e("PK状态", "" + i); + + + /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = vHeight; + params1.topMargin = contexts.getResources().getDimensionPixelOffset(R.dimen.live_top); + params1.addRule(RelativeLayout.ALIGN_TOP); + ry_view.requestLayout();*/ + isPk = true; + } + + /** + * 播放开始 + */ + public void onPrepared() { + if (mEnd) { + release(); + return; + } + int height; + if (videoLandscape == VIDEO_VERTICAL) { + height = ViewGroup.LayoutParams.MATCH_PARENT; + } else { + height = ViewGroup.LayoutParams.WRAP_CONTENT; + } + if (landscape == 2) { + Log.i(TAG, "onPrepared:还原9:16 land=" + videoLandscape); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = height; + params.topMargin = 0; + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.setLayoutParams(params); + mVideoView.requestLayout(); + + /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = height; + params1.topMargin = 0; + ry_view.setLayoutParams(params1); + ry_view.requestLayout();*/ + RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params2.height = height; + params2.topMargin = 0; + mCover.setLayoutParams(params2); + mCover.requestLayout(); + } else { + Log.i(TAG, "onPrepared:还原16:9"); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = height; + params.topMargin = 0; + if (videoLandscape == VIDEO_HORIZONTAL) { + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + } + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.setLayoutParams(params); + mVideoView.requestLayout(); + + /*RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams(); + params1.height = height; + params1.topMargin = 0; + params1.addRule(RelativeLayout.ALIGN_TOP); + if (videoLandscape == VIDEO_HORIZONTAL) { + params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + } + ry_view.setLayoutParams(params1); + ry_view.requestLayout();*/ + RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params2.height = height; + params2.topMargin = DpUtil.dp2px(120); + mCover.setLayoutParams(params2); + mCover.requestLayout(); + } + } + + @Override + public void setPkview() { + Log.i("收到socket--->", "变成16:9"); + String url = srcUrl; + isPk = true; + switchStreamPk(true); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + } + + @Override + public synchronized void setPkEndview() { + + Log.i("收收收", landscape + ""); + isPk = false; + tmpPk = false; + switchStreamPk(false); + if (landscape == 2) { + Log.i("收到socket--->", "还原9:16"); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = RelativeLayout.LayoutParams.MATCH_PARENT; + params.topMargin = 0; + mVideoView.requestLayout(); + + } else { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + } +// if (detailsView != null) { +// mVideoView.removeView(detailsView); +// detailsView = null; +// } + } + + + public void removeDetailView() { +// if (detailsView != null) { +// mVideoView.removeView(detailsView); +// detailsView = null; +// } + } + + @Override + public ViewGroup getSmallContainer() { + return mSmallContainer; + } + + + @Override + public ViewGroup getRightContainer() { + return mRightContainer; + } + + @Override + public ViewGroup getPkContainer() { + return mPkContainer; + } + + @Override + public void changeToLeft() { + if (mVideoView != null) { + + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; +// params.height = mContext.getResources().getDimensionPixelOffset(R.dimen.live_view); + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + + } + if (mLoading != null && mLeftContainer != null) { + ViewParent viewParent = mLoading.getParent(); + if (viewParent != null) { + ((ViewGroup) viewParent).removeView(mLoading); + } + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); + params.gravity = Gravity.CENTER; + mLoading.setLayoutParams(params); + mLeftContainer.addView(mLoading); + } + } + + @Override + public void changeToBig() { + if (mVideoView != null) { + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + mVideoView.setLayoutParams(params); + + } + if (mLoading != null && mRoot != null) { + ViewParent viewParent = mLoading.getParent(); + if (viewParent != null) { + ((ViewGroup) viewParent).removeView(mLoading); + } + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); + params.addRule(RelativeLayout.CENTER_IN_PARENT); + mLoading.setLayoutParams(params); + mRoot.addView(mLoading); + } + } + + @Override + public void onResume() { + if (!mPausedPlay && mPaused && mVideoView != null) { +// mVideoView.runInForeground(); +// mVideoView.start(); + } + mPaused = false; +// if (mPlayer.isPlaying() == 1) { +// mPlayer.resumeVideo(); +// mPlayer.resumeAudio(); +// } + } + + @Override + public void onPause() { +// if (!mPausedPlay && mVideoView != null) { +// mVideoView.runInBackground(false); +// } +// mPaused = true; +// mPlayer.pauseVideo(); +// mPlayer.pauseAudio(); + } + + @Override + public void onDestroy() { + release(); + } + + //全屏 + @Override + public void fullScreen() { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = RelativeLayout.LayoutParams.MATCH_PARENT; + params.topMargin = 0; + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + } + + //小屏 + @Override + public void smallScreen() { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); + params.height = vHeight; + params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); + // mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation0); + params.addRule(RelativeLayout.ALIGN_TOP); + mVideoView.requestLayout(); + } + + boolean isShow = false; + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onUpdata(String str) { + if ("UsertoRY".equals(str)) { + //todo 新增dis监听 + if (isShow) { + return; + } + isShow = true; + DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback2() { + @Override + public void onCancelClick() { + isShow = false; + } + + @Override + public void onConfirmClick(Dialog dialog, String content) { + UsertoRY(); + isShow = false; + } + }); + + } else if ("inviteMic".equals(str)) { + String content = "邀請您進行語音連麥"; + String confirm = "接受"; + String cancel = "拒絕"; + if (!WordUtil.isNewZh()) { + content = "You are invited to join the voice connection"; + confirm = "accept"; + cancel = "cancel"; + } + DialogUitl.Builder builder = new DialogUitl.Builder(mContext).setContent(content).setTitle(mLiveBean.getUserNiceName()).setConfirmString(confirm).setCancelString(cancel).setView(R.layout.dialog_live_mic_invite).setClickCallback(new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + String[] permissions; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + permissions = new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.RECORD_AUDIO}; + } else { + permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}; + } + LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { + @Override + public void run() { + // UsertoRY(); + //将自己设置成给主播,和主播连麦 + L.eSw("将自己设置成给主播,和主播连麦"); + joinLiveMic(); + } + }); + } + }); + builder.build().show(); + + } else if ("endMic".equals(str)) { + L.eSw("endMic.equals(str))" + str); + // 开始切换为观众身份 + //声网-将用户身份切换只观众 + endLiveMic(); + } else if ("Debug".equals(str)) { + if (EasyFloat.isShow("Debug")) { + EasyFloat.dismiss("Debug"); + return; + } + EasyFloat.with(mContext).setDragEnable(true).setTag("Debug").setLayout(debugView).show(); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onOpenDrawer(LiveAudienceEvent event) { + if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO) { + int ban = 0;//全模式都可以选择 + switch (roomModel.getClarityType() - 1) { + case PLAY_MODEL_720://仅允许720(高清),ban掉1080(超高清)模式 + ban = LiveClarityCustomPopup.BAN_1080; + break; + case -1://没有该字段 + case PLAY_MODEL_480://仅允许480(流畅),ban掉1080(超高清)和720(高清)模式 + ban = LiveClarityCustomPopup.BAN_720; + break; + + } + LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR), ban, true); + new XPopup.Builder(mContext).setPopupCallback(new XPopupCallback() { + @Override + public void onCreated(BasePopupView popupView) { + + } + + @Override + public void beforeShow(BasePopupView popupView) { + + } + + @Override + public void onShow(BasePopupView popupView) { + + } + + @Override + public void onDismiss(BasePopupView popupView) { + int selectClarity = liveClarityCustomPopup.getSelectClarity(); + if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR)) + return; + if (selectClarity == PLAY_MODEL_ANCHOR) { + switchStream(srcUrl, PLAY_MODEL_DEF); + setAudiencePlayModel(selectClarity); + } else { + switchStream(srcUrl, selectClarity); + } + IMLoginManager.get(mContext).put(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, selectClarity); + showToast(); + } + + private void showToast() { + if (WordUtil.isNewZh()) { + DialogUitl.showToast(mContext, "設置成功\n" + "正在為你轉換中", 3000); + } else { + DialogUitl.showToast(mContext, "successful\n" + "It's being converted for you", 3000); + } + } + + @Override + public void beforeDismiss(BasePopupView popupView) { + + } + + @Override + public boolean onBackPressed(BasePopupView popupView) { + return false; + } + + @Override + public void onKeyBoardStateChanged(BasePopupView popupView, int height) { + + } + + @Override + public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { + + } + + @Override + public void onClickOutside(BasePopupView popupView) { + + } + }).asCustom(liveClarityCustomPopup).show(); + } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.FONT_SIZE) { + int fount = 0; + try { + fount = Integer.parseInt(SpUtil.getStringValue("pd_live_room_fount_size")); + } catch (Exception ignored) { + + } + new LiveFontSizeSettingDialog(mContext, fount).setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(Integer bean, int position) { + EventBus.getDefault().post(new LiveAudienceEvent().setNums(bean).setType(LiveAudienceEvent.LiveAudienceType.LIVE_FONT_SIZE)); + } + }).showDialog(); + } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.PK_TWO_START) { + //将当前主播画面换个画布展示 + String pkUid = (String) event.getObject(); + setPkView(pkUid); + + } else if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_PK_END) { + String pkUid = (String) event.getObject(); + //endpk(pkUid); + } + } + + /** + * 把观众转换成主播 + */ + public List userinputStreamList = new ArrayList<>(); + + public void UsertoRY() { + userinputStreamList.clear(); + Log.e("ry", "主播同意了UsertoRY"); + if (userJoinLinkMic) {//已经在房间内,不再joinRoom直接去连麦 + //subscribeMic(rcrtcRoom); + joinLiveMic(); + return; + } + /*RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() + // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO + .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO).setLiveRole(RCRTCLiveRole.AUDIENCE).build(); + RCRTCEngine.getInstance().joinRoom(LiveActivity.mLiveUid, roomConfig, new IRCRTCResultDataCallback() { + + + @Override + public void onSuccess(RCRTCRoom data) { + userJoinLinkMic = true; + rcrtcRoom = data; + subscribeMic(data); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", LiveActivity.mLiveUid + errorCode + ""); + if (errorCode.getValue() == 50007) {//userJoinLinkMic可能失效,直接leaveRoom + userJoinLinkMic = false; + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + UsertoRY(); + } + }); + } else { + ToastUtil.show("房间失败" + errorCode); + } + + } + });*/ + + + } + + private void subscribeMic(RCRTCRoom data) { + runOnUiThread(new Runnable() { + @Override + public void run() { + RCRTCEngine.getInstance().enableSpeaker(true); + //遍历远端用户发布的资源列表 + Log.i(TAG, "软件资源数量:" + data.getLiveStreams().size()); + for (RCRTCInputStream stream : data.getLiveStreams()) { + Log.i(TAG, "资源流 type: " + stream.getMediaType()); + if (stream.getMediaType() == RCRTCMediaType.VIDEO) { + //暂停播放 + + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT); + ry_view.addView(remoteView); + Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + data.getLiveStreams().size()); + } + userinputStreamList.add(stream); + } + rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList, new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", userinputStreamList.size() + LiveActivity.mLiveUid + "订阅失败" + errorCode.toString()); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + + @Override + public void onSuccess() { + Log.e("ry", "订阅资源成功"); +// new Handler().postDelayed(new Runnable() { +// @Override +// public void run() { + toMic(); +// } +// }, 3000); + + } + }); + } + }); + } + + /** + * 主房间事件监听 + * 详细说明请参考文档:https://www.rongcloud.cn/docs/api/android/rtclib_v4/cn/rongcloud/rtc/api/callback/IRCRTCRoomEventsListener.html + */ + public IRCRTCRoomEventsListener roomEventsListener = new IRCRTCRoomEventsListener() { + @Override + public void onRemoteUserPublishResource(RCRTCRemoteUser rcrtcRemoteUser, List list) { + Log.e("ry", "远端来了" + list.size()); + //TODO 按需在此订阅远端用户发布的资源 + rcrtcRoom.getLocalUser().subscribeStreams(list, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "远端成功" + list.size()); + + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", "远端失败" + list.size()); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + }); + } + + @Override + public void onRemoteUserMuteAudio(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { + + } + + @Override + public void onRemoteUserMuteVideo(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { + + } + + @Override + public void onRemoteUserUnpublishResource(RCRTCRemoteUser remoteUser, List streams) { + + } + + @Override + public void onUserJoined(RCRTCRemoteUser remoteUser) { + + } + + @Override + public void onUserLeft(RCRTCRemoteUser remoteUser) { + + } + + @Override + public void onUserOffline(RCRTCRemoteUser remoteUser) { + + } + + @Override + public void onPublishLiveStreams(List streams) { + + } + + @Override + public void onUnpublishLiveStreams(List streams) { + + } + }; + + + public List userinputStreamList1 = new ArrayList<>(); + public List userinputStreamList2 = new ArrayList<>(); + + public void toMic() { + RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC, RCRTCParamsType.AudioScenario.MUSIC_CLASSROOM); + userinputStreamList1.clear(); + userinputStreamList2.clear(); + RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; + int minRate = 200; + int maxRate = 900; + switch (IMLoginManager.get(mContext).getSelectClarity()) { + case 0: + rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; + minRate = landscape == 1 ? 900 : 200; + maxRate = landscape == 1 ? 700 : 900; + break; + case 1: + rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; + minRate = landscape == 1 ? 900 : 250; + maxRate = landscape == 1 ? 700 : 2200; + break; + case 2: + rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; + minRate = landscape == 1 ? 900 : 400; + maxRate = landscape == 1 ? 700 : 4000; + break; + } + // 示例代码使用480x640分辨率演示 + RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig.Builder.create() + //设置分辨率 + .setVideoResolution(rcrtcVideoResolution) + //设置帧率 + .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_24) + //设置最小码率,480P下推荐200 + .setMinRate(minRate) + //设置最大码率,480P下推荐900 + .setMaxRate(maxRate).build(); + RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); +// 创建视图渲染视图 +// RCRTCVideoView videoView = new RCRTCVideoView(contexts); +// RCRTCEngine.getInstance().getDefaultVideoStream().setVideoView(videoView); +//TODO 示例代码使用获取本地默认视频流、音频流演示 + ArrayList streams = new ArrayList<>(); +// streams.add(RCRTCEngine.getInstance().getDefaultVideoStream()); + streams.add(RCRTCEngine.getInstance().getDefaultAudioStream()); + if (landscape == 1) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + setLiveBeanLandscape(1); + } + }); + + } +// 开启摄像头 +// RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(null); +// 开始切换为主播身份 + RCRTCEngine.getInstance().getRoom().getLocalUser().switchToBroadcaster(streams, new IRCRTCSwitchRoleDataCallback() { + /** + * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 + * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 + */ + @Override + public void onKicked() { + Log.e("ry", "切换onKicked"); + + } + + @Override + public void onSuccess(RCRTCLiveInfo data) { + rcrtcRoom.registerRoomListener(roomEventsListener); + //该用户切换为主播成功,可以以主播身份进行音视频 + Log.e("ry", "切换成功"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + if (onMicCallback != null) { + onMicCallback.onMikUpdate(); + } + //遍历远端用户列表 + for (int i = 0; i < rcrtcRoom.getRemoteUsers().size(); i++) { + Log.e("ry", rcrtcRoom.getRemoteUsers().get(i).getUserId() + "收到rcrtcOtherRoom" + rcrtcRoom.getRemoteUsers().size()); + //遍历远端用户发布的资源列表 + for (RCRTCInputStream stream : rcrtcRoom.getRemoteUsers().get(i).getStreams()) { + Log.e("ry", i + "收到" + stream.getMediaType() + "实打实打算" + rcrtcRoom.getRemoteUsers().get(i).getUserId()); + if (stream.getMediaType() == RCRTCMediaType.VIDEO) { + if (userinputStreamList1.size() == 0) { + + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setStreamType(RCRTCStreamType.NORMAL); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + ((RCRTCVideoInputStream) stream).setVideoFrameListener(new IRCRTCVideoInputFrameListener() { + @Override + public void onFrame(RCRTCRemoteVideoFrame videoFrame) { + String debugText = " 2、安卓主播开播, 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" + "rotation:" + videoFrame.getRotation() + "\n" + "timestampNs:" + videoFrame.getTimestampNs() + "\n" + "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n"; + //Log.d("ry", "onFrame: " + debugText); + new Handler(Looper.getMainLooper()).post(() -> { + debugView.setText(debugText); + + }); + } + }); + //todo 本demo只演示添加1个远端用户的视图 + ry_view.removeAllViews(); + remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL); + ry_view.addView(remoteView); + } + userinputStreamList1.add(stream); + } + userinputStreamList2.add(stream); + } + } + //开始订阅资源 + rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList2, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "订阅资源成功"); + MicStatusManager.getInstance().setMicData(MicStatusManager.MIC_TYPE_OPEN, LiveActivity.mLiveUid); + AudioManager audioManager = (AudioManager) contexts.getSystemService(Context.AUDIO_SERVICE); + RCRTCEngine.getInstance().enableSpeaker(true); + audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); + audioManager.setSpeakerphoneOn(true); + + HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm").params("roomid", LiveActivity.mLiveUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.e("ry", code + "热热热"); + } + }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", "订阅资源失败: " + rtcErrorCode.getReason()); + ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); + } + }); + } + }); + + + } + + /** + * 当切换失败且不影响当前角色继续音视频时回调 + * @param errorCode 失败错误码 + */ + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", errorCode + "切换失败"); + + } + }); + } + + @Override + public void setLoadViewListener(LoadingListener listener) { + super.setLoadViewListener(listener); + } + + private void showLoadingDialog() { + if (PLAY_MODEL == PLAY_MODEL_480) return; + + new DialogUitl.Builder(mContext).setTitle("網絡提示").setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。").setView(R.layout.dialog_simple_tip).setClickCallback(new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + dialog.dismiss(); + } + }).build().show(); + PLAY_MODEL = PLAY_MODEL_480; + String url = srcUrl; + if (videoLandscape == VIDEO_VERTICAL) { + url = url.replace(".flv", videoRatioVertical[PLAY_MODEL_480] + videoFps[0] + ".flv"); + } else if (videoLandscape == VIDEO_HORIZONTAL) { + url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); + } + } + + private class ExoPlayerListener implements Player.Listener { + String TAG = "播放流"; + + @Override + public void onPlayerError(PlaybackException error) { + Player.Listener.super.onPlayerError(error); + debugView.setText("播放出错code=" + error.errorCode + " msg=" + error.getErrorCodeName()); + } + + @Override + public void onVideoSizeChanged(VideoSize videoSize) { + Player.Listener.super.onVideoSizeChanged(videoSize); + Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height); + //ToastUtil.show("分辨率: 宽 = " + videoSize.width + " 高 = " + videoSize.height); + if (videoSize.height > videoSize.width) { + videoLandscape = VIDEO_VERTICAL; + } else { + videoLandscape = VIDEO_HORIZONTAL; + } + } + + @Override + public void onPlaybackStateChanged(int playbackState) { + Player.Listener.super.onPlaybackStateChanged(playbackState); + if (playbackState == Player.STATE_BUFFERING) { + //showLoadingDialog(); + mLoading.setVisibility(View.VISIBLE); + OkDownload.getInstance().pauseAll(); + Log.i(TAG, "onPlaybackStateChanged: 缓存中"); + } else { + mLoading.setVisibility(View.INVISIBLE); + Log.i(TAG, "onPlaybackStateChanged: 播放中"); + } + } + + @Override + public void onIsPlayingChanged(boolean isPlaying) { + Player.Listener.super.onIsPlayingChanged(isPlaying); + if (isPlaying) { + hideCover(); + mLoading.setVisibility(View.INVISIBLE); + Log.i(TAG, "onIsPlayingChanged: 开始播放 | waitNextUrl = " + waitNextUrl); + OkDownload.getInstance().startAll(); + if (loadingListener != null) { + loadingListener.onPlayer(); + } + if (waitNextUrl != null) { + waitNextUrl = null; + } + } + } + } + + private int mPkTimeCount = 0; + + + public interface PlayViewLayoutInterface { + void playViewLayout(int width, int height); + } + + private PlayViewLayoutInterface layoutInterface; + + public void setLayoutInterface(PlayViewLayoutInterface layoutInterface) { + mVideoView.post(new Runnable() { + @Override + public void run() { + int width = mVideoView.getMeasuredWidth(); + int height = mVideoView.getMeasuredHeight(); + if (layoutInterface != null) { + layoutInterface.playViewLayout(width, height); + } + } + }); + } + + +} diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java index 60e7155ec..73bb5b84f 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java @@ -79,6 +79,36 @@ public class LivePlayTxViewHolder extends LiveRoomPlayViewHolder implements ITXL public void setLiveBeanLandscape(int landscape) { } + @Override + public void endPk() { + + } + + @Override + public void endpk(String liveUid) { + + } + + @Override + public void initSwEngine(String liveUid) { + + } + + @Override + public void removeDetailView() { + + } + + @Override + public void setPkView(String liveUid) { + + } + + @Override + public void claerDrPkInfoView() { + + } + @Override protected int getLayoutId() { return R.layout.view_live_play_tx; diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java deleted file mode 100644 index d413b7013..000000000 --- a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java +++ /dev/null @@ -1,476 +0,0 @@ -package com.yunbao.live.views; - -import android.content.Context; -import android.os.Bundle; -import android.os.Handler; -import android.text.TextUtils; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewParent; -import android.widget.FrameLayout; -import android.widget.ImageView; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.tencent.rtmp.ITXLivePlayListener; -import com.tencent.rtmp.TXLiveConstants; -import com.tencent.rtmp.TXLivePlayConfig; -import com.tencent.rtmp.TXLivePlayer; -import com.tencent.rtmp.ui.TXCloudVideoView; -import com.yunbao.common.bean.UserBean; -import com.yunbao.common.glide.ImgLoader; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.utils.DpUtil; -import com.yunbao.common.utils.L; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.live.R; -import com.yunbao.common.http.LiveHttpConsts; -import com.yunbao.common.http.LiveHttpUtil; - -/** - * Created by cxf on 2018/10/10. - * 直播间播放器 腾讯播放器 - */ - -public class LivePlayTxViewHolder_backup extends LiveRoomPlayViewHolder implements ITXLivePlayListener { - - private static final String TAG = "LiveTxPlayViewHolder"; - private ViewGroup mRoot; - private ViewGroup mSmallContainer; - private ViewGroup mLeftContainer; - private ViewGroup mRightContainer; - private ViewGroup mPkContainer; - private TXCloudVideoView mVideoView; - private View mLoading; - private ImageView mCover; - private TXLivePlayer mPlayer; - private boolean mPaused;//是否切后台了 - private boolean mStarted;//是否开始了播放 - private boolean mEnd;//是否结束了播放 - private boolean mPausedPlay;//是否被动暂停了播放 - private boolean mChangeToLeft; - private boolean mChangeToAnchorLinkMic; - private String mUrl; - private int mPlayType; - private HttpCallback mGetTxLinkMicAccUrlCallback; - private Handler mHandler; - private int mVideoLastProgress; - - @Override - public void setPkview() { - - } - - @Override - public void setPkEndview() { - - } - - @Override - public void setDrMicInfo(UserBean u) { - - } - - @Override - public void setLiveBeanLandscape(int landscape) { - - } - - public LivePlayTxViewHolder_backup(Context context, ViewGroup parentView) { - super(context, parentView); - } - - @Override - protected int getLayoutId() { - return R.layout.view_live_play_tx; - } - - @Override - public void init() { - mRoot = (ViewGroup) findViewById(R.id.root); - mSmallContainer = (ViewGroup) findViewById(R.id.small_container); - mLeftContainer = (ViewGroup) findViewById(R.id.left_container); - mRightContainer = (ViewGroup) findViewById(R.id.right_container); - mPkContainer = (ViewGroup) findViewById(R.id.pk_container); - mLoading = findViewById(R.id.loading); - mCover = (ImageView) findViewById(R.id.cover); - mVideoView = (TXCloudVideoView) findViewById(R.id.video_view); - - mPlayer = new TXLivePlayer(mContext); - mPlayer.setPlayListener(this); - mPlayer.setPlayerView(mVideoView); - mPlayer.enableHardwareDecode(false); - mPlayer.setRenderRotation(TXLiveConstants.RENDER_ROTATION_PORTRAIT); - mPlayer.setRenderMode(TXLiveConstants.RENDER_MODE_FULL_FILL_SCREEN); - TXLivePlayConfig playConfig = new TXLivePlayConfig(); - playConfig.setAutoAdjustCacheTime(true); - playConfig.setMaxAutoAdjustCacheTime(5.0f); - playConfig.setMinAutoAdjustCacheTime(1.0f); - mPlayer.setConfig(playConfig); - - } - - - @Override - public void onPlayEvent(int e, Bundle bundle) { - if (mEnd) { - return; - } - switch (e) { - case TXLiveConstants.PLAY_EVT_PLAY_BEGIN://播放开始 - if (mLoading != null && mLoading.getVisibility() == View.VISIBLE) { - mLoading.setVisibility(View.INVISIBLE); - } - break; - case TXLiveConstants.PLAY_EVT_PLAY_LOADING: - if (mLoading != null && mLoading.getVisibility() != View.VISIBLE) { - mLoading.setVisibility(View.VISIBLE); - } - break; - case TXLiveConstants.PLAY_EVT_RCV_FIRST_I_FRAME://第一帧 - hideCover(); - break; - case TXLiveConstants.PLAY_EVT_PLAY_END://播放结束 - replay(); - break; - case TXLiveConstants.PLAY_EVT_CHANGE_RESOLUTION://获取视频宽高 - if (mChangeToLeft || mChangeToAnchorLinkMic) { - return; - } - float width = bundle.getInt("EVT_PARAM1", 0); - float height = bundle.getInt("EVT_PARAM2", 0); - L.e(TAG, "流---width----->" + width); - L.e(TAG, "流---height----->" + height); - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mVideoView.getLayoutParams(); - int targetH = 0; - if (width >= height) {//横屏 9:16=0.5625 - targetH = (int) (mVideoView.getWidth() / width * height); - } else { - targetH = ViewGroup.LayoutParams.MATCH_PARENT; - } - if (targetH != params.height) { - params.height = targetH; - params.gravity = Gravity.CENTER; - mVideoView.requestLayout(); - } - - break; - case TXLiveConstants.PLAY_ERR_NET_DISCONNECT://播放失败 - case TXLiveConstants.PLAY_ERR_FILE_NOT_FOUND: - ToastUtil.show(mContext.getString(R.string.live_play_error)); - break; - case TXLiveConstants.PLAY_EVT_PLAY_PROGRESS: - int progress = bundle.getInt("EVT_PLAY_PROGRESS_MS"); - if (mVideoLastProgress == progress) { - replay(); - } else { - mVideoLastProgress = progress; - } - break; - default:break; - } - } - - @Override - public void onNetStatus(Bundle bundle) { - - } - - - @Override - public void hideCover() { - if (mCover != null) { - mCover.animate().alpha(0).setDuration(500).start(); - } - } - - @Override - public void setCover(String coverUrl) { - if (mCover != null) { - ImgLoader.displayBlur(mContext, coverUrl, mCover); - } - } - - @Override - public void fullScreen() { - - } - - @Override - public void smallScreen() { - - } - - /** - * 循环播放 - */ - private void replay() { - if (mStarted && mPlayer != null) { - mPlayer.seek(0); - mPlayer.resume(); - } - } - - - /** - * 暂停播放 - */ - @Override - public void pausePlay() { - if (!mPausedPlay) { - mPausedPlay = true; - if (!mPaused) { - if (mPlayer != null) { - mPlayer.pause(); - } - } - if (mCover != null) { - mCover.setAlpha(1f); - if (mCover.getVisibility() != View.VISIBLE) { - mCover.setVisibility(View.VISIBLE); - } - } - } - } - - /** - * 暂停播放后恢复 - */ - @Override - public void resumePlay() { - if (mPausedPlay) { - mPausedPlay = false; - if (!mPaused) { - if (mPlayer != null) { - mPlayer.resume(); - } - } - hideCover(); - } - } - - /** - * 开始播放 - * - * @param url 流地址 - */ - @Override - public void play(String url,int playModel) { - if (TextUtils.isEmpty(url)) { - return; - } - int playType = -1; - if (url.startsWith("rtmp://")) { - playType = TXLivePlayer.PLAY_TYPE_LIVE_RTMP; - } else if (url.endsWith(".flv")) { - playType = TXLivePlayer.PLAY_TYPE_LIVE_FLV; - } else if (url.endsWith(".m3u8")) { - playType = TXLivePlayer.PLAY_TYPE_VOD_HLS; - } else if (url.endsWith(".mp4")) { - playType = TXLivePlayer.PLAY_TYPE_VOD_MP4; - } - if (playType == -1) { - ToastUtil.show(mContext.getString(R.string.live_play_error_2)); - return; - } - if (mPlayer != null) { - int result = mPlayer.startPlay(url, playType); - if (result == 0) { - mStarted = true; - mUrl = url; - mPlayType = playType; - } - } - L.e(TAG, "play----url--->" + url); - } - - @Override - public void switchStream(String url, int playModel) { - - } - - @Override - public void stopPlay() { - mChangeToLeft = false; - mChangeToAnchorLinkMic = false; - if (mHandler != null) { - mHandler.removeCallbacksAndMessages(null); - } - if (mCover != null) { - mCover.setAlpha(1f); - if (mCover.getVisibility() != View.VISIBLE) { - mCover.setVisibility(View.VISIBLE); - } - } - stopPlay2(); - } - - @Override - public void stopPlay2() { - if (mPlayer != null) { - mPlayer.stopPlay(false); - } - } - - @Override - public void release() { - mEnd = true; - if (mHandler != null) { - mHandler.removeCallbacksAndMessages(null); - } - mHandler = null; - LiveHttpUtil.cancel(LiveHttpConsts.GET_TX_LINK_MIC_ACC_URL); - if (mPlayer != null) { - mPlayer.stopPlay(false); - mPlayer.setPlayListener(null); - } - mPlayer = null; - L.e(TAG, "release------->"); - } - - - @Override - public ViewGroup getSmallContainer() { - return mSmallContainer; - } - - - @Override - public ViewGroup getRightContainer() { - return mRightContainer; - } - - @Override - public ViewGroup getPkContainer() { - return mPkContainer; - } - - @Override - public void changeToLeft() { - mChangeToLeft = true; - if (mVideoView != null) { - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mVideoView.getLayoutParams(); - params.width = mVideoView.getWidth() / 2; - params.height = DpUtil.dp2px(250); - params.topMargin = DpUtil.dp2px(130); - mVideoView.setLayoutParams(params); - } - if (mLoading != null && mLeftContainer != null) { - ViewParent viewParent = mLoading.getParent(); - if (viewParent != null) { - ((ViewGroup) viewParent).removeView(mLoading); - } - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); - params.gravity = Gravity.CENTER; - mLoading.setLayoutParams(params); - mLeftContainer.addView(mLoading); - } - } - - @Override - public void changeToBig() { - mChangeToLeft = false; - if (mVideoView != null) { - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mVideoView.getLayoutParams(); - params.width = ViewGroup.LayoutParams.MATCH_PARENT; - params.height = ViewGroup.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - mVideoView.setLayoutParams(params); - } - if (mLoading != null && mRoot != null) { - ViewParent viewParent = mLoading.getParent(); - if (viewParent != null) { - ((ViewGroup) viewParent).removeView(mLoading); - } - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); - params.gravity = Gravity.CENTER; - mLoading.setLayoutParams(params); - mRoot.addView(mLoading); - } - } - - @Override - public void onResume() { - if (!mPausedPlay && mPaused && mPlayer != null) { - mPlayer.resume(); - } - mPaused = false; - } - - @Override - public void onPause() { - if (!mPausedPlay && mPlayer != null) { - mPlayer.pause(); - } - mPaused = true; - } - - @Override - public void onDestroy() { - release(); - } - - /** - * 腾讯sdk连麦时候切换低延时流 - */ - public void onLinkMicTxAccEvent(boolean linkMic) { - if (mStarted && mPlayer != null && !TextUtils.isEmpty(mUrl)) { - mPlayer.stopPlay(false); - if (linkMic) { - if (mGetTxLinkMicAccUrlCallback == null) { - mGetTxLinkMicAccUrlCallback = new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - JSONObject obj = JSON.parseObject(info[0]); - if (obj != null) { - String accUrl = obj.getString("streamUrlWithSignature"); - if (!TextUtils.isEmpty(accUrl) && mPlayer != null) { - L.e(TAG, "低延时流----->" + accUrl); - mPlayer.startPlay(accUrl, TXLivePlayer.PLAY_TYPE_LIVE_RTMP_ACC); - } - } - } - } - }; - } - LiveHttpUtil.getTxLinkMicAccUrl(mUrl, mGetTxLinkMicAccUrlCallback); - } else { - mPlayer.startPlay(mUrl, mPlayType); - } - } - } - - /** - * 设置主播连麦模式 - * - * @param anchorLinkMic - */ - public void setAnchorLinkMic(final boolean anchorLinkMic, int delayTime) { - if (mVideoView == null) { - return; - } - if (mHandler == null) { - mHandler = new Handler(); - } - mHandler.postDelayed(new Runnable() { - @Override - public void run() { - mChangeToAnchorLinkMic = anchorLinkMic; - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mVideoView.getLayoutParams(); - if (anchorLinkMic) { - params.height = DpUtil.dp2px(250); - params.topMargin = DpUtil.dp2px(130); - params.gravity = Gravity.TOP; - } else { - params.height = ViewGroup.LayoutParams.MATCH_PARENT; - params.topMargin = 0; - params.gravity = Gravity.CENTER; - } - mVideoView.setLayoutParams(params); - } - }, delayTime); - - } -} diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index 373a64543..169b32dce 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -9,8 +9,8 @@ import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.LIVE_PK_I import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.inputStreamList; import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.inputStreamList1; import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.mPkUid; +import static cn.rongcloud.rtc.base.RCRTCLiveRole.BROADCASTER; -import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.res.Resources; @@ -46,17 +46,16 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.RandomPkManager; +import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; -import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveRyAnchorActivity; -import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.common.http.LiveHttpConsts; import com.yunbao.common.http.LiveHttpUtil; @@ -72,23 +71,29 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; import java.util.List; +import cn.rongcloud.rtc.api.RCRTCConfig; import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.RCRTCMixConfig; import cn.rongcloud.rtc.api.RCRTCRemoteUser; import cn.rongcloud.rtc.api.RCRTCRoom; +import cn.rongcloud.rtc.api.RCRTCRoomConfig; +import cn.rongcloud.rtc.api.callback.IRCRTCEngineEventListener; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; import cn.rongcloud.rtc.api.stream.RCRTCInputStream; import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; +import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; +import cn.rongcloud.rtc.api.stream.RCRTCVideoView; import cn.rongcloud.rtc.base.RCRTCParamsType; +import cn.rongcloud.rtc.base.RCRTCRoomType; +import cn.rongcloud.rtc.base.RCRTCVideoEventCode; import cn.rongcloud.rtc.base.RTCErrorCode; -import io.agora.beautyapi.faceunity.agora.SWAuManager; -import io.agora.beautyapi.faceunity.agora.SWManager; +import cn.rongcloud.rtc.core.CameraVideoCapturer; +import cn.rongcloud.rtc.core.RendererCommon; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; -import io.rong.imlib.model.Message; import io.rong.message.TextMessage; /** @@ -97,11 +102,13 @@ import io.rong.message.TextMessage; */ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITXLivePushListener { + private int mMeiBaiVal;//基础美颜 美白 private int mMoPiVal;//基础美颜 磨皮 private int mHongRunVal;//基础美颜 红润 private String mBgmPath;//背景音乐路径 private Bitmap mFilterBmp; + private TXDeviceManager mTXDeviceManager; private TRTCCloudDef.TRTCParams mTRTCParams; private Handler mMainHandler; @@ -111,6 +118,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public LinearLayout dr_pk_view; public static RCRTCRoom rtcRoom; public static RCRTCLiveInfo rcrtcLiveInfo; + private ViewGroup liveActivityContainer; public FrameLayout timeTitle; public TextView textTime; @@ -119,8 +127,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX private LinearLayout goto_room_view; private boolean isPk = false; private boolean isNeedOpenCamera = false; - private SWManager swManager; - private String pkUid1; //修改上面主播的头像 @Subscribe(threadMode = ThreadMode.MAIN) @@ -134,6 +140,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX goto_room_view.setVisibility(View.VISIBLE); } else { goto_room_view.setVisibility(View.GONE); + } } } @@ -231,7 +238,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX UserBean userBean = new UserBean(); userBean.setId(inviterRoomId); //收到邀请这个时候正在PK或连麦中 自动拒绝对方 - if (isPking()) { + if (isPking() == true) { rtcRoom.getLocalUser().responseJoinOtherRoom(userBean.getId(), userBean.getId(), false, false, "extra", new IRCRTCResultCallback() { @@ -242,7 +249,9 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 8); msg1.create(); String targetId = userBean.getId(); @@ -250,7 +259,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override public void onAttached(io.rong.imlib.model.Message message) { @@ -286,7 +295,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX rtcRoom.getLocalUser().responseJoinOtherRoom(userBean.getId(), userBean.getId(), true, true, "LiveDRPK1", new IRCRTCResultCallback() { @Override public void onSuccess() { - //mLiveRyLinkMicPkPresenter.dRjoinOtherRoom(userBean.getId(), 2); + mLiveRyLinkMicPkPresenter.dRjoinOtherRoom(userBean.getId(), 2); } @Override @@ -301,7 +310,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX JSONObject map = JSONObject.parseObject(extra); userBean1.setId(map.getString("uid")); userBean1.setUserNiceName(map.getString("pkname")); - userBean1.setAvatar(map.getString("uhead")); + userBean1.setAvatar(map.getString("pkhead")); } else { userBean1.setId(inviterRoomId); userBean1.setUserNiceName("null"); @@ -382,7 +391,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } else if (agree == true && extra.equals(SOCKET_LIVE_DRPK)) { mLiveRyLinkMicPkPresenter.onDRLinkMicToPk(inviteeRoomId); } else if (extra.equals("LiveDRPK1")) { - //mLiveRyLinkMicPkPresenter.dRjoinOtherRoom(inviteeRoomId, 3); + mLiveRyLinkMicPkPresenter.dRjoinOtherRoom(inviteeRoomId, 3); } else { Log.e("ry", extra); UserBean userBean1 = new UserBean(); @@ -406,7 +415,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + ToastUtil.show(WordUtil.isNewZh()?"抱歉!出錯了!":"i \\'m sorry! An error occurred"); } }); @@ -462,6 +471,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } }; + @Override public void init() { super.init(); @@ -496,231 +506,283 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX aheadOfScheduleEndPK(mPkUid, CommonAppConfig.getInstance().getUserBean().getUserNiceName(), (String) tv_avatarOther_name.getTag()); //断开连麦 LiveRyAnchorActivity.isDRPK = 0; - HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout").execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - } - }); + HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + } + }); - HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK").params("uid", CommonAppConfig.getInstance().getUid()).params("addtime", "1").params("type", "1").params("sign", "1").execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - JSONObject datas = JSONObject.parseObject(info[0]); - String pkUid = datas.getString("pkuid"); - //退出副房间 - // TODO: 2024/4/13 退出对方主播直播间 - SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), pkUid1); - SWManager.get().updateMyChannelView((FrameLayout) mBigContainer); - btn_close.setVisibility(View.GONE);//隐藏连麦按钮 - EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); - closeButtonGone(); - - SocketSendBean seed_msg = new SocketSendBean().param("_method_", Constants.SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); - seed_msg.create(); - Log.i("seed", seed_msg.mResult.toString()); - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("addtime", "1") + .params("type", "1") + .params("sign", "1") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + JSONObject datas = JSONObject.parseObject(info[0]); + String pkUid = datas.getString("pkuid"); + //退出副房间 + RCRTCEngine.getInstance().leaveOtherRoom(pkUid, true, new IRCRTCResultCallback() { @Override - public void onSuccess(int code, String msg, String[] info) { - - SocketSendBean seed_msgs = new SocketSendBean().param("_method_", Constants.SOCKET_LINK_MIC_PK).param("action", 5).param("msgtype", 10).param("uname", "1").param("uimg", "1").param("pkuid", LiveRyLinkMicPkPresenter.oldmPkUid).param("uid", CommonAppConfig.getInstance().getUid()); - seed_msgs.create(); - Log.i("seed", seed_msgs.mResult.toString()); - - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + LiveRyLinkMicPkPresenter.oldmPkUid).params("jsonstr", seed_msgs.mResult.toString()).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msgs.mResult.toString()).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - } - }); + public void onSuccess() { + Log.e("ry", "退出房间成功" + pkUid); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + mPreView1.removeAllViews(); + mPreView1.setVisibility(View.GONE); + inputStreamList.clear(); + inputStreamList1.clear(); + changeToBig(); + //清理PK上面对方的头像 + EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); + closeButtonGone(); } }); } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", pkUid + "退出房间s失败" + rtcErrorCode); + } }); + + + SocketSendBean seed_msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_LINK_MIC_PK) + .param("action", 9) + .param("msgtype", 10) + .param("win_uid", datas.getString("win_uid")) + .param("uid", CommonAppConfig.getInstance().getUid()); + seed_msg.create(); + Log.i("seed", seed_msg.mResult.toString()); + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") + .params("GroupId", "g" + pkUid) + .params("jsonstr", seed_msg.mResult.toString()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") + .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) + .params("jsonstr", seed_msg.mResult.toString()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + SocketSendBean seed_msgs = new SocketSendBean() + .param("_method_", Constants.SOCKET_LINK_MIC_PK) + .param("action", 5) + .param("msgtype", 10) + .param("uname", "1") + .param("uimg", "1") + .param("pkuid", LiveRyLinkMicPkPresenter.oldmPkUid) + .param("uid", CommonAppConfig.getInstance().getUid()); + seed_msgs.create(); + Log.i("seed", seed_msgs.mResult.toString()); + + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") + .params("GroupId", "g" + LiveRyLinkMicPkPresenter.oldmPkUid) + .params("jsonstr", seed_msgs.mResult.toString()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") + .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) + .params("jsonstr", seed_msgs.mResult.toString()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + } + }); + } + }); + } + }); + } + }); + } - }); - } - - } - }); + } + }); } }); } }); - initRtcEngine(); - } - /** - * 初始化声网SDK - */ - private void initRtcEngine() { - swManager = SWManager.get(); - swManager.setAnchorContainer((FrameLayout) mBigContainer); - swManager.initRtcEngine((Activity) mContext, CommonAppConfig.getInstance().getUid()); - swManager.setOnRtcEngineListener(new SWManager.onRtcEngineListener() { + // 构建 RoomConfig,指定房间类型和主播身份: + RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() + // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO + .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) + .setLiveRole(BROADCASTER) + .build(); + + + //调用 RCRTCEngine 下的 joinRoom 方法创建并加入一个直播房间: + final CommonAppConfig appConfig = CommonAppConfig.getInstance(); + + RCRTCEngine.getInstance().joinRoom(appConfig.getUid(), roomConfig, new IRCRTCResultDataCallback() { @Override - public void onOpenSuccess(String channel, int uid) { - //开播成功 - L.eSw("开播成功"); + public void onFailed(RTCErrorCode errorCode) { + ToastUtil.show("开播失败" + errorCode); } - }); - } - public void exitChannelDrPk(List drPkbeanList){ - for (int i = 0; i () { + @Override + public void onSuccess(Boolean data) { + //设置摄像头最大缩放比例 + boolean zoom = RCRTCEngine.getInstance().getDefaultVideoStream().setCameraZoomFactor(1.0f); + // ToastUtil.show("设置比例="+zoom); + Log.i("摄像头", "onSuccess: 打开摄像头"); + isNeedOpenCamera = false; + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.i("摄像头", "onFailed: 打开摄像头失败 " + errorCode); + } + }); + RCRTCEngine.getInstance().registerEventListener(new IRCRTCEngineEventListener() { + @Override + public void onKicked(String roomId, RCRTCParamsType.RCRTCKickedReason kickedReason) { + + } + + @Override + public void onError(RTCErrorCode errorCode) { + super.onError(errorCode); + Log.i("摄像头", "onError: 错误码" + errorCode); + } + + @Override + public void onLocalVideoEventNotify(RCRTCVideoEventCode event) { + super.onLocalVideoEventNotify(event); + Log.i("摄像头", "onLocalVideoEventNotify: 本地视频事件" + event.code); + if (event.code == 3) { + isNeedOpenCamera = true; + } + } + }); + //设置摄像头最大缩放比例 + // RCRTCEngine.getInstance().getDefaultVideoStream().setCameraZoomFactor(RCRTCEngine.getInstance().getDefaultVideoStream().getCameraMaxZoomFactor()); + mPreView.addView(rongRTCVideoView); + tencentTRTCBeautyManager = new TencentTRTCBeautyManager(mContext); + + //加入房间成功后可以通过 RCRTCLocalUser 对象发布本地默认音视频流,包括:麦克风采集的音频和摄像头采集的视频。 + RCRTCEngine.getInstance().getDefaultVideoStream().setEncoderMirror(true); + if (rtcRoom == null || rtcRoom.getLocalUser() == null) { + if (room == null || room.getLocalUser() == null) { + ToastUtil.show("开播失败 请稍后再试,错误代码:room is null"); + ((LiveRyAnchorActivity) mContext).endLives(); + return; + } + rtcRoom = room; + IMRTCManager.getInstance().setRtcRoom(room); + } + rtcRoom.getLocalUser().publishDefaultLiveStreams(new IRCRTCResultDataCallback() { + @Override + public void onSuccess(RCRTCLiveInfo rcrtcLiveInfo1) { + rcrtcLiveInfo = rcrtcLiveInfo1; + + room.registerRoomListener(roomEventsListener); + + //美颜 +// new Handler(Looper.getMainLooper()).post(new Runnable() { +// public void run() { +// //旧美颜不需要了 +// +// +// } +// }); + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", "rtcErrorCode" + rtcErrorCode); + } + }); } + }); - mLiveRyLinkMicPkPresenter.setPkUserInfoView(u); - } - private int currentPosition = 0; - private String drpkUid3 = ""; - public int setAnDrPkRtc(String uid, int position) { - L.eSw("setAnDrPkRtc uid:"+uid+" position"+position); - int temp= -1; - if (swManager != null && !StringUtil.isEmpty(uid)) { - L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid + "position:" + position); - if(currentPosition==0){ - position = 2; } - if(position==-1){ - temp = currentPosition+1; - }else{ - temp = position; - } - switch (temp) { - case 2: - swManager.joinChannelDrEx(dr2_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); - swManager.updateMyChannelView(dr1_preview); - mBigContainer.removeAllViews(); - - dr3_preview.setVisibility(View.GONE); - dr4_preview.setVisibility(View.GONE); - break; - case 3: - drpkUid3 = uid; - swManager.joinChannelDrEx(dr4_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); - dr3_preview.setVisibility(View.GONE); - dr4_preview.setVisibility(View.VISIBLE); - break; - case 4: - dr3_preview.setVisibility(View.VISIBLE); - //先退出这个主播的直播间,在进入该直播间,(视图问题暂时這樣處理) - swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),drpkUid3); - swManager.joinChannelDrEx(dr3_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3)); - - swManager.joinChannelDrEx(dr4_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); - break; - } - dr_pk_view.setVisibility(View.VISIBLE); - currentPosition = temp; - } - return currentPosition; - } - - public void anchorClose(){ - swManager.updateMyChannelView((FrameLayout) mBigContainer); //用户主动断开连麦再退出画面 - } - - public void onLinkMicAnchorClose() { - //swManager.updateMyChannelView((FrameLayout) mBigContainer); 用户主动断开连麦再退出画面 - //LivePushRyViewHolder.btn_close.setVisibility(View.GONE); - } - - - - public void onLinkDRMicPkApply(UserBean userBean) { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkDRMicPkApply(userBean); - } + }); } @Override public void changeToLeft() { if (mPreView != null) { - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mPreView.getLayoutParams(); + FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mPreView.getLayoutParams(); params.width = mPreView.getWidth() / 2; - params.height = DpUtil.dp2px(mPreView.getHeight()); + params.height = DpUtil.dp2px(250); params.topMargin = DpUtil.dp2px(130); camera.setLayoutParams(params); } @@ -754,7 +816,17 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } else { mCameraFront = true; } - swManager.switchCamera(); + RCRTCEngine.getInstance().getDefaultVideoStream().switchCamera(new CameraVideoCapturer.CameraSwitchHandler() { + @Override + public void onCameraSwitchDone(boolean isFrontCamera) { + + } + + @Override + public void onCameraSwitchError(String errorDescription) { + + } + }); } /** @@ -766,6 +838,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX ToastUtil.show(mContext.getString(R.string.live_open_flash)); return; } + } /** @@ -775,10 +848,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX */ @Override public void startPush(String pushUrl) { - //开播成功,创建频道 - if (swManager != null) { - swManager.createChannel(CommonAppConfig.SWToken, CommonAppConfig.getChannelName()); - } if (rcrtcLiveInfo != null) { rcrtcLiveInfo.addPublishStreamUrl(pushUrl, new IRCRTCResultDataCallback() { @Override @@ -878,7 +947,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void onResume() { mPaused = false; Log.i("摄像头", "onResume: " + isNeedOpenCamera); - if (isNeedOpenCamera) { + if(isNeedOpenCamera){ RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(new IRCRTCResultDataCallback() { @Override public void onSuccess(Boolean data) { @@ -901,6 +970,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX public void startBgm(String path) { mBgmPath = path; + } @Override @@ -968,20 +1038,30 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } String ct = "由於 " + uname + " 退出比賽," + pkname + " 獲得勝利"; - SocketSendBean seed_msg = new SocketSendBean().param("_method_", Constants.SOCKET_SYSTEM).param("action", 1).param("ct", ct); + SocketSendBean seed_msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_SYSTEM) + .param("action", 1) + .param("ct", ct); seed_msg.create(); - HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2") + .params("GroupId", "g" + pkUid) + .params("jsonstr", seed_msg.mResult.toString()) + .execute(new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2") + .params("GroupId", "g" + CommonAppConfig.getInstance().getUid()) + .params("jsonstr", seed_msg.mResult.toString()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + } + }); } }); - } - }); } private Bitmap decodeResource(Resources resources, int id) { @@ -1016,12 +1096,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX }); } - public void setEnableBeauty(boolean flag) { - if (swManager != null) { - swManager.setEnableBeauty(flag); - } - } - @Subscribe(threadMode = ThreadMode.MAIN) public void updateSub(LiveAudienceEvent event) { if (event.getType() == LIVE_PK_END) { @@ -1031,12 +1105,4 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } Log.i("PK----->", "updateSub: " + isPk + "|" + event.getType()); } - - @Override - public void onDestroy() { - super.onDestroy(); - if (swManager != null) { - swManager.exitChannelAll(); - } - } } diff --git a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java new file mode 100644 index 000000000..d5a2402c8 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -0,0 +1,731 @@ +package com.yunbao.live.views; + +import static com.yunbao.live.activity.LiveActivity.mLiveSwLinkMicPkPresenter; +import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.LIVE_PK_END; +import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.LIVE_PK_ING; +import static com.yunbao.live.presenter.LiveSwLinkMicPkPresenter.inputStreamList; +import static com.yunbao.live.presenter.LiveSwLinkMicPkPresenter.inputStreamList1; +import static com.yunbao.live.presenter.LiveSwLinkMicPkPresenter.mPkUid; + +import android.app.Activity; +import android.app.Dialog; +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import android.util.TypedValue; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.alibaba.fastjson.JSONObject; +import com.tencent.rtmp.ITXLivePushListener; +import com.tencent.rtmp.TXLiveConstants; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.Constants; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.event.AnchorInfoEvent; +import com.yunbao.common.event.LivePushRyEvent; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; +import com.yunbao.live.bean.DrPkbean; +import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.common.http.LiveHttpConsts; +import com.yunbao.common.http.LiveHttpUtil; +import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; +import com.yunbao.live.socket.SocketSendBean; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.List; + +import cn.rongcloud.rtc.api.RCRTCEngine; +import cn.rongcloud.rtc.api.RCRTCMixConfig; +import cn.rongcloud.rtc.api.RCRTCRoom; +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; +import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; +import cn.rongcloud.rtc.base.RCRTCParamsType; +import cn.rongcloud.rtc.base.RTCErrorCode; +import io.agora.beautyapi.faceunity.agora.SWAuManager; +import io.agora.beautyapi.faceunity.agora.SWManager; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; +import io.rong.message.TextMessage; + +/** + * Created by cxf on 2018/10/7. + * 腾讯云直播推流 + */ + +public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITXLivePushListener { + private int mMeiBaiVal;//基础美颜 美白 + private int mMoPiVal;//基础美颜 磨皮 + private int mHongRunVal;//基础美颜 红润 + private String mBgmPath;//背景音乐路径 + private Bitmap mFilterBmp; + private Handler mMainHandler; + public static Context contexts; + public static TextView btn_close; + public LinearLayout dr_pk_view; + public static RCRTCRoom rtcRoom; + public static RCRTCLiveInfo rcrtcLiveInfo; + private ViewGroup liveActivityContainer; + public FrameLayout timeTitle; + public TextView textTime; + private TextView tv_avatarOther_name; + private ImageView avatarOther; + private LinearLayout goto_room_view; + private boolean isPk = false; + private boolean isNeedOpenCamera = false; + private SWManager swManager; + private String pkUid1; + + //修改上面主播的头像 + @Subscribe(threadMode = ThreadMode.MAIN) + public void onUPAnchorInfo(AnchorInfoEvent e) { + Log.i(TAG, "onUPAnchorInfo: " + e); + if (e != null) { + if (!e.isClear()) { + tv_avatarOther_name.setText(e.getUserNiceName()); + tv_avatarOther_name.setTag(e.getUserNiceName()); + ImgLoader.displayAvatar(mContext, e.getAvatar(), avatarOther); + goto_room_view.setVisibility(View.VISIBLE); + } else { + goto_room_view.setVisibility(View.GONE); + } + } + } + + + public LivePushSwViewHolder(Context context, ViewGroup parentView) { + super(context, parentView); + this.contexts = context; + EventBus.getDefault().register(this); + } + + @Override + protected int getLayoutId() { + return R.layout.view_live_push_sw; + } + + public void setLiveActivityContainer(ViewGroup liveActivityContainer) { + this.liveActivityContainer = liveActivityContainer; + } + + @Override + public void init() { + super.init(); + Bus.getOn(this); + mPreView = (FrameLayout) findViewById(R.id.camera_preview); + camera = (LinearLayout) findViewById(R.id.camera); + mPreView1 = (FrameLayout) findViewById(R.id.camera_preview1); + cameraPreview3 = (FrameLayout) findViewById(R.id.camera_preview3); + dr1_preview = (FrameLayout) findViewById(R.id.dr1_preview); + dr2_preview = (FrameLayout) findViewById(R.id.dr2_preview); + dr3_preview = (FrameLayout) findViewById(R.id.dr3_preview); + dr4_preview = (FrameLayout) findViewById(R.id.dr4_preview); + leave = (ImageView) findViewById(R.id.leave); + dr_pk_view = (LinearLayout) findViewById(R.id.dr_pk_view); + timeTitle = (FrameLayout) findViewById(R.id.time_title); + textTime = (TextView) findViewById(R.id.text_time); + dr_pk_view.setVisibility(View.GONE); + cameraPreview3.setVisibility(View.GONE); + btn_close = (TextView) findViewById(R.id.btn_close); + tv_avatarOther_name = (TextView) findViewById(R.id.tv_avatarOther_name); + avatarOther = (ImageView) findViewById(R.id.avatarOther); + goto_room_view = (LinearLayout) findViewById(R.id.goto_room_view); + goto_room_view.setVisibility(View.GONE); + mMainHandler = new Handler(Looper.getMainLooper()); + btn_close.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DialogUitl.showSimpleDialog(mContext, WordUtil.isNewZh() ? "是否要斷開連麥?" : "Do you want to disconnect Link?", new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + Log.i("PK----->", "updateSub: " + isPk + "|"); + aheadOfScheduleEndPK(mPkUid, CommonAppConfig.getInstance().getUserBean().getUserNiceName(), (String) tv_avatarOther_name.getTag()); + //断开连麦 + LiveSwAnchorActivity.isDRPK = 0; + HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + } + }); + + HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK").params("uid", CommonAppConfig.getInstance().getUid()).params("addtime", "1").params("type", "1").params("sign", "1").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + JSONObject datas = JSONObject.parseObject(info[0]); + String pkUid = datas.getString("pkuid"); + + //退出副房间 + // TODO: 2024/4/13 退出对方主播直播间 + SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), pkUid1); + SWManager.get().updateMyChannelView((FrameLayout) mBigContainer); + btn_close.setVisibility(View.GONE);//隐藏连麦按钮 + EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); + closeButtonGone(); + + SocketSendBean seed_msg = new SocketSendBean().param("_method_", Constants.SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); + seed_msg.create(); + Log.i("seed", seed_msg.mResult.toString()); + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + SocketSendBean seed_msgs = new SocketSendBean().param("_method_", Constants.SOCKET_LINK_MIC_PK).param("action", 5).param("msgtype", 10).param("uname", "1").param("uimg", "1").param("pkuid", LiveSwLinkMicPkPresenter.oldmPkUid).param("uid", CommonAppConfig.getInstance().getUid()); + seed_msgs.create(); + Log.i("seed", seed_msgs.mResult.toString()); + + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + LiveSwLinkMicPkPresenter.oldmPkUid).params("jsonstr", seed_msgs.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msgs.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + } + }); + } + }); + } + }); + } + }); + + } + + } + }); + + + } + }); + } + }); + initRtcEngine(); + } + + /** + * 初始化声网SDK + */ + private void initRtcEngine() { + swManager = SWManager.get(); + swManager.setAnchorContainer((FrameLayout) mBigContainer); + swManager.initRtcEngine((Activity) mContext, CommonAppConfig.getInstance().getUid()); + swManager.setOnRtcEngineListener(new SWManager.onRtcEngineListener() { + @Override + public void onOpenSuccess(String channel, int uid) { + //开播成功 + L.eSw("开播成功"); + } + }); + } + + public void exitChannelDrPk(List drPkbeanList){ + for (int i = 0; i () { + @Override + public void onSuccess(String[] data) { + //强制设置开播后cdn的尺寸竖屏,因为有时候PK异常退出,cdn没有还原竖屏。 + if (rtcRoom != null) { + RCRTCMixConfig config = new RCRTCMixConfig(); + RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); + config.setMediaConfig(mediaConfig); + //视频输出配置 + RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); + mediaConfig.setVideoConfig(videoConfig); + //大流视频的输出参数 + RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); + + //推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 + //如不设置宽高值则服务端将使用默认宽高 360 * 640 + //例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, + //所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 + //設置開播分辨率 + //設置開播分辨率 + RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; + int minRate = 200; + int maxRate = 900; + switch (IMLoginManager.get(mContext).getSelectClarity()) { + case 0: + rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; + break; + case 1: + rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; + break; + case 2: + rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; + break; + } + int width = rcrtcVideoResolution.getWidth(); + int height = rcrtcVideoResolution.getHeight(); + normal.setWidth(width); //视频宽 + normal.setHeight(height); //视频高 + normal.setFps(15); //视频帧率 + videoConfig.setVideoLayout(normal); + //2. 合流画布设置 + //(请参照画布和声音配置示例代码) + //3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高 + ArrayList list = new ArrayList<>(); + config.setCustomLayouts(list); + //user1的视频流 + RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); + list.add(videoLayout1); + videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video + videoLayout1.setX(0); //X 坐标 + videoLayout1.setY(0); //Y 坐标 + videoLayout1.setWidth(720); // 视频窗口的宽 + videoLayout1.setHeight(1280); // 视频窗口的高 + //2. 合流画布设置 + rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "混成功12"); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "混失败" + errorCode); + + } + }); + } + + + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + } + }); + startCountDown(); + } else { + ToastUtil.show("请稍后,准备中...."); + } + } + + public boolean isPking() { + if (btn_close != null) { + return btn_close.getVisibility() == View.VISIBLE; + } + return false; + } + + @Override + public void onPause() { + mPaused = true; + + } + + @Override + public void onResume() { + mPaused = false; + Log.i("摄像头", "onResume: " + isNeedOpenCamera); + if (isNeedOpenCamera) { + RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(new IRCRTCResultDataCallback() { + @Override + public void onSuccess(Boolean data) { + //设置摄像头最大缩放比例 + boolean zoom = RCRTCEngine.getInstance().getDefaultVideoStream().setCameraZoomFactor(1.0f); + // ToastUtil.show("设置比例="+zoom); + Log.i("摄像头", "onSuccess: 打开摄像头"); + isNeedOpenCamera = false; + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.i("摄像头", "onFailed: 打开摄像头失败 " + errorCode); + } + }); + } + } + + @Override + public void startBgm(String path) { + mBgmPath = path; + + } + + @Override + public void pauseBgm() { + + } + + @Override + public void resumeBgm() { + + } + + @Override + public void stopBgm() { + mBgmPath = null; + } + + + @Override + public void release() { + super.release(); + Bus.getOff(this); + LiveHttpUtil.cancel(LiveHttpConsts.LINK_MIC_TX_MIX_STREAM); + rtcRoom = null; + } + + @Override + public void onPushEvent(int e, Bundle bundle) { + if (e == TXLiveConstants.PUSH_ERR_OPEN_CAMERA_FAIL) { + ToastUtil.show(mContext.getString(R.string.live_push_failed_1)); + + } else if (e == TXLiveConstants.PUSH_ERR_OPEN_MIC_FAIL) { + ToastUtil.show(mContext.getString(R.string.live_push_failed_2)); + + } else if (e == TXLiveConstants.PUSH_ERR_NET_DISCONNECT || e == TXLiveConstants.PUSH_ERR_INVALID_ADDRESS) { + L.e(TAG, "网络断开,推流失败------>"); + + } else if (e == TXLiveConstants.PUSH_WARNING_HW_ACCELERATION_FAIL) { + L.e(TAG, "不支持硬件加速------>"); + + } else if (e == TXLiveConstants.PUSH_EVT_FIRST_FRAME_AVAILABLE) {//预览成功 + L.e(TAG, "mStearm--->初始化完毕"); + if (mLivePushListener != null) { + mLivePushListener.onPreviewStart(); + } + } else if (e == TXLiveConstants.PUSH_EVT_PUSH_BEGIN) {//推流成功 + L.e(TAG, "mStearm--->推流成功"); + if (!mStartPush) { + mStartPush = true; + if (mLivePushListener != null) { + mLivePushListener.onPushStart(); + } + } + } + } + + @Override + public void onNetStatus(Bundle bundle) { + + } + + private void aheadOfScheduleEndPK(String pkUid, String uname, String pkname) { + if (!isPk) { + return; + } + String ct = "由於 " + uname + " 退出比賽," + pkname + " 獲得勝利"; + + SocketSendBean seed_msg = new SocketSendBean().param("_method_", Constants.SOCKET_SYSTEM).param("action", 1).param("ct", ct); + seed_msg.create(); + + HttpClient.getInstance().get("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + } + }); + } + }); + } + + private Bitmap decodeResource(Resources resources, int id) { + TypedValue value = new TypedValue(); + resources.openRawResource(id, value); + BitmapFactory.Options opts = new BitmapFactory.Options(); + opts.inTargetDensity = value.density; + return BitmapFactory.decodeResource(resources, id, opts); + } + + public static String getLiveStream() { + return ((LiveActivity) contexts).getStream(); + } + + private String getTxAppId() { + return ((LiveActivity) mContext).getTxAppId(); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void setSelectClarity(LivePushRyEvent event) { + if (rtcRoom != null) + rtcRoom.getLocalUser().publishDefaultLiveStreams(new IRCRTCResultDataCallback() { + @Override + public void onSuccess(RCRTCLiveInfo rcrtcLiveInfo1) { + rcrtcLiveInfo = rcrtcLiveInfo1; + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + Log.e("ry", "rtcErrorCode" + rtcErrorCode); + } + }); + } + + public void setEnableBeauty(boolean flag) { + if (swManager != null) { + swManager.setEnableBeauty(flag); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void updateSub(LiveAudienceEvent event) { + if (event.getType() == LIVE_PK_END) { + isPk = false; + } else if (event.getType() == LIVE_PK_ING) { + isPk = true; + } + Log.i("PK----->", "updateSub: " + isPk + "|" + event.getType()); + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (swManager != null) { + swManager.exitChannelAll(); + } + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java index e329329eb..79ea38d0f 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java @@ -34,7 +34,7 @@ import com.yunbao.common.views.AbsViewHolder; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveChooseClassActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.adapter.LiveReadyShareAdapter; import com.yunbao.common.bean.LiveRoomTypeBean; import com.yunbao.live.dialog.LiveRoomTypeDialogFragment; @@ -123,7 +123,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick @Override public void beforeCamera() { - ((LiveRyAnchorActivity) mContext).beforeCamera(); + ((LiveSwAnchorActivity) mContext).beforeCamera(); } @Override @@ -218,8 +218,8 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick public void openWishListWindow() { LiveWishListDialogFragment fragment = new LiveWishListDialogFragment(); - if (mContext instanceof LiveRyAnchorActivity){ - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "RY"); + if (mContext instanceof LiveSwAnchorActivity){ + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "RY"); } } @@ -281,14 +281,14 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick * 切换镜头 */ private void toggleCamera() { - ((LiveRyAnchorActivity) mContext).toggleCamera(); + ((LiveSwAnchorActivity) mContext).toggleCamera(); } /** * 关闭 */ private void close() { - ((LiveRyAnchorActivity) mContext).endLives(); + ((LiveSwAnchorActivity) mContext).endLives(); } /** @@ -309,7 +309,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick * 设置美颜 */ private void beauty() { - ((LiveRyAnchorActivity) mContext).beauty(); + ((LiveSwAnchorActivity) mContext).beauty(); // Intent intent = new Intent(mContext, Beauty360Activity3.class); // mContext.startActivity(intent); @@ -324,7 +324,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick LiveRoomTypeDialogFragment fragment = new LiveRoomTypeDialogFragment(); fragment.setArguments(bundle); fragment.setCallback(mLiveTypeCallback); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); } /** @@ -398,7 +398,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick mLiveTimeCoin = coin; } }); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveTimeDialogFragment"); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveTimeDialogFragment"); } public void hide() { @@ -418,7 +418,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick * 点击开始直播按钮 */ private void startLive() { - boolean startPreview = ((LiveRyAnchorActivity) mContext).isStartPreview(); + boolean startPreview = ((LiveSwAnchorActivity) mContext).isStartPreview(); // if (!startPreview) { // ToastUtil.show(R.string.please_wait); // return; @@ -471,7 +471,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick return; } String title = mEditTitle.getText().toString().trim(); - LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile,0, new HttpCallback() { + LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile,0, false,new HttpCallback() { @Override public void onSuccess(int code, String msg, final String[] info) { if (code == 0 && info.length > 0) { @@ -480,7 +480,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick final CommonAppConfig appConfig = CommonAppConfig.getInstance(); UserBean u = appConfig.getUserBean(); - ((LiveRyAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); + ((LiveSwAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); // // RongChatRoomClient.getInstance().joinChatRoom("g" + appConfig.getUid(), -1, new IRongCoreCallback.OperationCallback() { // @Override diff --git a/live/src/main/java/com/yunbao/live/views/LiveReadyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveReadyViewHolder.java index abf89e1fb..a19123a46 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveReadyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveReadyViewHolder.java @@ -492,7 +492,7 @@ public class LiveReadyViewHolder extends AbsViewHolder implements View.OnClickLi return; } String title = mEditTitle.getText().toString().trim(); - LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile, 0, new HttpCallback() { + LiveHttpUtil.newcreateRoom(title, mLiveClassID, mLiveType, mLiveTypeVal, mAvatarFile, 0, false,new HttpCallback() { @Override public void onSuccess(int code, String msg, final String[] info) { if (code == 0 && info.length > 0) { diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index 0cbe9709e..7fb4954ca 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -90,6 +90,7 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public void setViewDrMic() { } + public void setViewDrPk() { } @@ -115,6 +116,17 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public void clearFrame() { } + public abstract void endPk(); + + public abstract void endpk(String liveUid); + + public abstract void initSwEngine(String liveUid); + + public abstract void removeDetailView(); + + public abstract void setPkView(String liveUid); + + public abstract void claerDrPkInfoView(); public interface OnMicCallback { diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index cbe457cc0..2be05e28d 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -148,7 +148,7 @@ import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAnchorActivity; import com.yunbao.live.activity.LiveAudienceActivity; -import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.activity.ZhuangBanActivity; import com.yunbao.live.adapter.LiveChatAdapter; import com.yunbao.live.adapter.LiveRoomFastMessageRecyclerViewAdapter; @@ -1263,7 +1263,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis topBanner1 = (Banner) findViewById(R.id.top_banner1); topBanner2 = (Banner) findViewById(R.id.top_banner2); - if (LivePushTxViewHolder.mTRTCCloud != null || LivePushRyViewHolder.rtcRoom != null) { + if (LivePushTxViewHolder.mTRTCCloud != null || LivePushSwViewHolder.rtcRoom != null) { fans_btn.setVisibility(View.GONE); } mPkRankTopIcon.setVisibility(View.GONE); @@ -1579,7 +1579,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } // fastMsgRecyclerView.setItemAnimator(new DefaultItemAnimator()); //主播页面隐藏头部 - if (mContext instanceof LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity) { findViewById(R.id.open_sidebar).setVisibility(View.GONE); findViewById(R.id.btn_follow).setVisibility(View.GONE); findViewById(R.id.live_rank_pk).setVisibility(View.GONE); @@ -1739,7 +1739,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis redSchedule.setText(stringBuffer.toString()); openRedPacket.setText(String.format(mContext.getString(R.string.open_red_packet), mRedPacketModel.getRedPacketCount() + "")); } - if (IMLoginManager.get(mContext).getUserInfo().anchorUserType() && mContext instanceof LiveRyAnchorActivity) { + if (IMLoginManager.get(mContext).getUserInfo().anchorUserType() && mContext instanceof LiveSwAnchorActivity) { anchorTimeHandler.removeCallbacks(anchorTimeRunnable); anchorTimeHandler.post(anchorTimeRunnable); } @@ -1751,7 +1751,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void onViewClicks() { - if (!(mContext instanceof LiveRyAnchorActivity)) { + if (!(mContext instanceof LiveSwAnchorActivity)) { LiveNetManager.get(mContext) .redPacketInfo(mLiveUid, redPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { @Override @@ -1885,7 +1885,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (d_pk_view != null) { d_pk_view.setVisibility(View.GONE); } - if (LivePushTxViewHolder.mTRTCCloud != null || LivePushRyViewHolder.rtcRoom != null) { + if (LivePushTxViewHolder.mTRTCCloud != null || LivePushSwViewHolder.rtcRoom != null) { fans_btn.setVisibility(View.GONE); } mRedVal.setVisibility(View.GONE); @@ -3029,7 +3029,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis bundle.putString("toUid", toUid); bundle.putInt("isAttention", isAttention); bundle.putBoolean("isLive", isAnchor); - bundle.putBoolean("SBW", !(mContext instanceof LiveRyAnchorActivity)); + bundle.putBoolean("SBW", !(mContext instanceof LiveSwAnchorActivity)); giftWallDialog.setArguments(bundle); giftWallDialog.show(((AbsActivity) mContext).getSupportFragmentManager(), "GiftWallDialog"); @@ -3387,7 +3387,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis //直播间 粉丝排行榜 openMedalRankWindow(); } else if (i == R.id.btn_guard) { - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); } else if (i == R.id.btn_red_pack) { ((LiveActivity) mContext).openRedPackListWindow(); @@ -3395,13 +3395,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ((LiveActivity) mContext).openPrizePoolWindow(); } else if (i == R.id.user_more) { MobclickAgent.onEvent(mContext, "live_room_audience_list", "直播间上面点观众列表按钮"); - ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity); } else if (i == R.id.hot_btn) { - ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity); } else if (i == R.id.noble_seat) { MobclickAgent.onEvent(mContext, "live_room_noble", "贵族按钮"); - ((LiveActivity) mContext).openUserMoreListWindow(1, false, true, mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, true, mContext instanceof LiveSwAnchorActivity); } else if (i == R.id.btn_close) { // if (sudGameMin!=null&&sudGameMin.getVisibility()==View.VISIBLE) { // new XPopup.Builder(mContext) @@ -3434,7 +3434,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } else if (i == R.id.user_guard) { MobclickAgent.onEvent(mContext, "anchor_avatar_guard", "守护按钮"); // ((LiveActivity) mContext).openUserMoreListWindow(2, true); - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); } if (i == R.id.lt_trickery) { showTrickeryDialog(); @@ -3459,7 +3459,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis * @param in 展示的view */ private void changeMsgView(View out, View in) { - if (mContext instanceof LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity) { return; } if (in.getVisibility() == View.VISIBLE) { @@ -3669,23 +3669,23 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ((LiveAudienceActivity) mContext).setBackIndex(1); ((LiveAnchorActivity) mContext).onBackPressed(); } - } else if (mContext instanceof LiveRyAnchorActivity) { + } else if (mContext instanceof LiveSwAnchorActivity) { if (forAct == 1) { //是否关注0==没关注 if (isAttention == 0) { if (isStayRoomfive) { showFollowDialog(mNameText, mAvatarUrl, mContext); } else { - LiveRyAnchorActivity.backIndex = 1; - ((LiveRyAnchorActivity) mContext).onBackPressed(); + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); } } else { - LiveRyAnchorActivity.backIndex = 1; - ((LiveRyAnchorActivity) mContext).onBackPressed(); + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); } } else { - LiveRyAnchorActivity.backIndex = 1; - ((LiveRyAnchorActivity) mContext).onBackPressed(); + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); } } } @@ -4840,7 +4840,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis lt_trickster_salvation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mContext instanceof LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity) { dialog.dismiss(); return; } @@ -4883,7 +4883,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java index 828916dd6..b57c75d7a 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -1,8 +1,8 @@ package com.yunbao.live.views; import static com.yunbao.live.activity.LiveActivity.mLiveUid; -import static com.yunbao.live.activity.LiveRyAnchorActivity.PKing; -import static com.yunbao.live.activity.LiveRyAnchorActivity.pk_nub; +import static com.yunbao.live.activity.LiveSwAnchorActivity.PKing; +import static com.yunbao.live.activity.LiveSwAnchorActivity.pk_nub; import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.START_MESSAGE; import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.WISH_LIST_UPDATE; @@ -44,6 +44,7 @@ import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.activity.ZhuangBanActivity; import com.yunbao.live.bean.WishlistModel; import com.yunbao.live.dialog.LiveHDDialogFragment; @@ -173,7 +174,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (yaoqing.size() < 3) { if (PKing == false) { - ((LiveRyAnchorActivity) mContext).openLinkMicAnchorWindow(true); + ((LiveSwAnchorActivity) mContext).openLinkMicAnchorWindow(true); } else { ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); } @@ -241,7 +242,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 关闭直播 */ private void close() { - ((LiveRyAnchorActivity) mContext).closeLive(); + ((LiveSwAnchorActivity) mContext).closeLive(); } @Override @@ -257,7 +258,11 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (mBtnFunction != null) { mBtnFunction.setImageDrawable(mDrawable1); } - ((LiveRyAnchorActivity) mContext).showFunctionDialog(); + if(mContext instanceof LiveSwAnchorActivity){ + ((LiveSwAnchorActivity) mContext).showFunctionDialog(); + }else{ + ((LiveRyAnchorActivity) mContext).showFunctionDialog(); + } } /** @@ -290,7 +295,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 发起主播连麦pk */ private void applyLinkMicPk() { - ((LiveRyAnchorActivity) mContext).applyLinkMicPk(); + ((LiveSwAnchorActivity) mContext).applyLinkMicPk(); } public void setLinkMicEnable(boolean linkMicEnable) { @@ -516,7 +521,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { bundle.putString("url", htmlUrl.toString()); LiveHDDialogFragment fragment = new LiveHDDialogFragment(); fragment.setArguments(bundle); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); } } } @@ -577,7 +582,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { bundle.putString("url", htmlUrl.toString()); LiveHDDialogFragment fragment = new LiveHDDialogFragment(); fragment.setArguments(bundle); - fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); } } } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 1ac6894bc..a7605dbca 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -105,10 +105,12 @@ import com.yunbao.live.event.LiveOpenSuccessEvent; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; +import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; import com.yunbao.live.socket.SocketClient; import com.yunbao.live.socket.SocketMessageListener; import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; +import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.utils.LiveImDeletUtil; @@ -155,7 +157,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //侧滑布局 // private DrawerLayout drawerLayout; //直播间拆分布局 - public LivePlayRyViewHolder mLivePlayViewHolder; + public LiveRoomPlayViewHolder mLivePlayViewHolder; + //头部布局 public LiveRoomViewHolder mLiveRoomViewHolder; //底部布局 @@ -169,14 +172,20 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //主播与主播连麦逻辑 private LiveLinkMicAnchorPresenter mLiveLinkMicAnchorPresenter; //主播与主播PK逻辑 + private LiveSwLinkMicPkPresenter mLiveSwLinkMicPkPresenter; + private LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter; + + //直播间的类型 普通 密码 门票 计时等 private int mLiveType; //收费价格,计时收费每次扣费的值 private int mLiveTypeVal; //直播结束页面 private LiveEndViewHolder mLiveEndViewHolder; + private SocketSwClient mSocketSwClient; private SocketRyClient mSocketRyClient; + private SocketClient mSocketClient; private String mDanmuPrice;//弹幕价格 private int mSocketUserType;//socket用户类型 30 普通用户 40 管理员 50 主播 60超管 @@ -215,6 +224,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public static PortraitLiveManager portraitLiveManager; private static int waitShowTopBannerTime = 6000; + private boolean isSw; + public PortraitLiveManager setQuitF(boolean quitF) { isQuitF = quitF; return this; @@ -265,6 +276,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public PortraitLiveManager(Activity context, Intent intent) { this.mContext = context; this.mIntent = intent; + isSw = intent.getBooleanExtra("isSw", false); liveImDeletUtil = new LiveImDeletUtil(); portraitLiveManager = this; ininView(); @@ -333,7 +345,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override - public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk) { + public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk, boolean isSw) { isEnterRoom = false; MobclickAgent.onEvent(mContext, "live_room_chat_list", "滑动直播间聊天列表"); openParametersModel = new OpenParametersModel(); @@ -351,6 +363,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter.release(); mLiveRyLinkMicPkPresenter = null; } + + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.clearData(); + mLiveSwLinkMicPkPresenter.release(); + mLiveSwLinkMicPkPresenter = null; + } OpenAdManager.getInstance().dismiss(); mLiveBean = data; mLiveSDK = liveSdk; @@ -369,13 +387,23 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe liveHandler.removeCallbacks(loadRunnableGone); liveHandler.removeCallbacks(loadTimeoutRunnableGone); if (mLivePlayViewHolder == null) { - mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); + if (isSw) { + mLivePlayViewHolder = new LivePlaySwViewHolder(mContext, playContainer, 1); + } else { + mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); + } mLivePlayViewHolder.initSwEngine(mLiveBean.getUid()); mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager()); mLiveAudienceViewHolder = new LiveAudienceViewHolder(mContext, mContainer); mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, mLiveAudienceViewHolder.getContentView()); mLiveLinkMicAnchorPresenter = new LiveLinkMicAnchorPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, null); - mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + if (isSw) { + mLiveSwLinkMicPkPresenter = new LiveSwLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + } else { + mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + } + + mLivePlayViewHolder.addToParent(); mLivePlayViewHolder.subscribeActivityLifeCycle(); mLivePlayViewHolder.setLoadViewListener(new LiveRoomPlayViewHolder.LoadingListener() { @@ -394,16 +422,22 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveLinkMicPresenter.setLiveSdk(mLiveSDK); mLiveLinkMicAnchorPresenter.setLiveSdk(mLiveSDK); } - - if (mLiveRyLinkMicPkPresenter == null) { - mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + if (isSw) { + if (mLiveSwLinkMicPkPresenter == null) { + mLiveSwLinkMicPkPresenter = new LiveSwLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + } + } else { + if (mLiveRyLinkMicPkPresenter == null) { + mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); + } } + //去除主播离开画面 if (LivePlayKsyViewHolder.leave != null) { LivePlayKsyViewHolder.leave.setVisibility(View.GONE); } - if (LivePlayRyViewHolder.leave != null) { - LivePlayRyViewHolder.leave.setVisibility(View.GONE); + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.GONE); } //直播间背景 @@ -438,8 +472,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.clearGuardIcon(); mLiveRoomViewHolder.clearChat(); mLiveRoomViewHolder.releaseGift(); - mLiveRyLinkMicPkPresenter.setLiveUid(data.getUid(), ""); - mSocketRyClient = new SocketRyClient(mLiveBean.getUid(), PortraitLiveManager.this, mContext); + if (isSw) { + mLiveSwLinkMicPkPresenter.setLiveUid(data.getUid(), ""); + } else { + mLiveRyLinkMicPkPresenter.setLiveUid(data.getUid(), ""); + } + + if (isSw) { + mSocketSwClient = new SocketSwClient(mLiveBean.getUid(), PortraitLiveManager.this, mContext); + } else { + mSocketRyClient = new SocketRyClient(mLiveBean.getUid(), PortraitLiveManager.this, mContext); + } if (mLiveLinkMicPresenter != null) { mLiveLinkMicPresenter.setSocketClient(mSocketClient); } @@ -616,8 +659,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } if (leave == 1) { - if (LivePlayRyViewHolder.leave != null) { - LivePlayRyViewHolder.leave.setVisibility(View.VISIBLE); + if (LivePlaySwViewHolder.leave != null) { + LivePlaySwViewHolder.leave.setVisibility(View.VISIBLE); } } //判断是否有连麦,要显示连麦窗口 @@ -644,17 +687,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } } - if(mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")){ - JSONArray array = pkInfo.getJSONArray("userlist"); + if (mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")) { + JSONArray array = pkInfo.getJSONArray("userlist"); //判断是否是多人连麦 - if(array.size()>0){//多人連麥 + if (array.size() > 0) {//多人連麥 if (mLivePlayViewHolder != null) { List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { UserBean drPkbean = new UserBean(); DrPkbean drPkbean1 = new DrPkbean(); JSONObject da = array.getJSONObject(j); - if(!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))){ + if (!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))) { drPkbean.setId(String.valueOf(da.getIntValue("id"))); drPkbean1.setId(da.getIntValue("id")); drPkbean1.setUser_nicename(da.getString("user_nicename")); @@ -664,9 +707,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } //mLivePlayViewHolder.setDrPkView(drPkbeans); } - }else{//单人连麦 - LivePkMicModel connection_info = data.getEnterRoomInfo().getConnectionInfo(); - if(!StringUtil.isEmpty(connection_info.getPkuid())){ + } else {//单人连麦 + LivePkMicModel connection_info = data.getEnterRoomInfo().getConnectionInfo(); + if (!StringUtil.isEmpty(connection_info.getPkuid())) { mPkUid = connection_info.getPkuid(); mLivePlayViewHolder.setPkView(connection_info.getPkuid()); } @@ -692,9 +735,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } }; linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000); - } - mLiveRyLinkMicPkPresenter.onEnterRoomPkStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("pk_time"), livePKUserListBean); + if (isSw) { + mLiveSwLinkMicPkPresenter.onEnterRoomPkStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("pk_time"), livePKUserListBean); + } else { + mLiveRyLinkMicPkPresenter.onEnterRoomPkStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("pk_time"), livePKUserListBean); + } } else if (!pkInfo.getString("end_pk_time").equals("0")) { if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.pkHandler = true; @@ -708,7 +754,11 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //pk排名数据 LivePKUserListBean livePKUserListBean = JSON.parseObject(pkInfo.getString("pk_top_users"), LivePKUserListBean.class); - mLiveRyLinkMicPkPresenter.onEnterRoomCFStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("end_pk_time"), livePKUserListBean); + if (isSw) { + mLiveSwLinkMicPkPresenter.onEnterRoomCFStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("end_pk_time"), livePKUserListBean); + } else { + mLiveRyLinkMicPkPresenter.onEnterRoomCFStart(pkUid, pkInfo.getLongValue("pk_gift_liveuid"), pkInfo.getLongValue("pk_gift_pkuid"), pkInfo.getIntValue("end_pk_time"), livePKUserListBean); + } } else { if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.initPkRank(null); @@ -720,13 +770,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.initPkRank(null); } if (mLivePlayViewHolder != null) { - JSONArray array = pkInfo.getJSONArray("userlist"); - List drPkbeans = new ArrayList<>(); + JSONArray array = pkInfo.getJSONArray("userlist"); + List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { UserBean userBean = new UserBean(); DrPkbean drPkbean = new DrPkbean(); JSONObject da = array.getJSONObject(j); - if(!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))){ + if (!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))) { userBean.setId(String.valueOf(da.getIntValue("id"))); drPkbean.setId(da.getIntValue("id")); drPkbean.setUser_nicename(da.getString("user_nicename")); @@ -837,10 +887,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } - - - public void loadTimeoutRunnableGone(){ - if(liveHandler!=null){ + public void loadTimeoutRunnableGone() { + if (liveHandler != null) { liveHandler.postDelayed(loadTimeoutRunnableGone, 1_000); } } @@ -871,11 +919,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter.clearData(); mLiveRyLinkMicPkPresenter.release(); } + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.clearData(); + mLiveSwLinkMicPkPresenter.release(); + } + mLiveAudienceViewHolder = null; mLiveRoomViewHolder = null; mLiveLinkMicPresenter = null; mLiveLinkMicAnchorPresenter = null; mLiveRyLinkMicPkPresenter = null; + mLiveSwLinkMicPkPresenter = null; mLivePlayViewHolder = null; } @@ -902,6 +956,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mSocketRyClient.disConnect(); mSocketRyClient = null; } + if (mSocketSwClient != null) { + mSocketSwClient.disConnect(); + mSocketSwClient = null; + } if (mSocketClient != null) { mSocketClient.disConnect(); mSocketClient = null; @@ -1360,7 +1418,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public void showAllServerNotifyFFGGGD(AllServerNotifyFFGGGDJANEvent notifyFFGGGDJANEvent) { if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.showAllServerNotifyFFGGGD(notifyFFGGGDJANEvent,true); + mLiveRoomViewHolder.showAllServerNotifyFFGGGD(notifyFFGGGDJANEvent, true); } } @@ -1392,20 +1450,34 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onSendGiftPk(long leftGift, long rightGift, LivePKUserListBean bean) { - - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); - + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); + } + } else { + if (mLiveRyLinkMicPkPresenter != null) { + mLiveRyLinkMicPkPresenter.onPkProgressChanged(leftGift, rightGift, bean); + } } } @Override public void onEndPk(long leftUid, long rightUid, long left, long right, LivePKUserListBean bean) { - if (mLiveRyLinkMicPkPresenter != null) { - if (mLiveUid.equals(leftUid + "")) { - mLiveRyLinkMicPkPresenter.onPkProgressEnd(left, right, bean); - } else { - mLiveRyLinkMicPkPresenter.onPkProgressEnd(right, left, bean); + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null) { + if (mLiveUid.equals(leftUid + "")) { + mLiveSwLinkMicPkPresenter.onPkProgressEnd(left, right, bean); + } else { + mLiveSwLinkMicPkPresenter.onPkProgressEnd(right, left, bean); + } + } + } else { + if (mLiveRyLinkMicPkPresenter != null) { + if (mLiveUid.equals(leftUid + "")) { + mLiveRyLinkMicPkPresenter.onPkProgressEnd(left, right, bean); + } else { + mLiveRyLinkMicPkPresenter.onPkProgressEnd(right, left, bean); + } } } } @@ -1610,7 +1682,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public void onLinkDRMicPKToUser(UserBean u) { L.eSw("onLinkDRMicPKToUser(UserBean u)PortraitLiveManager"); mLivePlayViewHolder.setDrMicInfo(u); - } @Override @@ -1619,7 +1690,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //mLivePlayViewHolder.setDrMicInfo(u); } - /** * 主播与主播PK 所有人收到PK开始的回调 */ @@ -1645,12 +1715,20 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } }; - - if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.pkHandler = true; - mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); - linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000);//3秒后执行Runnable中的run方法 + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.pkHandler = true; + mLiveSwLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); + linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000);//3秒后执行Runnable中的run方法 + } + } else { + if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.pkHandler = true; + mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); + linkMicPkStartHandler.postDelayed(linkMicPkStartRunnable, 4000);//3秒后执行Runnable中的run方法 + } } + if (mLivePlayViewHolder != null) { mLivePlayViewHolder.setLiveBeanLandscape(1); } @@ -1673,11 +1751,19 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onLinkMicPkClose(int i) { - - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkClose(i); - if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.resetViewGone(); + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkClose(i); + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.resetViewGone(); + } + } + } else { + if (mLiveRyLinkMicPkPresenter != null) { + mLiveRyLinkMicPkPresenter.onLinkMicPkClose(i); + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.resetViewGone(); + } } } if (mLiveRoomViewHolder != null) { @@ -1706,9 +1792,16 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onLinkMicPkEnd(String winUid) { - if (mLiveRyLinkMicPkPresenter != null) { - mLiveRyLinkMicPkPresenter.onLinkMicPkEnd(winUid); - //mLiveRoomViewHolder.setDelOtherInfo(); + if (isSw) { + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.onLinkMicPkEnd(winUid); + //mLiveRoomViewHolder.setDelOtherInfo(); + } + } else { + if (mLiveRyLinkMicPkPresenter != null) { + mLiveRyLinkMicPkPresenter.onLinkMicPkEnd(winUid); + //mLiveRoomViewHolder.setDelOtherInfo(); + } } } @@ -1900,9 +1993,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (mSocketRyClient != null) { mSocketRyClient.disConnect(); + mSocketRyClient = null; } - mSocketRyClient = null; + if (mSocketSwClient != null) { + mSocketSwClient.disConnect(); + mSocketSwClient = null; + } //结束播放 if (mLivePlayViewHolder != null) { @@ -2210,7 +2307,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe * @param time */ public void upDataPkScore(JSONArray pkScores, int time) { - L.eSw("upDataPkScore"+time); + L.eSw("upDataPkScore" + time); if (mLiveRoomViewHolder != null) { String liveId = mLiveBean.getUid(); JSONObject liveModel = null; diff --git a/live/src/main/java/com/yunbao/live/views/SidebarViewHoler.java b/live/src/main/java/com/yunbao/live/views/SidebarViewHoler.java index 78561638b..4e3a49980 100644 --- a/live/src/main/java/com/yunbao/live/views/SidebarViewHoler.java +++ b/live/src/main/java/com/yunbao/live/views/SidebarViewHoler.java @@ -102,8 +102,8 @@ public class SidebarViewHoler extends RecyclerView.ViewHolder { } new LiveRoomCheckLivePresenter(itemView.getContext(), liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index f7c596dc0..91b5d0346 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -1,41 +1,18 @@ + android:layout_height="match_parent"> - - - - - - - - - + app:use_controller="false" + android:layout_height="match_parent" /> - + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="@dimen/live_top"> - - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/view_live_push_ry.xml b/live/src/main/res/layout/view_live_push_ry.xml index bb814174d..1931cc742 100644 --- a/live/src/main/res/layout/view_live_push_ry.xml +++ b/live/src/main/res/layout/view_live_push_ry.xml @@ -1,10 +1,10 @@ + + + android:orientation="horizontal"> + android:background="@mipmap/live_icon_vacancy" /> + android:orientation="horizontal"> + android:background="@mipmap/live_icon_vacancy" /> @@ -93,12 +91,16 @@ + + android:layout_height="match_parent"> + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/main/src/main/java/com/yunbao/main/activity/EntryActivity.java b/main/src/main/java/com/yunbao/main/activity/EntryActivity.java index eca8ddae0..e21d251eb 100644 --- a/main/src/main/java/com/yunbao/main/activity/EntryActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/EntryActivity.java @@ -671,8 +671,8 @@ public class EntryActivity extends AppCompatActivity { } new LiveRoomCheckLivePresenter(activity, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/LiveClassActivity.java b/main/src/main/java/com/yunbao/main/activity/LiveClassActivity.java index 58ec570ab..1a7d0bfad 100644 --- a/main/src/main/java/com/yunbao/main/activity/LiveClassActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/LiveClassActivity.java @@ -118,8 +118,8 @@ public class LiveClassActivity extends AbsActivity implements OnItemClickListene public void watchLive(LiveBean liveBean, int position) { new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/LoginActivity.java b/main/src/main/java/com/yunbao/main/activity/LoginActivity.java index dbefee6f7..1ad1c7c07 100644 --- a/main/src/main/java/com/yunbao/main/activity/LoginActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/LoginActivity.java @@ -257,8 +257,8 @@ public class LoginActivity extends AbsActivity { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index eb8874263..c035f6c70 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -271,8 +271,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override @@ -485,8 +485,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override @@ -1069,9 +1069,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene public void watchLive(LiveBean liveBean, String key, int position) { new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { MobclickAgent.onEvent(mContext, "home_page_enter_room", "首页点击直播间"); - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity.java b/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity.java index 751ae514d..729e0323d 100644 --- a/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity.java @@ -261,7 +261,7 @@ public class MyWebViewActivity extends AbsActivity { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (LiveRoomViewHolder.mHandler != null) { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); @@ -274,7 +274,7 @@ public class MyWebViewActivity extends AbsActivity { } EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal)).setLiveEnd(true)); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } } diff --git a/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity2.java b/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity2.java index 07b6ddd1c..c5f3c15d1 100644 --- a/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity2.java +++ b/main/src/main/java/com/yunbao/main/activity/MyWebViewActivity2.java @@ -230,7 +230,7 @@ public class MyWebViewActivity2 extends AbsActivity { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (LiveRoomViewHolder.mHandler != null) { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); @@ -243,7 +243,7 @@ public class MyWebViewActivity2 extends AbsActivity { } EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal))); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } } diff --git a/main/src/main/java/com/yunbao/main/activity/RegisterActivity.java b/main/src/main/java/com/yunbao/main/activity/RegisterActivity.java index 11491f72a..82fcf0718 100644 --- a/main/src/main/java/com/yunbao/main/activity/RegisterActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/RegisterActivity.java @@ -528,8 +528,8 @@ public class RegisterActivity extends AbsActivity { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); NoviceInstructorManager.get(mContext).setFrist(false); } diff --git a/main/src/main/java/com/yunbao/main/activity/SearchActivity.java b/main/src/main/java/com/yunbao/main/activity/SearchActivity.java index 1ef37dbfe..6a02c7f26 100644 --- a/main/src/main/java/com/yunbao/main/activity/SearchActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/SearchActivity.java @@ -176,8 +176,8 @@ public class SearchActivity extends AbsActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/WeekWebViewActivity.java b/main/src/main/java/com/yunbao/main/activity/WeekWebViewActivity.java index cd1fb5682..f0096f634 100644 --- a/main/src/main/java/com/yunbao/main/activity/WeekWebViewActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/WeekWebViewActivity.java @@ -154,8 +154,8 @@ public class WeekWebViewActivity extends AbsActivity { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java b/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java index bf2ac850f..927b5b02c 100644 --- a/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java @@ -391,7 +391,7 @@ public class ZhuangBanActivity extends AbsActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } @@ -400,7 +400,7 @@ public class ZhuangBanActivity extends AbsActivity { return; } - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); finish(); } diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchAdapter.java index d3ff13be0..a371e3f93 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchAdapter.java @@ -203,8 +203,8 @@ public class SearchAdapter extends RefreshAdapter { } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/dialog/AnchorStartLiveNotifyDialog.java b/main/src/main/java/com/yunbao/main/dialog/AnchorStartLiveNotifyDialog.java index a1237951c..c0177c0cb 100644 --- a/main/src/main/java/com/yunbao/main/dialog/AnchorStartLiveNotifyDialog.java +++ b/main/src/main/java/com/yunbao/main/dialog/AnchorStartLiveNotifyDialog.java @@ -77,8 +77,8 @@ public class AnchorStartLiveNotifyDialog extends AbsDialogPositionPopupWindow { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java b/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java index f099229a7..4a19c2e2c 100644 --- a/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java +++ b/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java @@ -39,6 +39,7 @@ import com.yunbao.common.utils.WordUtil; import com.yunbao.live.LiveConfig; import com.yunbao.live.activity.LiveAnchorActivity; import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.bean.LiveKsyConfigBean; import com.yunbao.main.R; import com.yunbao.main.activity.MyWebViewActivity; @@ -227,13 +228,23 @@ public class MainStartDialogFragment extends AbsDialogFragment implements View.O @Override public void onSuccess(int code, String msg, String[] info1) { try { - JSONObject obj = JSON.parseObject(info[0]); - JSONObject obj1 = JSON.parseObject(info1[0]); - if (obj1.getString("is_rong").equals("1")) { - LiveRyAnchorActivity.forward(mContext, obj.getIntValue("live_sdk"), JSON.parseObject(obj.getString("android"), LiveKsyConfigBean.class)); - } else { - LiveAnchorActivity.forward(mContext, obj.getIntValue("live_sdk"), JSON.parseObject(obj.getString("android"), LiveKsyConfigBean.class)); - } + LiveHttpUtil.getIsSw(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] infos) { + JSONObject obj = JSON.parseObject(info[0]); + JSONObject obj1 = JSON.parseObject(info1[0]); + try { + code = 200; + if(code==201){ //声网 + LiveSwAnchorActivity.forward(mContext, Constants.LIVE_SDK_SW, JSON.parseObject(obj.getString("android"), LiveKsyConfigBean.class)); + }else if(code==200){//融云 + LiveRyAnchorActivity.forward(mContext, obj.getIntValue("live_sdk"), JSON.parseObject(obj.getString("android"), LiveKsyConfigBean.class)); + } + } catch (Exception e) { + + } + } + }); } catch (Exception e) { } diff --git a/main/src/main/java/com/yunbao/main/dialog/OneLoginDialog.java b/main/src/main/java/com/yunbao/main/dialog/OneLoginDialog.java index 46bd068f6..fc6406056 100644 --- a/main/src/main/java/com/yunbao/main/dialog/OneLoginDialog.java +++ b/main/src/main/java/com/yunbao/main/dialog/OneLoginDialog.java @@ -150,11 +150,11 @@ public class OneLoginDialog extends AbsDialogFragment { new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); NoviceInstructorManager.get(mContext).setFrist(false); } diff --git a/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java b/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java index ae5f07953..cd8d7f804 100644 --- a/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java @@ -262,8 +262,8 @@ public class MainHomeCommunityFragment extends BaseFragment { new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java b/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java index 410000ee8..6b8d7226b 100644 --- a/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java @@ -170,8 +170,8 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override @@ -406,8 +406,8 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index 48c711896..81fe8df52 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -402,8 +402,8 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement liveBean.setParams(gotoRoomKey); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override @@ -497,7 +497,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (LiveRoomViewHolder.mHandler != null) { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); @@ -509,7 +509,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement } EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal))); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } } diff --git a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java index f71385345..f8a17638a 100644 --- a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java @@ -515,8 +515,8 @@ public class MainMessageViewHolder extends AbsMainViewHolder { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw); } @Override diff --git a/main/src/main/java/com/yunbao/main/views/UserHomeViewHolder2.java b/main/src/main/java/com/yunbao/main/views/UserHomeViewHolder2.java index 7f691cf41..e4a566c88 100644 --- a/main/src/main/java/com/yunbao/main/views/UserHomeViewHolder2.java +++ b/main/src/main/java/com/yunbao/main/views/UserHomeViewHolder2.java @@ -794,7 +794,7 @@ public class UserHomeViewHolder2 extends AbsLivePageViewHolder implements LiveSh } new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (mFromLiveRoom) { if (MicStatusManager.getInstance().isMic(liveUid)) { @@ -804,7 +804,7 @@ public class UserHomeViewHolder2 extends AbsLivePageViewHolder implements LiveSh ((UserHomeActivity) mContext).onBackPressed(); EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal))); } else { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveTypeVal), Integer.parseInt(liveSdk),isSw); } } From 0b218157d2ae1d64d800a20165270db1f2894e77 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 18 May 2024 18:27:38 +0800 Subject: [PATCH 18/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?AB=E9=9D=A2]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 52 +- .../yunbao/live/activity/LiveActivity.java | 127 ++- .../live/activity/LiveAnchorActivity.java | 2 +- .../live/activity/LiveRyAnchorActivity.java | 18 +- .../live/activity/LiveSwAnchorActivity.java | 10 +- .../dialog/LiveOldUserDialogFragment.java | 5 +- .../yunbao/live/socket/SocketRyChatUtil.java | 50 +- .../yunbao/live/socket/SocketSwChatUtil.java | 793 ++++++++++++++++++ .../live/views/LiveReadyRyViewHolder.java | 23 +- .../yunbao/live/views/LiveRoomViewHolder.java | 43 +- .../live/views/LiveRyAnchorViewHolder.java | 12 +- .../live/views/PortraitLiveManager.java | 32 +- 12 files changed, 1052 insertions(+), 115 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index cb28e9277..5f79704f4 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -50,6 +50,7 @@ import com.yunbao.common.utils.GoogleUtils; import com.yunbao.common.utils.L; import com.yunbao.common.utils.SpUtil; import com.yunbao.live.socket.SocketReceiveBean; +import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.utils.LiveImDeletUtil; import com.yunbao.live.views.PortraitLiveManager; @@ -198,7 +199,7 @@ public class AppContext extends CommonAppContext { RongcloudIMManager.addRongcloudIMOnReceiveMessageListener(new RongIMClient.OnReceiveMessageWrapperListener() { @Override public boolean onReceived(io.rong.imlib.model.Message message, int i, boolean b, boolean b1) { - Log.e("wewe", message.getConversationType() + "112121"); + Log.e("wewe", message.getConversationType() + "112121 "+message.getContent()); MessageIMManager.get(sInstance).getSystemForRongcloud(message); //融云直播间聊天 Message msg = Message.obtain(); @@ -209,23 +210,42 @@ public class AppContext extends CommonAppContext { if (content.getContent().contains("_method_")) { msg.obj = content.getContent(); //观众页面 - if (SocketSwClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { - SocketSwClient.mSocketHandler.sendMessage(msg); - } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 - SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); - JSONObject map = received.getMsg().getJSONObject(0); - sendStartAnchorLive(map); - } else if (message.getTargetId().contains("v")) { - String contentJson = ((TextMessage) message.getContent()).getContent(); - Log.e("wewe", contentJson); - SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); - Bus.get().post(sudGameSocketImEvent); + if(SocketRyClient.mSocketHandler!=null){ + if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { + SocketRyClient.mSocketHandler.sendMessage(msg); + } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 + SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); + JSONObject map = received.getMsg().getJSONObject(0); + sendStartAnchorLive(map); + } else if (message.getTargetId().contains("v")) { + String contentJson = ((TextMessage) message.getContent()).getContent(); + Log.e("wewe", contentJson); + SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); + Bus.get().post(sudGameSocketImEvent); + } + //主播页面 + if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.sendMessage(msg); + } } - //主播页面 - if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.sendMessage(msg); + if(SocketSwClient.mSocketHandler!=null){ + if (SocketSwClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { + SocketSwClient.mSocketHandler.sendMessage(msg); + } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 + SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); + JSONObject map = received.getMsg().getJSONObject(0); + sendStartAnchorLive(map); + } else if (message.getTargetId().contains("v")) { + String contentJson = ((TextMessage) message.getContent()).getContent(); + Log.e("wewe", contentJson); + SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); + Bus.get().post(sudGameSocketImEvent); + } + //主播页面 + if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.sendMessage(msg); + } } - } else if (message.getConversationType() == Conversation.ConversationType.PRIVATE) {//私聊信息 EventBus.getDefault().post(message); } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index 0cf2630cc..c420e5a5e 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -88,6 +88,7 @@ import com.yunbao.live.socket.SocketClient; import com.yunbao.live.socket.SocketMessageListener; import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; +import com.yunbao.live.socket.SocketSwChatUtil; import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.utils.LoadDian9TuUtil; import com.yunbao.live.views.AbsLiveViewHolder; @@ -166,7 +167,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL protected List mAudienceList = new ArrayList<>(); protected LiveMicAnchorDialogFragment.OnMicListener micListener = null; - public boolean isSw; + public static boolean isSw; @Override protected void main() { @@ -241,13 +242,22 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL // if (isRy == false) { // SocketChatUtil.sendUpdateVotesMessage(mLiveUid, mLiveTypeVal, 1); // } else { - SocketRyChatUtil.sendUpdateVotesMessage(mLiveUid, mLiveTypeVal, 1); + if(isSw){ + SocketSwChatUtil.sendUpdateVotesMessage(mLiveUid, mLiveTypeVal, 1); + }else{ + SocketRyChatUtil.sendUpdateVotesMessage(mLiveUid, mLiveTypeVal, 1); + } + // } } // if (isRy == false) { // SocketChatUtil.getFakeFans(mLiveUid); // } else { - SocketRyChatUtil.getFakeFans(mLiveUid); + if(isSw){ + SocketSwChatUtil.getFakeFans(mLiveUid); + }else{ + SocketRyChatUtil.getFakeFans(mLiveUid); + } // } } } @@ -1004,7 +1014,11 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL onCoinChanged(coin); } String[] data = new String[]{obj.getString("barragetoken")}; - SocketRyChatUtil.sendDanmuMessage(mLiveUid, contents, obj.getIntValue("level_fans")); + if(isSw){ + SocketSwChatUtil.sendDanmuMessage(mLiveUid, contents, obj.getIntValue("level_fans")); + }else{ + SocketRyChatUtil.sendDanmuMessage(mLiveUid, contents, obj.getIntValue("level_fans")); + } } else if (code == 1001) { DialogUitl.showSimpleDialog(mContext, msg, new DialogUitl.SimpleCallback2() { @Override @@ -1038,15 +1052,44 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL } } int guardType = mLiveGuardInfo != null ? mLiveGuardInfo.getMyGuardType() : Constants.GUARD_TYPE_NONE; - SocketRyChatUtil.sendChatMessage(mLiveUid, content, IMLoginManager.get(mContext).getUserInfo().anchorUserType(), mSocketUserType, guardType, atUserID, atUserName); + if(isSw){ + SocketSwChatUtil.sendChatMessage(mLiveUid, content, IMLoginManager.get(mContext).getUserInfo().anchorUserType(), mSocketUserType, guardType, atUserID, atUserName); + }else{ + SocketRyChatUtil.sendChatMessage(mLiveUid, content, IMLoginManager.get(mContext).getUserInfo().anchorUserType(), mSocketUserType, guardType, atUserID, atUserName); + } + } + /** + * 发 系统 消息 融云 + */ + public static void sendSystemMessageSw(String content) { + if(isSw){ + SocketSwChatUtil.sendSystemMessage(mLiveUid, content); + }else{ + SocketRyChatUtil.sendSystemMessage(mLiveUid, content); + } + } + + /** + * 发 系统 消息 声网 + */ + public static void sendSystemMessageRy(String content) { + if(isSw){ + SocketSwChatUtil.sendSystemMessage(mLiveUid, content); + }else{ + SocketRyChatUtil.sendSystemMessage(mLiveUid, content); + } } /** * 发 系统 消息 */ - public static void sendSystemMessage(String content) { - SocketRyChatUtil.sendSystemMessage(mLiveUid, content); + public void sendSystemMessage(String content) { + if(isSw){ + SocketSwChatUtil.sendSystemMessage(mLiveUid, content); + }else{ + SocketRyChatUtil.sendSystemMessage(mLiveUid, content); + } } @@ -1055,7 +1098,11 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL */ public void sendGiftMessage(LiveGiftBean giftBean, String giftToken, String ancherName, String by) { int guardType = mLiveGuardInfo != null ? mLiveGuardInfo.getMyGuardType() : Constants.GUARD_TYPE_NONE; - SocketRyChatUtil.sendGiftMessage(giftBean.getType(), giftToken, mLiveUid, ancherName, guardType, by); + if(isSw){ + SocketSwChatUtil.sendGiftMessage(giftBean.getType(), giftToken, mLiveUid, ancherName, guardType, by); + }else{ + SocketRyChatUtil.sendGiftMessage(giftBean.getType(), giftToken, mLiveUid, ancherName, guardType, by); + } } @@ -1063,28 +1110,44 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL * 主播或管理员踢人 */ public void kickUser(String toUid, String toName) { - SocketRyChatUtil.sendKickMessage(mLiveUid, toUid, toName); + if(isSw){ + SocketSwChatUtil.sendKickMessage(mLiveUid, toUid, toName); + }else{ + SocketRyChatUtil.sendKickMessage(mLiveUid, toUid, toName); + } } /** * 禁言 */ public void setShutUp(String toUid, String toName, int type) { - SocketRyChatUtil.sendShutUpMessage(mLiveUid, toUid, toName, type); + if(isSw){ + SocketSwChatUtil.sendShutUpMessage(mLiveUid, toUid, toName, type); + }else{ + SocketRyChatUtil.sendShutUpMessage(mLiveUid, toUid, toName, type); + } } /** * 期限禁言 */ public void setShutUp(String toUid, String toName, int type, int time) { - SocketRyChatUtil.sendShutUpMessage(mLiveUid, toUid, toName, type, time); + if(isSw){ + SocketSwChatUtil.sendShutUpMessage(mLiveUid, toUid, toName, type, time); + }else{ + SocketRyChatUtil.sendShutUpMessage(mLiveUid, toUid, toName, type, time); + } } /** * 设置或取消管理员消息 */ public void sendSetAdminMessage(int action, String toUid, String toName) { - SocketRyChatUtil.sendSetAdminMessage(mLiveUid, action, toUid, toName); + if(isSw){ + SocketSwChatUtil.sendSetAdminMessage(mLiveUid, action, toUid, toName); + }else{ + SocketRyChatUtil.sendSetAdminMessage(mLiveUid, action, toUid, toName); + } } @@ -1092,14 +1155,24 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL * 超管关闭直播间 */ public void superCloseRoom() { - SocketRyChatUtil.superCloseRoom(mLiveUid); + if(isSw){ + SocketSwChatUtil.superCloseRoom(mLiveUid); + }else{ + SocketRyChatUtil.superCloseRoom(mLiveUid); + } + } /** * 更新主播映票数 */ public void sendUpdateVotesMessage(int deltaVal) { - SocketRyChatUtil.sendUpdateVotesMessage(mLiveUid, deltaVal); + if(isSw){ + SocketSwChatUtil.sendUpdateVotesMessage(mLiveUid, deltaVal); + }else{ + SocketRyChatUtil.sendUpdateVotesMessage(mLiveUid, deltaVal); + } + } @@ -1107,12 +1180,21 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL * 发送购买守护成功消息 */ public void sendBuyGuardMessage(String votes, int guardNum, int guardType) { - SocketRyChatUtil.sendBuyGuardMessage(mLiveUid, votes, guardNum, guardType); + if(isSw){ + SocketSwChatUtil.sendBuyGuardMessage(mLiveUid, votes, guardNum, guardType); + }else{ + SocketRyChatUtil.sendBuyGuardMessage(mLiveUid, votes, guardNum, guardType); + } + } public void sendBuyGuardMessage2(String votes, int guardNum, int guardType, String ancherName, String liveId) { if (guardType != 1) { - SocketRyChatUtil.sendBuyGuardMessage2(mLiveUid, votes, guardNum, guardType, ancherName, liveId); + if(isSw){ + SocketSwChatUtil.sendBuyGuardMessage2(mLiveUid, votes, guardNum, guardType, ancherName, liveId); + }else{ + SocketRyChatUtil.sendBuyGuardMessage2(mLiveUid, votes, guardNum, guardType, ancherName, liveId); + } } } @@ -1120,7 +1202,11 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL * 发送发红包成功消息 */ public void sendRedPackMessage() { - SocketRyChatUtil.sendRedPackMessage(mLiveUid); + if(isSw){ + SocketSwChatUtil.sendRedPackMessage(mLiveUid); + }else{ + SocketRyChatUtil.sendRedPackMessage(mLiveUid); + } } @@ -1707,7 +1793,12 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL micListener = fragment.getMicListener(); fragment.setMicQueueList(mMicQueueList); fragment.setAudienceList(mAudienceList); - fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveMicAnchorDialogFragment"); + if(isSw){ + fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveMicAnchorDialogFragment"); + }else{ + fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveMicAnchorDialogFragment"); + } + } /** diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java index e8b571e2c..250c1ffbe 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java @@ -471,7 +471,7 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic } mLiveReadyViewHolder = null; if (mLiveRoomViewHolder == null) { - mLiveRoomViewHolder = new LiveRoomViewHolder(false, 2, mContext, mContainer, (GifImageView) findViewById(R.id.gift_gif), (SVGAImageView) findViewById(R.id.gift_svga), mContainerWrap, getWindowManager()); + mLiveRoomViewHolder = new LiveRoomViewHolder(false, 2, mContext, mContainer, (GifImageView) findViewById(R.id.gift_gif), (SVGAImageView) findViewById(R.id.gift_svga), mContainerWrap, getWindowManager(),false); mLiveRoomViewHolder.addToParent(); mLiveRoomViewHolder.subscribeActivityLifeCycle(); mLiveRoomViewHolder.setLiveInfo(mLiveUid, mStream, obj.getIntValue("userlist_time") * 1000); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index f92e9fe4a..77684997f 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -104,10 +104,8 @@ import com.yunbao.live.music.LiveMusicDialogFragment; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; -import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; -import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.views.LiveEndViewHolder; import com.yunbao.live.views.LiveMusicViewHolder; @@ -554,7 +552,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(BitmapUtil.getInstance().convertMirror(resource), rect); - sendSystemMessage(mContext.getString(R.string.live_anchor_leave)); + sendSystemMessageRy(mContext.getString(R.string.live_anchor_leave)); } @Override @@ -567,7 +565,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl leave_img.setVisibility(View.GONE); // 清除水印 boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(null, rect); - sendSystemMessage(mContext.getString(R.string.live_anchor_come_back)); + sendSystemMessageRy(mContext.getString(R.string.live_anchor_come_back)); } HttpClient.getInstance().get("Live.isLeave", "Live.isLeave") @@ -788,7 +786,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl } mLiveReadyViewHolder = null; if (mLiveRoomViewHolder == null) { - mLiveRoomViewHolder = new LiveRoomViewHolder(true, 2, mContext, mContainer, (GifImageView) findViewById(R.id.gift_gif), (SVGAImageView) findViewById(R.id.gift_svga), mContainerWrap, getWindowManager()); + mLiveRoomViewHolder = new LiveRoomViewHolder(true, 2, mContext, mContainer, (GifImageView) findViewById(R.id.gift_gif), (SVGAImageView) findViewById(R.id.gift_svga), mContainerWrap, getWindowManager(),isSw); mLiveRoomViewHolder.setManager(manager); mLiveRoomViewHolder.addToParent(); mLiveRoomViewHolder.subscribeActivityLifeCycle(); @@ -974,7 +972,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl JSONObject obj = JSON.parseObject(info[0]); JSONObject datas = obj.getJSONObject("data"); try { - SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid, mSocketSwClient); + SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid); } catch (Exception e) { e.printStackTrace(); } @@ -1060,8 +1058,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl mLivePushViewHolder = null; mLiveLinkMicPresenter = null; //断开socket - if (mSocketSwClient != null) { - mSocketSwClient.disConnect(); + if (mSocketRyClient != null) { + mSocketRyClient.disConnect(); } super.release(); } @@ -1891,8 +1889,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl @Override public void onSuccess(Message message) { - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index bad0121c0..c3e5a1265 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -101,7 +101,7 @@ import com.yunbao.live.music.LiveMusicDialogFragment; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveSwLinkMicPkPresenter; -import com.yunbao.live.socket.SocketRyChatUtil; +import com.yunbao.live.socket.SocketSwChatUtil; import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.views.LiveEndViewHolder; @@ -536,7 +536,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(BitmapUtil.getInstance().convertMirror(resource), rect); - sendSystemMessage(mContext.getString(R.string.live_anchor_leave)); + sendSystemMessageSw(mContext.getString(R.string.live_anchor_leave)); } @Override @@ -549,7 +549,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl leave_img.setVisibility(View.GONE); // 清除水印 boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(null, rect); - sendSystemMessage(mContext.getString(R.string.live_anchor_come_back)); + sendSystemMessageSw(mContext.getString(R.string.live_anchor_come_back)); } HttpClient.getInstance().get("Live.isLeave", "Live.isLeave") @@ -770,7 +770,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl } mLiveReadyViewHolder = null; if (mLiveRoomViewHolder == null) { - mLiveRoomViewHolder = new LiveRoomViewHolder(true, 2, mContext, mContainer, (GifImageView) findViewById(R.id.gift_gif), (SVGAImageView) findViewById(R.id.gift_svga), mContainerWrap, getWindowManager()); + mLiveRoomViewHolder = new LiveRoomViewHolder(true, 2, mContext, mContainer, (GifImageView) findViewById(R.id.gift_gif), (SVGAImageView) findViewById(R.id.gift_svga), mContainerWrap, getWindowManager(),isSw); mLiveRoomViewHolder.setManager(manager); mLiveRoomViewHolder.addToParent(); mLiveRoomViewHolder.subscribeActivityLifeCycle(); @@ -956,7 +956,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl JSONObject obj = JSON.parseObject(info[0]); JSONObject datas = obj.getJSONObject("data"); try { - SocketRyChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid, mSocketSwClient); + SocketSwChatUtil.closeLive(datas.getString("votes"), datas.getString("length"), datas.getString("nums"), mLiveUid); } catch (Exception e) { e.printStackTrace(); } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java index c2aff85c3..a6e869833 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveOldUserDialogFragment.java @@ -47,6 +47,8 @@ import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveReportActivity; +import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.bean.ImpressBean; import com.yunbao.live.custom.MyTextView; import com.yunbao.live.utils.LiveTextRender; @@ -551,8 +553,7 @@ public class LiveOldUserDialogFragment extends AbsDialogFragment implements View mFollowImage.setImageDrawable(mFollowing ? mFollowDrawable : mUnFollowDrawable); } if (isAttention == 1 && mLiveUid.equals(mToUid)) {//关注了主播 - ((LiveActivity) mContext).sendSystemMessage( - CommonAppConfig.getInstance().getUserBean().getUserNiceName() + mContext.getString(R.string.live_follow_anchor)); + ((LiveActivity) mContext).sendSystemMessage(CommonAppConfig.getInstance().getUserBean().getUserNiceName() + mContext.getString(R.string.live_follow_anchor)); } } }; diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java index f451fb908..4811ff0a2 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java @@ -34,7 +34,7 @@ import io.rong.message.TextMessage; public class SocketRyChatUtil { //关闭直播 - public static void closeLive(final String votes, final String length, final String nums, final String mLiveUid, SocketSwClient client) { + public static void closeLive(final String votes, final String length, final String nums, final String mLiveUid) { UserBean u = CommonAppConfig.getInstance().getUserBean(); final SocketSendBean msg = new SocketSendBean() .param("_method_", Constants.SOCKET_LIVE_END) @@ -64,8 +64,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketSwClient.mSocketHandler != null) - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -128,8 +128,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } LiveNetManager.get(CommonAppContext.sInstance) .addChatCount(LiveActivity.mStream, new com.yunbao.common.http.base.HttpCallback() { @@ -214,8 +214,8 @@ public class SocketRyChatUtil { } } }); - if (SocketSwClient.mSocketHandler != null) - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -263,8 +263,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -400,8 +400,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -470,8 +470,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -517,8 +517,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -554,8 +554,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -597,8 +597,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketSwClient.mSocketHandler != null) - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -634,8 +634,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -674,8 +674,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -778,8 +778,8 @@ public class SocketRyChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java new file mode 100644 index 000000000..c1f1228e6 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java @@ -0,0 +1,793 @@ +package com.yunbao.live.socket; + + +import android.util.Log; + +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.CommonAppContext; +import com.yunbao.common.Constants; +import com.yunbao.common.bean.HttpCallbackModel; +import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.LiveHttpUtil; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveActivity; + +import org.greenrobot.eventbus.EventBus; + +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; +import io.rong.message.TextMessage; + +/** + * Created by cxf on 2018/10/9. + * 直播间发言 + */ + +public class SocketSwChatUtil { + + //关闭直播 + public static void closeLive(final String votes, final String length, final String nums, final String mLiveUid) { + UserBean u = CommonAppConfig.getInstance().getUserBean(); + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_LIVE_END) + .param("action", 18) + .param("msgtype", 1) + .param("equipment", "app") + .param("uname", u.getUserNiceName()) + .param("uid", u.getId()) + .param("length", length) + .param("votes", votes) + .param("nums", nums) + .param("roomnum", u.getId()) + .param("ct", "直播关闭"); + msg.create(); + + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + if (SocketRyClient.mSocketHandler != null) + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + + } + + /** + * 发言 + */ + public static void sendChatMessage(String mLiveUid, String content, boolean isAnchor, int userType, int guardType, String atUserID, String atUserName) { + UserBean u = CommonAppConfig.getInstance().getUserBean(); + IMLoginModel model = IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getUserInfo(); + if (u == null) { + return; + } + + final SocketSendBean msg = + new SocketSendBean() + .param("_method_", Constants.SOCKET_SEND_MSG) + .param("action", 0) + .param("msgtype", 2) + .param("usertype", userType) + .param("isAnchor", isAnchor ? 1 : 0) + .param("level", u.getLevel()) + .param("uname", u.getUserNiceName()) + .param("bubble", u.getDress().getBubble()) + .param("medal_honor", u.getMedal_no_display_src()) + .param("medal", u.getDress().getMedal()) + .param("medal_new", u.getDress().getMedal_new()) + .param("uid", u.getId()) + .param("liangname", u.getGoodName()) + .param("vip_type", u.getVip().getType()) + .param("guard_type", IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getGuardType()) + .param("medal_name", u.getMedalName()) + .param("medal_level", model.getMedalLevel()) + .param("good_num", u.getGoodnum()) + .param("ct", content) + .param("noble_id", String.valueOf(model.getNobleId())) + .param("contentColor", String.valueOf(model.getContentColor())) + .param("startColor", String.valueOf(model.getStartColor())) + .param("endColor", String.valueOf(model.getEndColor())) + .param("atUserName", String.valueOf(atUserName)) + .param("atUserID", String.valueOf(atUserID)); + msg.create(); + + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + LiveNetManager.get(CommonAppContext.sInstance) + .addChatCount(LiveActivity.mStream, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + + } + + @Override + public void onError(String error) { + + } + }); + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + if (errorCode.code == 23408) { + ToastUtil.show(WordUtil.isNewZh() ? "您已被禁言" : "You have been banned"); + } else { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" + errorCode.code : "I'm sorry! An error occurred:" + errorCode.code); + } + } + }); + + } + + /** + * 点亮 + */ + public static void sendLightMessage(final String mLiveUid, int heart, int guardType) { + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_SEND_MSG) + .param("action", 0) + .param("msgtype", 2) + .param("level", u.getLevel()) + .param("uname", u.getUserNiceName()) + .param("uid", u.getId()) + .param("liangname", u.getGoodName()) + .param("vip_type", u.getVip().getType()) + .param("medal_honor", u.getMedal_no_display_src()) + .param("heart", heart) + .param("bubble", u.getDress().getBubble()) + .param("medal", u.getDress().getMedal()) + .param("medal_new", u.getDress().getMedal_new()) + .param("guard_type", IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getGuardType()) + .param("medal_name", u.getMedalName()) + .param("medal_level", u.getMedalLevel()) + .param("good_num", u.getGoodnum()) + .param("ct", WordUtil.getNewString(R.string.live_lighted)); + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + LiveHttpUtil.sendZAN(mLiveUid + "", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + EventBus.getDefault().post("stop_svga_new_user_double"); + } + }); + + LiveHttpUtil.setFrontTask("illumine", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + EventBus.getDefault().post("stop_svga_new_user_double1"); + } + } + }); + if (SocketRyClient.mSocketHandler != null) + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + } + + + /** + * 发送弹幕消息 + */ + public static void sendDanmuMessage(String mLiveUid, String danmuToken) { + sendDanmuMessage(mLiveUid, danmuToken, 0); + } + + public static void sendDanmuMessage(String mLiveUid, String danmuToken, int fansLevel) { + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_SEND_BARRAGE) + .param("action", 7) + .param("msgtype", 1) + .param("level", u.getLevel()) + .param("uname", u.getUserNiceName()) + .param("uid", u.getId()) + .param("uhead", u.getAvatar()) + .param("fansLevel", fansLevel) + .param("ct", danmuToken); + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + if (errorCode.code == 23408) { + ToastUtil.show(WordUtil.isNewZh() ? "您已被禁言" : "You have been banned"); + } else { + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + } + }); + + } + + + /** + * 发送礼物消息 + */ + public static void sendGiftMessage(int giftType, String giftToken, String liveUid, int guard_type, String by) { + + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_SEND_GIFT) + .param("action", 0) + .param("msgtype", 1) + .param("level", u.getLevel()) + .param("uname", u.getUserNiceName()) + .param("uid", u.getId()) + .param("uhead", u.getAvatar()) + .param("evensend", giftType) + .param("liangname", u.getGoodName()) + .param("vip_type", u.getVip().getType()) + .param("ct", giftToken) + .param("bubble", u.getDress().getBubble()) + .param("medal", u.getDress().getMedal()) + .param("medal_new", u.getDress().getMedal_new()) + .param("medal_name", u.getMedalName()) + .param("medal_level", u.getMedalLevel()) + .param("guard_type", guard_type + "") + .param("medal_honor", u.getMedal_no_display_src()) + .param("good_num", u.getGoodnum()) + .param("roomnum", liveUid); + + msg.create(); + LiveHttpUtil.sendGiftMsg(by, liveUid, msg.mResult.toString(), new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i("tag", "禮物im"); + } + }); + + } + + /** + * 发送礼物消息 增加主播名字 + */ + public static void sendGiftMessage(int giftType, String giftToken, String liveUid, String ancherName, int guard_type, String by) { + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_SEND_GIFT) + .param("action", 0) + .param("msgtype", 1) + .param("level", u.getLevel()) + .param("uname", u.getUserNiceName()) + .param("uid", u.getId()) + .param("uhead", u.getAvatar()) + .param("evensend", giftType) + .param("liangname", u.getGoodName()) + .param("vip_type", u.getVip().getType()) + .param("bubble", u.getDress().getBubble()) + .param("medal", u.getDress().getMedal()) + .param("medal_new", u.getDress().getMedal_new()) + .param("ct", giftToken) + .param("ancherName", ancherName) + .param("medal_name", u.getMedalName()) + .param("medal_level", u.getMedalLevel()) + .param("guard_type", guard_type + "") + .param("medal_honor", u.getMedal_no_display_src()) + .param("good_num", u.getGoodnum()) + .param("roomnum", liveUid); + + msg.create(); + + LiveHttpUtil.sendGiftMsg(by, liveUid, msg.mResult.toString(), new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i("tag", "禮物im"); + } + }); + + } + + /** + * 主播或管理员 踢人 + */ + public static void sendKickMessage(String mLiveUid, String toUid, String toName) { + + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_KICK) + .param("action", 2) + .param("msgtype", 4) + .param("level", u.getLevel()) + .param("uname", u.getUserNiceName()) + .param("uid", u.getId()) + .param("touid", toUid) + .param("toname", toName) + .param("ct", toName + "被踢出房間(Kicked out of the room)"); + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + } + + + /** + * 主播或管理员 禁言 + */ + public static void sendShutUpMessage(String mLiveUid, String toUid, String toName, int type) { + sendShutUpMessage(mLiveUid, toUid, toName, type, 0); + } + + /** + * 主播或管理员 禁言 + * + * @param time 禁言时间 1~60 + */ + public static void sendShutUpMessage(String mLiveUid, String toUid, String toName, int type, int time) { + + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + String ct = ""; + switch (type) { + case 0: + ct = "被永久禁言(Forbidden forever)"; + break; + case 1: + ct = "被本場禁言(Forbidden by this scene)"; + break; + case 2: + ct = String.format("被禁言%s分鐘", time + "") + "(" + String.format("Forbidden by %s min", time + "") + ")"; + break; + } + + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_SHUT_UP) + .param("action", 1) + .param("msgtype", 4) + .param("level", u.getLevel()) + .param("uname", u.getUserNiceName()) + .param("uid", u.getId()) + .param("touid", toUid) + .param("toname", toName) + .param("time", time) + .param("ct", toName + ct); + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + + } + + /** + * 设置或取消管理员消息 + */ + public static void sendSetAdminMessage(String mLiveUid, int action, String toUid, String toName) { + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + String s = action == 1 ? "被設為管理員(Set as Administrator)" : "被取消管理員(Cancelled administrator)"; + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_SET_ADMIN) + .param("action", action) + .param("msgtype", 1) + .param("uname", u.getUserNiceName()) + .param("uid", u.getId()) + .param("touid", toUid) + .param("toname", toName) + .param("ct", toName + " " + s); + + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + + } + + /** + * 超管关闭直播间 + */ + public static void superCloseRoom(String mLiveUid) { + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_STOP_LIVE) + .param("action", 19) + .param("msgtype", 1) + .param("ct", ""); + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + } + + /** + * 发系统消息 + */ + public static void sendSystemMessage(String mLiveUid, String content) { + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_SYSTEM) + .param("action", 13) + .param("msgtype", 4) + .param("level", u.getLevel()) + .param("uname", u.getUserNiceName()) + .param("uid", u.getId()) + .param("ct", content); + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + if (SocketRyClient.mSocketHandler != null) + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + } + + + /** + * 获取僵尸粉 + */ + public static void getFakeFans(String mLiveUid) { + + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_FAKE_FANS) + .param("action", "") + .param("msgtype", ""); + + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + } + + + /** + * 更新主播映票数 + */ + public static void sendUpdateVotesMessage(String mLiveUid, int votes, int first) { + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_UPDATE_VOTES) + .param("action", 1) + .param("msgtype", 26) + .param("votes", votes) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("isfirst", first) + .param("ct", ""); + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + + } + + /** + * 更新主播映票数 + */ + public static void sendUpdateVotesMessage(String mLiveUid, int votes) { + sendUpdateVotesMessage(mLiveUid, votes, 0); + } + + /** + * 发送购买守护成功消息 + */ + public static void sendBuyGuardMessage(String mLiveUid, String votes, int guardNum, int guardType) { + + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_BUY_GUARD) + .param("action", 0) + .param("msgtype", 0) + .param("uid", u.getId()) + .param("bubble", u.getDress().getBubble()) + .param("medal", u.getDress().getMedal()) + .param("medal_new", u.getDress().getMedal_new()) + .param("uname", u.getUserNiceName()) + .param("uhead", u.getAvatar()) + .param("votestotal", votes) + .param("guard_nums", guardNum) + .param("guard_type", IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getGuardType()); + msg.create(); + + } + + public static void sendBuyGuardMessage2(String mLiveUid, String votes, int guardNum, + int guardType, String ancherName, String liveId) { + + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_BUY_GUARD) + .param("action", 0) + .param("msgtype", 0) + .param("uid", u.getId()) + .param("uname", u.getUserNiceName()) + .param("uhead", u.getAvatar()) + .param("votestotal", votes) + .param("guard_nums", guardNum) + .param("ancherName", ancherName) + .param("liveuid", liveId) + .param("bubble", u.getDress().getBubble()) + .param("medal", u.getDress().getMedal()) + .param("medal_new", u.getDress().getMedal_new()) + .param("guard_type", IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getGuardType()); + msg.create(); + + } + + /** + * 发送发红包成功消息 + */ + public static void sendRedPackMessage(String mLiveUid) { + + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u == null) { + return; + } + final SocketSendBean msg = new SocketSendBean() + .param("_method_", Constants.SOCKET_RED_PACK) + .param("action", 0) + .param("msgtype", 0) + .param("uid", u.getId()) + .param("uname", u.getUserNiceName()) + .param("ct", CommonAppContext.sInstance.getBaseContext().getString(R.string.red_pack_22) + ); + msg.create(); + String targetId = "g" + mLiveUid; + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + Message message = Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + } + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + + } + }); + } + +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java index 79ea38d0f..8d44d530f 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveReadyRyViewHolder.java @@ -34,7 +34,8 @@ import com.yunbao.common.views.AbsViewHolder; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveChooseClassActivity; -import com.yunbao.live.activity.LiveSwAnchorActivity; +import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.adapter.LiveReadyShareAdapter; import com.yunbao.common.bean.LiveRoomTypeBean; import com.yunbao.live.dialog.LiveRoomTypeDialogFragment; @@ -123,7 +124,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick @Override public void beforeCamera() { - ((LiveSwAnchorActivity) mContext).beforeCamera(); + ((LiveRyAnchorActivity) mContext).beforeCamera(); } @Override @@ -218,8 +219,8 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick public void openWishListWindow() { LiveWishListDialogFragment fragment = new LiveWishListDialogFragment(); - if (mContext instanceof LiveSwAnchorActivity){ - fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "RY"); + if (mContext instanceof LiveRyAnchorActivity){ + fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "RY"); } } @@ -281,14 +282,14 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick * 切换镜头 */ private void toggleCamera() { - ((LiveSwAnchorActivity) mContext).toggleCamera(); + ((LiveRyAnchorActivity) mContext).toggleCamera(); } /** * 关闭 */ private void close() { - ((LiveSwAnchorActivity) mContext).endLives(); + ((LiveRyAnchorActivity) mContext).endLives(); } /** @@ -309,7 +310,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick * 设置美颜 */ private void beauty() { - ((LiveSwAnchorActivity) mContext).beauty(); + ((LiveRyAnchorActivity) mContext).beauty(); // Intent intent = new Intent(mContext, Beauty360Activity3.class); // mContext.startActivity(intent); @@ -324,7 +325,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick LiveRoomTypeDialogFragment fragment = new LiveRoomTypeDialogFragment(); fragment.setArguments(bundle); fragment.setCallback(mLiveTypeCallback); - fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); + fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveRoomTypeDialogFragment"); } /** @@ -398,7 +399,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick mLiveTimeCoin = coin; } }); - fragment.show(((LiveSwAnchorActivity) mContext).getSupportFragmentManager(), "LiveTimeDialogFragment"); + fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveTimeDialogFragment"); } public void hide() { @@ -418,7 +419,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick * 点击开始直播按钮 */ private void startLive() { - boolean startPreview = ((LiveSwAnchorActivity) mContext).isStartPreview(); + boolean startPreview = ((LiveRyAnchorActivity) mContext).isStartPreview(); // if (!startPreview) { // ToastUtil.show(R.string.please_wait); // return; @@ -480,7 +481,7 @@ public class LiveReadyRyViewHolder extends AbsViewHolder implements View.OnClick final CommonAppConfig appConfig = CommonAppConfig.getInstance(); UserBean u = appConfig.getUserBean(); - ((LiveSwAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); + ((LiveRyAnchorActivity) mContext).startLiveSuccess(info[0], mLiveType, mLiveTypeVal); // // RongChatRoomClient.getInstance().joinChatRoom("g" + appConfig.getUid(), -1, new IRongCoreCallback.OperationCallback() { // @Override diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 2be05e28d..a301dd5e9 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -148,6 +148,7 @@ import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAnchorActivity; import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.activity.ZhuangBanActivity; import com.yunbao.live.adapter.LiveChatAdapter; @@ -399,6 +400,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis private View quick_gift_reminder; private int guardType = 0; + private static boolean isSw; + public LiveRoomViewHolder setGuardType(int guardType) { this.guardType = guardType; return this; @@ -545,8 +548,9 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } - public LiveRoomViewHolder(boolean isRys, int forActivity, Context context, ViewGroup parentView, GifImageView gifImageView, SVGAImageView svgaImageView, ViewGroup liveGiftPrizePoolContainer, WindowManager windowManager) { + public LiveRoomViewHolder(boolean isRys, int forActivity, Context context, ViewGroup parentView, GifImageView gifImageView, SVGAImageView svgaImageView, ViewGroup liveGiftPrizePoolContainer, WindowManager windowManager,boolean isSw) { super(context, parentView); + this.isSw =isSw; Contexts = context; this.forAct = forActivity; // this.isRy = isRys; @@ -3607,8 +3611,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void callback(Integer isAttention) { if (isAttention == 1) { - LiveActivity.sendSystemMessage( - CommonAppConfig.getInstance().getUserBean().getUserNiceName() + Contexts.getString(R.string.live_follow_anchor)); + if(isSw){ + LiveActivity.sendSystemMessageSw( + CommonAppConfig.getInstance().getUserBean().getUserNiceName() + Contexts.getString(R.string.live_follow_anchor)); + }else{ + LiveActivity.sendSystemMessageRy( + CommonAppConfig.getInstance().getUserBean().getUserNiceName() + Contexts.getString(R.string.live_follow_anchor)); + } } } }); @@ -3676,16 +3685,32 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (isStayRoomfive) { showFollowDialog(mNameText, mAvatarUrl, mContext); } else { - LiveSwAnchorActivity.backIndex = 1; - ((LiveSwAnchorActivity) mContext).onBackPressed(); + + if(mContext instanceof LiveSwAnchorActivity){ + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); + }else{ + LiveRyAnchorActivity.backIndex = 1; + ((LiveRyAnchorActivity) mContext).onBackPressed(); + } } } else { - LiveSwAnchorActivity.backIndex = 1; - ((LiveSwAnchorActivity) mContext).onBackPressed(); + if(mContext instanceof LiveSwAnchorActivity){ + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); + }else{ + LiveRyAnchorActivity.backIndex = 1; + ((LiveRyAnchorActivity) mContext).onBackPressed(); + } } } else { - LiveSwAnchorActivity.backIndex = 1; - ((LiveSwAnchorActivity) mContext).onBackPressed(); + if(mContext instanceof LiveSwAnchorActivity){ + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); + }else{ + LiveRyAnchorActivity.backIndex = 1; + ((LiveRyAnchorActivity) mContext).onBackPressed(); + } } } } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java index b57c75d7a..4a9f40083 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -174,7 +174,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (yaoqing.size() < 3) { if (PKing == false) { - ((LiveSwAnchorActivity) mContext).openLinkMicAnchorWindow(true); + ((LiveRyAnchorActivity) mContext).openLinkMicAnchorWindow(true); } else { ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); } @@ -242,7 +242,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 关闭直播 */ private void close() { - ((LiveSwAnchorActivity) mContext).closeLive(); + ((LiveRyAnchorActivity) mContext).closeLive(); } @Override @@ -258,11 +258,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (mBtnFunction != null) { mBtnFunction.setImageDrawable(mDrawable1); } - if(mContext instanceof LiveSwAnchorActivity){ - ((LiveSwAnchorActivity) mContext).showFunctionDialog(); - }else{ - ((LiveRyAnchorActivity) mContext).showFunctionDialog(); - } + ((LiveRyAnchorActivity) mContext).showFunctionDialog(); } /** @@ -295,7 +291,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 发起主播连麦pk */ private void applyLinkMicPk() { - ((LiveSwAnchorActivity) mContext).applyLinkMicPk(); + ((LiveRyAnchorActivity) mContext).applyLinkMicPk(); } public void setLinkMicEnable(boolean linkMicEnable) { diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index a7605dbca..f0603a13e 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -110,6 +110,7 @@ import com.yunbao.live.socket.SocketClient; import com.yunbao.live.socket.SocketMessageListener; import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; +import com.yunbao.live.socket.SocketSwChatUtil; import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.utils.LiveImDeletUtil; @@ -393,7 +394,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); } mLivePlayViewHolder.initSwEngine(mLiveBean.getUid()); - mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager()); + mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager(),isSw); mLiveAudienceViewHolder = new LiveAudienceViewHolder(mContext, mContainer); mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, mLiveAudienceViewHolder.getContentView()); mLiveLinkMicAnchorPresenter = new LiveLinkMicAnchorPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, null); @@ -1240,11 +1241,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (!mFirstConnectSocket) { mFirstConnectSocket = true; if (mLiveType == Constants.LIVE_TYPE_PAY || mLiveType == Constants.LIVE_TYPE_TIME) { - - SocketRyChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal, 1); - + if(isSw){ + SocketSwChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal, 1); + }else{ + SocketRyChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal, 1); + } + } + if(isSw){ + SocketSwChatUtil.getFakeFans(mLiveBean.getUid()); + }else{ + SocketRyChatUtil.getFakeFans(mLiveBean.getUid()); } - SocketRyChatUtil.getFakeFans(mLiveBean.getUid()); } } } @@ -2117,8 +2124,11 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe MobclickAgent.onEvent(mContext, "live_room_light", "直播间点亮"); mLighted = true; int guardType = mLiveGuardInfo != null ? mLiveGuardInfo.getMyGuardType() : Constants.GUARD_TYPE_NONE; - SocketRyChatUtil.sendLightMessage(mLiveBean.getUid(), 1 + RandomUtil.nextInt(6), guardType); - + if(isSw){ + SocketSwChatUtil.sendLightMessage(mLiveBean.getUid(), 1 + RandomUtil.nextInt(6), guardType); + }else{ + SocketRyChatUtil.sendLightMessage(mLiveBean.getUid(), 1 + RandomUtil.nextInt(6), guardType); + } } if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.playLightAnim(); @@ -2176,9 +2186,11 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe * 更新主播映票数 */ public void sendUpdateVotesMessage() { - - SocketRyChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal); - + if(isSw){ + SocketSwChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal); + }else{ + SocketRyChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal); + } } public void onFollowEvent(FollowEvent e) { From 3167ab0be817db32bfc2997c298c4d1a56fd7717 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Mon, 20 May 2024 16:18:16 +0800 Subject: [PATCH 19/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E6=88=BF=E5=88=A4=E6=96=AD=E5=A3=B0=E7=BD=91?= =?UTF-8?q?=E6=88=96=E8=80=85=E8=9E=8D=E4=BA=91]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 37 +- .../com/yunbao/common/bean/ConfigBean.java | 22 + .../common/dialog/CreateSudGamePopup.java | 9 +- .../com/yunbao/common/event/SubGameEvent.java | 44 ++ .../manager/imrongcloud/GameRyMicManager.java | 559 ++++++++++++++ ...eMicManager.java => GameSwMicManager.java} | 4 +- .../com/yunbao/common/utils/RouteUtil.java | 15 +- .../common/views/SudGameListViewHolder.java | 15 +- live/src/main/AndroidManifest.xml | 5 +- .../yunbao/live/activity/LiveActivity.java | 1 - .../live/activity/SudRyGameActivity.java | 698 ++++++++++++++++++ ...meActivity.java => SudSwGameActivity.java} | 18 +- .../yunbao/live/views/LiveEndViewHolder.java | 10 +- .../yunbao/live/views/LiveRoomViewHolder.java | 38 +- .../live/views/LiveRyAnchorViewHolder.java | 25 +- .../main/views/MainHomeGameViewHolder.java | 4 +- 16 files changed, 1432 insertions(+), 72 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/event/SubGameEvent.java create mode 100644 common/src/main/java/com/yunbao/common/manager/imrongcloud/GameRyMicManager.java rename common/src/main/java/com/yunbao/common/manager/imrongcloud/{GameMicManager.java => GameSwMicManager.java} (99%) create mode 100644 live/src/main/java/com/yunbao/live/activity/SudRyGameActivity.java rename live/src/main/java/com/yunbao/live/activity/{SudGameActivity.java => SudSwGameActivity.java} (97%) diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 5f79704f4..b49b1b844 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -210,25 +210,7 @@ public class AppContext extends CommonAppContext { if (content.getContent().contains("_method_")) { msg.obj = content.getContent(); //观众页面 - if(SocketRyClient.mSocketHandler!=null){ - if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { - SocketRyClient.mSocketHandler.sendMessage(msg); - } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 - SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); - JSONObject map = received.getMsg().getJSONObject(0); - sendStartAnchorLive(map); - } else if (message.getTargetId().contains("v")) { - String contentJson = ((TextMessage) message.getContent()).getContent(); - Log.e("wewe", contentJson); - SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); - Bus.get().post(sudGameSocketImEvent); - } - //主播页面 - if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.sendMessage(msg); - } - } - if(SocketSwClient.mSocketHandler!=null){ + if(CommonAppConfig.getInstance().getConfig().isSw()){ if (SocketSwClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { SocketSwClient.mSocketHandler.sendMessage(msg); } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 @@ -245,6 +227,23 @@ public class AppContext extends CommonAppContext { if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketSwClient.mSocketHandler != null) { SocketSwClient.mSocketHandler.sendMessage(msg); } + }else{ + if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { + SocketRyClient.mSocketHandler.sendMessage(msg); + } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 + SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); + JSONObject map = received.getMsg().getJSONObject(0); + sendStartAnchorLive(map); + } else if (message.getTargetId().contains("v")) { + String contentJson = ((TextMessage) message.getContent()).getContent(); + Log.e("wewe", contentJson); + SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); + Bus.get().post(sudGameSocketImEvent); + } + //主播页面 + if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.sendMessage(msg); + } } } else if (message.getConversationType() == Conversation.ConversationType.PRIVATE) {//私聊信息 EventBus.getDefault().post(message); diff --git a/common/src/main/java/com/yunbao/common/bean/ConfigBean.java b/common/src/main/java/com/yunbao/common/bean/ConfigBean.java index a2a307dce..12fc45d1f 100644 --- a/common/src/main/java/com/yunbao/common/bean/ConfigBean.java +++ b/common/src/main/java/com/yunbao/common/bean/ConfigBean.java @@ -2,6 +2,7 @@ package com.yunbao.common.bean; import com.alibaba.fastjson.annotation.JSONField; import com.google.gson.annotations.SerializedName; +import com.yunbao.common.utils.StringUtil; import java.util.Arrays; import java.util.List; @@ -59,6 +60,9 @@ public class ConfigBean extends BaseModel { private String txPlayUgcLicenceUrl;//腾讯短视频鉴权 private String txVideoUgcKey; private String google_isup; + @SerializedName("sud_game_speech")//(0否,1是) + private String sudGameSpeech; + @SerializedName("is_return_user")//是否需要弹窗(0否,1是) private String isReturnUser=""; @SerializedName("popup_img_url")//弹窗图片地址 @@ -182,6 +186,24 @@ public class ConfigBean extends BaseModel { '}'; } + public boolean isSw(){ + if(StringUtil.isEmpty(sudGameSpeech)){ + return false; + }else if(sudGameSpeech.equals("1")){ + return true; + }else{ + return false; + } + } + + public String getSudGameSpeech() { + return sudGameSpeech; + } + + public void setSudGameSpeech(String sudGameSpeech) { + this.sudGameSpeech = sudGameSpeech; + } + @JSONField(name = "apk_ver") public String getVersion() { return version; diff --git a/common/src/main/java/com/yunbao/common/dialog/CreateSudGamePopup.java b/common/src/main/java/com/yunbao/common/dialog/CreateSudGamePopup.java index 8d080a086..479746a32 100644 --- a/common/src/main/java/com/yunbao/common/dialog/CreateSudGamePopup.java +++ b/common/src/main/java/com/yunbao/common/dialog/CreateSudGamePopup.java @@ -20,6 +20,7 @@ import com.google.gson.Gson; import com.lxj.xpopup.XPopup; import com.lxj.xpopup.core.BottomPopupView; import com.lxj.xpopup.enums.PopupPosition; +import com.yunbao.common.CommonAppConfig; import com.yunbao.common.R; import com.yunbao.common.bean.CreateSudRoomModel; import com.yunbao.common.bean.CustomSidebarChildModel; @@ -150,8 +151,6 @@ public class CreateSudGamePopup extends BottomPopupView { .asCustom(new SudGameListSelectPopup(getContext(), 4, customSidebarChildModels, interactionID)) .show(); } - - } }); ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.room_back), @@ -279,7 +278,11 @@ public class CreateSudGamePopup extends BottomPopupView { public void onSuccess(CreateSudRoomModel data) { if (isHome) { dialog.dismiss(); - RouteUtil.forwardSudGameActivity(new Gson().toJson(data),true,isHome); + if(CommonAppConfig.getInstance().getConfig().isSw()){ + RouteUtil.forwardSwSudGameActivity(new Gson().toJson(data),true,isHome); + }else{ + RouteUtil.forwardRySudGameActivity(new Gson().toJson(data),true,isHome); + } } else { Bus.get().post(new LiveSudGamePopupShowOrHideEvent().setType(0).setCreateSudRoomModel(data)); diff --git a/common/src/main/java/com/yunbao/common/event/SubGameEvent.java b/common/src/main/java/com/yunbao/common/event/SubGameEvent.java new file mode 100644 index 000000000..d88b9f54c --- /dev/null +++ b/common/src/main/java/com/yunbao/common/event/SubGameEvent.java @@ -0,0 +1,44 @@ +package com.yunbao.common.event; + +import com.yunbao.common.bean.HttpCallbackModel; + +public class SubGameEvent { + int type; + HttpCallbackModel model; + String dataJson; + + public SubGameEvent(int type, HttpCallbackModel model, String dataJson) { + this.type = type; + this.model = model; + this.dataJson = dataJson; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public HttpCallbackModel getModel() { + return model; + } + + public void setModel(HttpCallbackModel model) { + this.model = model; + } + + public String getDataJson() { + return dataJson; + } + + @Override + public String toString() { + return "SubGameEvent{" + + "type=" + type + + ", model=" + model + + ", dataJson='" + dataJson + '\'' + + '}'; + } +} diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameRyMicManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameRyMicManager.java new file mode 100644 index 000000000..d696513dd --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameRyMicManager.java @@ -0,0 +1,559 @@ +package com.yunbao.common.manager.imrongcloud; + +import android.content.Context; +import android.text.TextUtils; +import android.util.Log; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.yunbao.common.CommonAppContext; +import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.bean.SudGameChatImModel; +import com.yunbao.common.bean.SudGameUserModel; +import com.yunbao.common.event.SudGameSocketImEvent; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; + +import java.util.ArrayList; +import java.util.List; + +import cn.rongcloud.rtc.api.RCRTCEngine; +import cn.rongcloud.rtc.api.RCRTCRemoteUser; +import cn.rongcloud.rtc.api.RCRTCRoom; +import cn.rongcloud.rtc.api.RCRTCRoomConfig; +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; +import cn.rongcloud.rtc.api.stream.RCRTCInputStream; +import cn.rongcloud.rtc.base.RCRTCParamsType; +import cn.rongcloud.rtc.base.RCRTCRoomType; +import cn.rongcloud.rtc.base.RTCErrorCode; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.IRongCoreCallback; +import io.rong.imlib.IRongCoreEnum; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.chatroom.base.RongChatRoomClient; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; +import io.rong.message.TextMessage; + +public class GameRyMicManager { + MeetingCallback mMeetingCallback = null; + private RCRTCRoom mRtcRoom = null; + private String mRoomID = ""; + + + private final IRCRTCRoomEventsListener roomEventsListener = new IRCRTCRoomEventsListener() { + /** + * 房间内用户发布资源 + * + * @param rcrtcRemoteUser 远端用户 + * @param list 发布的资源 + */ + @Override + public void onRemoteUserPublishResource(RCRTCRemoteUser rcrtcRemoteUser, final List list) { +// subscribeAVStream(); + } + + @Override + public void onRemoteUserMuteAudio(RCRTCRemoteUser rcrtcRemoteUser, RCRTCInputStream rcrtcInputStream, boolean b) { + + } + + @Override + public void onRemoteUserMuteVideo(RCRTCRemoteUser rcrtcRemoteUser, RCRTCInputStream rcrtcInputStream, boolean b) { + } + + + @Override + public void onRemoteUserUnpublishResource(RCRTCRemoteUser rcrtcRemoteUser, List list) { + } + + /** + * 用户加入房间 + * + * @param rcrtcRemoteUser 远端用户 + */ + @Override + public void onUserJoined(final RCRTCRemoteUser rcrtcRemoteUser) { + try { + getView().onUserJoined(rcrtcRemoteUser); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + /** + * 用户离开房间 + * + * @param rcrtcRemoteUser 远端用户 + */ + @Override + public void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser) { + try { + getView().onUserLeft(rcrtcRemoteUser); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void onUserOffline(RCRTCRemoteUser rcrtcRemoteUser) { + } + + @Override + public void onPublishLiveStreams(List list) { + } + + @Override + public void onUnpublishLiveStreams(List list) { + } + + /** + * 自己退出房间。 例如断网退出等 + * @param i 状态码 + */ + @Override + public void onLeaveRoom(int i) { + } + }; + + protected MeetingCallback getView() { + if (mMeetingCallback == null) { + throw new IllegalStateException("view is not attached"); + } else { + return mMeetingCallback; + } + } + + public void attachView(MeetingCallback callback) { + mMeetingCallback = callback; + } + + public void detachView() { + mMeetingCallback = null; + } + + /** + * 主动订阅远端用户发布的流 + * 视频流需要用户设置用于显示载体的videoview + */ + public void subscribeAVStream() { + if (mRtcRoom == null || mRtcRoom.getRemoteUsers() == null) { + return; + } + final List inputStreams = new ArrayList<>(); + for (final RCRTCRemoteUser remoteUser : mRtcRoom.getRemoteUsers()) { + if (remoteUser.getStreams().size() == 0) { + continue; + } + + inputStreams.addAll(remoteUser.getStreams()); + + } + + if (inputStreams.size() == 0) { + return; + } + mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + + + try { + getView().onSubscribeSuccess(inputStreams); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + try { + getView().onSubscribeFailed(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + }); + } + + + public void refreshStreams(List personList) { + + final List inputStreams = new ArrayList<>(); + + for (SudGameUserModel sudGameUserModel : personList) { + List rcrtcRemoteUsers = mRtcRoom.getRemoteUsers(); + + for (RCRTCRemoteUser rcrtcRemoteUser : rcrtcRemoteUsers) { + if (TextUtils.equals(rcrtcRemoteUser.getUserId(), String.valueOf(sudGameUserModel.getId()))) { + for (RCRTCInputStream rcrtcInputStream : rcrtcRemoteUser.getStreams()) { + rcrtcInputStream.mute(sudGameUserModel.getMicStatus() == 3); + } + inputStreams.addAll(rcrtcRemoteUser.getStreams()); + } + } + } + if (inputStreams.size() == 0) { + return; + } + mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + + + try { + getView().onSubscribeSuccess(inputStreams); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + try { + getView().onSubscribeFailed(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + }); + } + + public void refreshStreams(String userID, boolean mute, int position) { + + final List inputStreams = new ArrayList<>(); + + List rcrtcRemoteUsers = mRtcRoom.getRemoteUsers(); + + for (RCRTCRemoteUser rcrtcRemoteUser : rcrtcRemoteUsers) { + if (TextUtils.equals(rcrtcRemoteUser.getUserId(), String.valueOf(userID))) { + for (RCRTCInputStream rcrtcInputStream : rcrtcRemoteUser.getStreams()) { + rcrtcInputStream.mute(mute); + } + inputStreams.addAll(rcrtcRemoteUser.getStreams()); + } + } + if (inputStreams.size() == 0) { + return; + } + mRtcRoom.getLocalUser().subscribeStreams(inputStreams, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + + + try { + getView().onSubscribeSuccess(userID, mute, position); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + try { + getView().onSubscribeFailed(userID); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + }); + } + + public void unPublishStreams() { + if (mRtcRoom == null) { + return; + } + mRtcRoom.getLocalUser().unpublishStream(RCRTCEngine.getInstance().getDefaultAudioStream(), new IRCRTCResultCallback() { + @Override + public void onSuccess() { + try { + getView().onUnPublishStreamsSuccess(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + try { + getView().onUnPublishStreamsFailed(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + }); + } + + /** + * 发布默认流 + */ + public void publishDefaultAVStream() { + if (mRtcRoom == null) { + return; + } + mRtcRoom.getLocalUser().publishStream(RCRTCEngine.getInstance().getDefaultAudioStream(), new IRCRTCResultCallback() { + @Override + public void onSuccess() { + try { + getView().onPublishSuccess(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + try { + getView().onPublishFailed(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + }); + } + + + /** + * 配置rtc sdk + */ + public void config(Context context) { + +// RCRTCConfig.Builder configBuilder = RCRTCConfig.Builder.create(); +// // 是否硬解码 +// configBuilder.enableHardwareDecoder(true); +// // 是否硬编码 +// configBuilder.enableHardwareEncoder(true); +// +// // init 需结合 uninit 使用,否则有些配置无法重新初始化 +// RCRTCEngine.getInstance().unInit(); +// RCRTCEngine.getInstance().init(context, configBuilder.build()); + +// RCRTCVideoStreamConfig.Builder videoConfigBuilder = RCRTCVideoStreamConfig.Builder.create(); +// // 设置分辨率 +// videoConfigBuilder.setVideoResolution(RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280); +// // 设置帧率 +// videoConfigBuilder.setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_30); +// /** +// * 设置最小码率,可根据分辨率RCRTCVideoResolution设置 +// * {@link RCRTCParamsType.RCRTCVideoResolution)} +// */ +// videoConfigBuilder.setMinRate(250); +// /** +// * 设置最大码率,可根据分辨率RCRTCVideoResolution设置 +// * {@link RCRTCParamsType.RCRTCVideoResolution)} +// */ +// videoConfigBuilder.setMaxRate(2200); +// RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(videoConfigBuilder.build()); + //打开扬声器。 + RCRTCEngine.getInstance().enableSpeaker(true); + // 启用耳返功能 + RCRTCEngine.getInstance().getDefaultAudioStream().enableEarMonitoring(true); + RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(false); + RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC_HIGH, RCRTCParamsType.AudioScenario.MUSIC_CHATROOM); + } + + public void joinRoom(String roomId, boolean imOff) { + mRoomID = roomId; + if (imOff) { + + RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() + // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO + .setRoomType(RCRTCRoomType.MEETING) + + .build(); + RCRTCEngine.getInstance().joinRoom("v" + roomId, roomConfig, new IRCRTCResultDataCallback() { + @Override + public void onSuccess(final RCRTCRoom rcrtcRoom) { + GameRyMicManager.this.mRtcRoom = rcrtcRoom; + // 注册房间回调 + rcrtcRoom.registerRoomListener(roomEventsListener); + try { + getView().onJoinRoomSuccess(rcrtcRoom); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + try { + getView().onJoinRoomFailed(rtcErrorCode); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + }); + } + + RongChatRoomClient.getInstance().joinChatRoom("v" + roomId, -1, new IRongCoreCallback.OperationCallback() { + @Override + public void onSuccess() { + Log.i("tx", "加入成功"); + enterRoom(); + + } + + @Override + public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) { + Log.i("tx", "加入" + "失败" + coreErrorCode); + if (WordUtil.isNewZh()) { + ToastUtil.show("網絡不佳無法連接,請重新進入"); + } else { + ToastUtil.show("The network is not connected, please re-enter"); + } + } + }); + } + + public void leaveRoom() { + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + @Override + public void onFailed(RTCErrorCode rtcErrorCode) { + } + + @Override + public void onSuccess() { + } + }); + RongChatRoomClient.getInstance().quitChatRoom("v" + mRoomID, new IRongCoreCallback.OperationCallback() { + @Override + public void onSuccess() { + Log.i("tx", "退出成功"); + } + + @Override + public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) { + Log.i("tx", "退出" + "" + coreErrorCode); + } + }); + } + + /** + * 处理游戏房Im消息 + */ + public void processingMessage(SudGameSocketImEvent socketImModel) { + + List msgDTOS = socketImModel.getMsg(); + if (msgDTOS.isEmpty()) return; + SudGameSocketImEvent.MsgDTO msgDTO = msgDTOS.get(0); + //正常文字消息 + if (TextUtils.equals(msgDTO.getMethod(), "SendMsg")) { + getView().insertItem(new SudGameChatImModel().setWelcomMessage(false).setNickname(msgDTO.getUname()).setTextMessage(msgDTO.getCt())); + } else if (TextUtils.equals(msgDTO.getMethod(), "welcomMessage")) { + // 欢迎(用户名)进入房间 Welcome (username) to the room + + StringBuffer stringBuffer = new StringBuffer(); + if (WordUtil.isNewZh()) { + stringBuffer.append("歡迎 ").append(msgDTO.getCt()).append(" 進入房間"); + } else { + stringBuffer.append("Welcome ").append(msgDTO.getCt()).append(" to enter the room"); + } + + getView().insertItem(new SudGameChatImModel().setWelcomMessage(true).setNickname(msgDTO.getCt()).setTextMessage(stringBuffer.toString())); + } else if (TextUtils.equals(msgDTO.getMethod(), "sudGameRoomVoiceList")) { + List personList = new Gson().fromJson(msgDTO.getCt(), new TypeToken>() { + }.getType()); + getView().refreshSudGameUserList(personList); + + refreshStreams(personList); + + } + } + + private void sendChatMessage(String textMessage, String method) { + IMLoginModel loginModel = IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getUserInfo(); + SudGameSocketImEvent sudGameSocketImEvent = new SudGameSocketImEvent(); + sudGameSocketImEvent.setRetcode("000000"); + sudGameSocketImEvent.setRetmsg("ok"); + + SudGameSocketImEvent.MsgDTO msgDTO = new SudGameSocketImEvent.MsgDTO(); + msgDTO.setAction("0") + .setCt(textMessage) + .setEquipment("app") + .setUid(String.valueOf(loginModel.getId())) + .setMethod(method) + .setUname(loginModel.getUserNicename()) + .setRoomnum(mRoomID); + + List msgDTOS = new ArrayList<>(); + msgDTOS.add(msgDTO); + sudGameSocketImEvent.setMsg(msgDTOS); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(new Gson().toJson(sudGameSocketImEvent)); + Message message = Message.obtain("v" + mRoomID, conversationType, messageContent); + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { + + } + + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + String contentJson = ((TextMessage) message.getContent()).getContent(); + Log.e("wewe", contentJson); + SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); + processingMessage(sudGameSocketImEvent); + } + + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { + Log.i("tx", "发送成功" + errorCode.toString()); + } + }); + } + + /** + * 发送聊天信息 + * + * @param textMessage + */ + public void sendMessage(String textMessage) { + sendChatMessage(textMessage, "SendMsg"); + } + + /** + * 进房间 + */ + public void enterRoom() { + IMLoginModel loginModel = IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getUserInfo(); + sendChatMessage(loginModel.getUserNicename(), "welcomMessage"); + } + + /** + * activity相关回调 + */ + public interface MeetingCallback { + void onJoinRoomSuccess(RCRTCRoom rcrtcRoom); + + void onJoinRoomFailed(RTCErrorCode rtcErrorCode); + + void onPublishSuccess(); + + + void onPublishFailed(); + + void onUnPublishStreamsSuccess(); + + void onUnPublishStreamsFailed(); + + void onSubscribeSuccess(List inputStreamList); + + void onSubscribeFailed(); + + void onSubscribeSuccess(String userID, boolean mute, int position); + + void onSubscribeFailed(String userID); + + void onUserJoined(RCRTCRemoteUser rcrtcRemoteUser); + + void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser); + + void insertItem(SudGameChatImModel sudGameChatImModel); + + void refreshSudGameUserList(List personList); + } +} diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameMicManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java similarity index 99% rename from common/src/main/java/com/yunbao/common/manager/imrongcloud/GameMicManager.java rename to common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java index 48d489a7c..b4c9abc59 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameMicManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java @@ -38,7 +38,7 @@ import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Message; import io.rong.message.TextMessage; -public class GameMicManager { +public class GameSwMicManager { MeetingCallback mMeetingCallback = null; private RCRTCRoom mRtcRoom = null; private String mRoomID = ""; @@ -369,7 +369,7 @@ public class GameMicManager { RCRTCEngine.getInstance().joinRoom("v" + roomId, roomConfig, new IRCRTCResultDataCallback() { @Override public void onSuccess(final RCRTCRoom rcrtcRoom) { - GameMicManager.this.mRtcRoom = rcrtcRoom; + GameSwMicManager.this.mRtcRoom = rcrtcRoom; // 注册房间回调 rcrtcRoom.registerRoomListener(roomEventsListener); try { diff --git a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java index cc449286f..6e9823dfc 100644 --- a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java @@ -48,7 +48,8 @@ public class RouteUtil { public static final String PATH_RED_PACKET_USER = "/main/RedPacketUsersActivity"; public static final String PATH_SELECT_AVATAR = "/main/UserAvatarSelectActivity"; public static final String PATH_BattlePassActivity = "/main/BattlePassActivity"; - public static final String PATH_SudGameActivity = "/live/SudGameActivity"; + public static final String PATH_SudSwGameActivity = "/live/SudSwGameActivity"; + public static final String PATH_SudRyGameActivity = "/live/SudRyGameActivity"; public static final String PATH_COMMUNITY_Activity = "/main/MainHomeCommunityActivity"; @@ -64,8 +65,16 @@ public class RouteUtil { .navigation(); } - public static void forwardSudGameActivity(String CreateSudRoom, boolean isAn, boolean isHome) { - ARouter.getInstance().build(PATH_SudGameActivity) + public static void forwardSwSudGameActivity(String CreateSudRoom, boolean isAn, boolean isHome) { + ARouter.getInstance().build(PATH_SudSwGameActivity) + .withString("CreateSudRoom", CreateSudRoom) + .withBoolean("CreateIsAn", isAn) + .withBoolean("CreateIsHome", isHome) + .navigation(); + } + + public static void forwardRySudGameActivity(String CreateSudRoom, boolean isAn, boolean isHome) { + ARouter.getInstance().build(PATH_SudRyGameActivity) .withString("CreateSudRoom", CreateSudRoom) .withBoolean("CreateIsAn", isAn) .withBoolean("CreateIsHome", isHome) diff --git a/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java b/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java index 0eff03c05..a3b89ce13 100644 --- a/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java +++ b/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java @@ -14,6 +14,7 @@ import com.alibaba.fastjson.JSON; import com.google.gson.Gson; import com.lxj.xpopup.XPopup; import com.makeramen.roundedimageview.RoundedImageView; +import com.yunbao.common.CommonAppConfig; import com.yunbao.common.R; import com.yunbao.common.bean.CreateSudRoomModel; import com.yunbao.common.bean.LiveBean; @@ -106,8 +107,11 @@ public class SudGameListViewHolder extends RecyclerView.ViewHolder { createSudRoomModel.setSudGameName(model.getSudGameName()); if (isHome) { if (TextUtils.equals(model.getLiveUid(), "0")) { - RouteUtil.forwardSudGameActivity(new Gson().toJson(createSudRoomModel),false,isHome); - + if(CommonAppConfig.getInstance().getConfig().isSw()){ + RouteUtil.forwardSwSudGameActivity(new Gson().toJson(data),true,isHome); + }else{ + RouteUtil.forwardRySudGameActivity(new Gson().toJson(data),true,isHome); + } } else { String yes = "是"; if (IMLoginManager.get(itemView.getContext()).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) { @@ -155,8 +159,11 @@ public class SudGameListViewHolder extends RecyclerView.ViewHolder { @Override public void onCancel() { - - RouteUtil.forwardSudGameActivity(new Gson().toJson(createSudRoomModel),false,isHome); + if(CommonAppConfig.getInstance().getConfig().isSw()){ + RouteUtil.forwardSwSudGameActivity(new Gson().toJson(createSudRoomModel),true,isHome); + }else{ + RouteUtil.forwardRySudGameActivity(new Gson().toJson(createSudRoomModel),true,isHome); + } } })).show(); diff --git a/live/src/main/AndroidManifest.xml b/live/src/main/AndroidManifest.xml index 2f80c2ebd..98ec3f02f 100644 --- a/live/src/main/AndroidManifest.xml +++ b/live/src/main/AndroidManifest.xml @@ -85,7 +85,10 @@ android:name=".activity.WebViewActivityMedal" android:screenOrientation="portrait" /> + muteUser = new ArrayList<>(); + private boolean imOff; + + @Override + protected int getLayoutId() { + return R.layout.activity_sud_game; + } + + @Override + protected void main() { + Bus.getOn(this); + super.main(); + initView(); + initDate(); + } + + private List customSidebarChildModels = new ArrayList<>(); + + private void initDate() { + + LiveNetManager.get(mContext) + .getCustomSidebarInfo("1", new HttpCallback>() { + @Override + public void onSuccess(List data) { + for (CustomSidebarInfoModel datum : data) { + if (datum.getType().equals("6")) { + customSidebarChildModels = datum.getChild(); + return; + } + } + } + + @Override + public void onError(String error) { + + } + }); + + // 设置禁用麦克风采集 + RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); + ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); + gameCloseWheat.setVisibility(View.INVISIBLE); + + + mProcessResultUtil = new ProcessResultUtil(this); + LiveNetManager.get(mContext) + .getRoomMicStatus(new HttpCallback() { + @Override + public void onSuccess(RoomMicStatusModel data) { + gameMicManager = new GameRyMicManager(); + gameMicManager.attachView(SudRyGameActivity.this); + gameMicManager.config(SudRyGameActivity.this); + //语音 + if (TextUtils.equals(data.getMicStatus(), "1")) { + imOff = true; + gameSeat.setVisibility(View.VISIBLE); + userList.setVisibility(View.VISIBLE); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + if (!mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) { + ToastUtil.show("拒绝权限将无法使用上麦功能"); + mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() { + @Override + public void run() { + + } + }); + } + } + }, 1500); + } else { + imOff = false; + gameSeat.setVisibility(View.GONE); + userList.setVisibility(View.GONE); + } + if (TextUtils.equals(data.getImStatus(), "1")) { + findViewById(R.id.game_review_input).setVisibility(View.VISIBLE); + chatList.setVisibility(View.VISIBLE); + } else { + findViewById(R.id.game_review_input).setVisibility(View.GONE); + chatList.setVisibility(View.GONE); + } + gameMicManager.joinRoom(mLiveUid, imOff); + } + + @Override + public void onError(String error) { + imOff = false; + //文字 + findViewById(R.id.game_review_input).setVisibility(View.GONE); + chatList.setVisibility(View.GONE); + //语音 + gameCloseWheat.setVisibility(View.GONE); + gameSeat.setVisibility(View.GONE); + userList.setVisibility(View.GONE); + } + }); + + + } + + @Override + protected void onDestroy() { + + LiveNetManager.get(mContext) + .leaveMic(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + + } + + @Override + public void onError(String error) { + + } + }); + + if (gameMicManager != null) { + gameMicManager.leaveRoom(); + gameMicManager.detachView(); + } + Bus.getOff(this); + + super.onDestroy(); + } + + private void initView() { + + String createSudRoomJson = getIntent().getStringExtra("CreateSudRoom"); + mCreateSudRoomModel = new Gson().fromJson(createSudRoomJson, CreateSudRoomModel.class); + mInteractionID = mCreateSudRoomModel.getLongSudGameId(); + mLiveUid = mCreateSudRoomModel.getSudGameRoomId(); + + gameContainer = findViewById(R.id.game_container); + roomName = findViewById(R.id.room_name); + roomNumber = findViewById(R.id.room_number); + gameCloseWheat = findViewById(R.id.game_close_wheat); + gameSeat = findViewById(R.id.game_seat); + chatList = findViewById(R.id.chat_list); + userList = findViewById(R.id.user_list); + //聊天栏 + FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) + chatList.getLayoutParams(); + params1.topMargin = DpUtil.dp2px(65); + chatList.setLayoutParams(params1); + + chatList.setHasFixedSize(true); + LinearLayoutManager layoutManager = new LinearLayoutManager(mContext); + layoutManager.setOrientation(RecyclerView.VERTICAL); + layoutManager.setStackFromEnd(true); + chatList.setLayoutManager(layoutManager); + chatList.addItemDecoration(new TopGradual()); + chatList.setItemViewCacheSize(10); + mLiveChatAdapter = new SudGameChatAdapter(mContext); + chatList.setAdapter(mLiveChatAdapter); + sudGameUserListAdapter = new SudGameUserListAdapter(new ArrayList<>()); + ImgLoader.display(mContext, WordUtil.isNewZh() ? R.mipmap.icon_game_seat : R.mipmap.icon_game_seat_en, gameSeat); + sudGameUserListAdapter.setSudGameSmallCallBack(new SudGameUserListAdapter.SudGameSmallCallBack() { + @Override + public void unMute(String userID, int position) { + if (!TextUtils.equals(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()), userID)) { + gameMicManager.refreshStreams(userID, false, position); + } else { + ToastUtil.show(WordUtil.isNewZh() ? "無法對本人靜音" : "Unable to mute myself"); + } + muteUser.remove(userID); + } + + @Override + public void mute(String userID, int position) { + muteUser.add(userID); + if (!TextUtils.equals(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()), userID)) { + gameMicManager.refreshStreams(userID, true, position); + } else { + ToastUtil.show(WordUtil.isNewZh() ? "無法對本人靜音" : "Unable to mute myself"); + } + + } + + @Override + public void viewInformation(SudGameUserModel sudGameUserModel) { + LiveUserDialogFragment fragment = new LiveUserDialogFragment(); + Bundle bundle = new Bundle(); + bundle.putString(Constants.LIVE_UID, "uid"); + bundle.putString(Constants.STREAM, ""); + bundle.putString(Constants.TO_UID, sudGameUserModel.getId() + ""); + fragment.setArguments(bundle); + fragment.show(((SudRyGameActivity) mContext).getSupportFragmentManager(), "LiveUserDialogFragment"); + } + }); + userList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false)); + userList.setAdapter(sudGameUserListAdapter); + if (mCreateSudRoomModel != null) { + roomName.setText(mCreateSudRoomModel.getRoomName()); + roomNumber.setText(mCreateSudRoomModel.getSudGameRoomId()); + } + + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.exit), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + gameViewModel.onDestroy(); + finish(); + } + }); + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.sud_history), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + + new XPopup.Builder(mContext) + .enableDrag(false) + .asCustom(new LiveSudGameHistoryPopup(mContext, customSidebarChildModels)).show(); + } + }); + + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.game_seat), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + if (imOff && gameMicManager != null) { + if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) { + if (publishDefault) { + disable = true; + // 设置禁用麦克风采集 + RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); +// ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); + gameMicManager.unPublishStreams(); + } else { + if (sudGameUserListAdapter.isMicMax()) { + ToastUtil.show(WordUtil.isNewZh() ? "上麥人數最大7人" : "The maximum number of people on the microphone is 7"); + } else { + gameMicManager.publishDefaultAVStream(); + } + + } + } else { + mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() { + @Override + public void run() { + + } + }); + } + } + + + } + }); + ViewClicksAntiShake.clicksAntiShake(gameCloseWheat, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + if (imOff && gameMicManager != null) { + + gameCloseWheat.post(new Runnable() { + @Override + public void run() { + if (disable) { + disable = false; + // 设置禁用麦克风采集 + RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); + ImgLoader.display(mContext, R.mipmap.icon_game_open_wheat, gameCloseWheat); + LiveNetManager.get(mContext) + .onMic(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + + } + + @Override + public void onError(String error) { + + } + }); + ToastUtil.show(WordUtil.isNewZh() ? "麥克風已開啟" : "Microphone turned on"); + } else { + disable = true; + // 设置禁用麦克风采集 + RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); + ImgLoader.display(mContext, R.mipmap.icon_game_close_wheat, gameCloseWheat); + LiveNetManager.get(mContext) + .offMic(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + + } + + @Override + public void onError(String error) { + + } + }); + ToastUtil.show(WordUtil.isNewZh() ? "麥克風已關閉" : "Microphone turned off"); + } + } + }); + + + } + + + } + }); + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.game_review_input), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + new XPopup.Builder(mContext) + .enableDrag(false) + .asCustom(new SudGameInputPopupWindow(mContext, new SudGameInputPopupWindow.SudGameInputCallBack() { + @Override + public void sendMessage(String textMessage) { + gameMicManager.sendMessage(textMessage); + } + })) + .show(); + } + }); + + gameViewModel.gameViewLiveData.observe(this, new Observer() { + @Override + public void onChanged(View view) { + if (view == null) { // 在关闭游戏时,把游戏View给移除 + gameContainer.removeAllViews(); + } else { // 把游戏View添加到容器内 + gameContainer.addView(view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); + + } + + } + }); + // 加载游戏,参数定义可查看BaseGameViewModel.switchGame()方法注释 + // 游戏配置 + GameConfigModel gameConfigModel = gameViewModel.getGameConfigModel(); + gameConfigModel.ui.ping.hide = true; // 配置不隐藏ping值 + gameConfigModel.ui.level.hide = true; // 配置不隐藏ping值 + gameConfigModel.ui.lobby_game_setting.hide = true; // 配置不隐藏ping值 + + gameConfigModel.ui.lobby_players.custom = true; + gameConfigModel.ui.join_btn.custom = true; + gameConfigModel.ui.game_settle_again_btn.custom = true; + gameConfigModel.ui.start_btn.custom = true; + + + // SudMGP平台64bit游戏ID + gameViewModel.switchGame((Activity) mContext, mLiveUid, mInteractionID); +// gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfIn(true, -1, true, 1); +// gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfCaptain(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); +// ViewClicksAntiShake.clicksAntiShake(gameTitle, new ViewClicksAntiShake.ViewClicksCallBack() { +// @Override +// public void onViewClicks() { +// +// } +// }); + // 设置游戏安全操作区域 + GameViewInfoModel.GameViewRectModel gameViewRectModel = new GameViewInfoModel.GameViewRectModel(); + gameViewRectModel.left = 0; + gameViewRectModel.top = DpUtil.dp2px(155); + gameViewRectModel.right = 0; + gameViewRectModel.bottom = DpUtil.dp2px(155); + gameViewModel.gameViewRectModel = gameViewRectModel; + + + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onCheckRemainingBalanceEvent(CheckRemainingBalanceEvent event) { + switch (event.getSudMGPMGState()) { + case SudMGPMGState.MG_COMMON_SELF_CLICK_JOIN_BTN: + case SudMGPMGState.MG_COMMON_SELF_CLICK_GAME_SETTLE_AGAIN_BTN: + + LiveNetManager.get(mContext).checkRemainingBalance(mCreateSudRoomModel.getSudGameRoomId(), new HttpCallback() { + @Override + public void onSuccess(CheckRemainingBalance data) { + if (TextUtils.equals(String.valueOf(data.getGoldenBeanRemainingBalance()), "1")) { + gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfIn(true, event.getSeatIndex(), true, 1); + } else { + if (IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) { + ToastUtil.show("貨幣数量不足 "); + } else { + ToastUtil.show("Insufficient number of currency"); + } + + } +// ToastUtil.show(data.toString()); + + } + + @Override + public void onError(String error) { + if (IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) { + ToastUtil.show("貨幣数量不足 "); + } else { + ToastUtil.show("Insufficient number of currency"); + } + + } + }); + break; + case SudMGPMGState.MG_COMMON_GAME_SETTLE: + gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfIn(false, event.getSeatIndex(), true, 1); + break; + case SudMGPMGState.MG_COMMON_SELF_CLICK_START_BTN: + LiveNetManager.get(mContext).gameStartCheckRemainingBalance(mCreateSudRoomModel.getSudGameId(), + mCreateSudRoomModel.getSudGameRoomId(), new + HttpCallback() { + @Override + public void onSuccess(CheckRemainingBalance data) { + if (data.getStatus() == 1) { + gameViewModel.sudFSTAPPDecorator.notifyAPPCommonSelfPlaying(true); + } else { + + } + + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + break; + case SudMGPMGState.MG_COMMON_GAME_STATE: + LiveNetManager.get(mContext).deductMoney(mCreateSudRoomModel.getSudGameRoomId()); + break; + } + + } + + @Override + public void onJoinRoomSuccess(RCRTCRoom rcrtcRoom) { + LiveNetManager.get(mContext).getRoomMicData(mLiveUid, new HttpCallback>() { + @Override + public void onSuccess(List data) { + + gameMicManager.refreshStreams(data); + sudGameUserListAdapter.refreshSudGameUserList(data, muteUser); + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + // 主动订阅远端用户发布的资源 +// gameMicManager.subscribeAVStream(); + } + + @Override + public void onJoinRoomFailed(RTCErrorCode rtcErrorCode) { + ToastUtil.show("加入失败 " + rtcErrorCode.toString()); + } + + @Override + public void onPublishSuccess() { + runOnUiThread(new Runnable() { + @Override + public void run() { + ImgLoader.display(mContext, WordUtil.isNewZh() ? R.mipmap.icon_game_hang_up : R.mipmap.icon_game_hang_up_en, gameSeat); + publishDefault = true; + gameCloseWheat.setVisibility(View.VISIBLE); + disable = false; + // 设置禁用麦克风采集 + RCRTCEngine.getInstance().getDefaultAudioStream().setMicrophoneDisable(disable); + ImgLoader.display(mContext, R.mipmap.icon_game_open_wheat, gameCloseWheat); + } + }); + + LiveNetManager.get(mContext) + .joinMic(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + + } + + @Override + public void onError(String error) { + + } + }); + } + + @Override + public void onPublishFailed() { + ToastUtil.show(WordUtil.isNewZh() ? "語音加入失敗" : "Voice joining failed"); + } + + @Override + public void onSubscribeSuccess(List inputStreamList) { +// ToastUtil.show("订阅成功 "); + } + + @Override + public void onSubscribeFailed() { + ToastUtil.show("订阅失败 "); + } + + @Override + public void onSubscribeSuccess(String userID, boolean mute, int position) { + runOnUiThread(new Runnable() { + @Override + public void run() { + if (mute) { + ToastUtil.show(WordUtil.isNewZh() ? "已靜音該用戶" : "The user has been muted"); + } else { + ToastUtil.show(WordUtil.isNewZh() ? "已取消該用戶靜音" : "The user has been unmuted"); + } + sudGameUserListAdapter.muteUser(userID, mute, position); + } + }); + + } + + @Override + public void onSubscribeFailed(String userID) { + ToastUtil.show("订阅失败 "); + } + + @Override + public void onUserJoined(RCRTCRemoteUser rcrtcRemoteUser) { + + } + + @Override + public void onUserLeft(RCRTCRemoteUser rcrtcRemoteUser) { + + } + + @Override + public void insertItem(SudGameChatImModel sudGameChatImModel) { + mLiveChatAdapter.insertItem(sudGameChatImModel); + } + + @Override + public void refreshSudGameUserList(List personList) { + sudGameUserListAdapter.refreshSudGameUserList(personList, muteUser); + } + + @Override + public void onUnPublishStreamsSuccess() { + runOnUiThread(new Runnable() { + @Override + public void run() { + ImgLoader.display(mContext, WordUtil.isNewZh() ? R.mipmap.icon_game_seat : R.mipmap.icon_game_seat_en, gameSeat); + publishDefault = false; + gameCloseWheat.setVisibility(View.INVISIBLE); + } + }); + LiveNetManager.get(mContext) + .leaveMic(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + + } + + @Override + public void onError(String error) { + + } + }); + + } + + @Override + public void onUnPublishStreamsFailed() { + + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSudGameSocketImEvent(SudGameSocketImEvent event) { + gameMicManager.processingMessage(event); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSudGameUserModel(SudGameUserModel model) { + if (model.isNullUser()) { + if (!publishDefault) { + if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) { + if (sudGameUserListAdapter.isMicMax()) { + ToastUtil.show(WordUtil.isNewZh() ? "上麥人數最大7人" : "The maximum number of people on the microphone is 7"); + } else { + gameMicManager.publishDefaultAVStream(); + } + + } else { + mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() { + @Override + public void run() { + + } + }); + } + + } else { + ToastUtil.show(WordUtil.isNewZh() ? "已經是上麥狀態" : "It is already in the wheat state"); + } + + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSudGameStatus(SubGameEvent event) { + if (event.getType() == 0) { + Log.i("游戏回调", "onGameStateChange: event :" + event.toString()); + if (event.getModel().getCode() == 1001 || event.getModel().getCode() == 1002) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("result", 0); + gameViewModel.sudFSTAPPDecorator.notifyStateChange(SudMGPAPPState.APP_COMMON_GAME_CREATE_ORDER_RESULT, jsonObject.toString()); + } + } + } +} diff --git a/live/src/main/java/com/yunbao/live/activity/SudGameActivity.java b/live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java similarity index 97% rename from live/src/main/java/com/yunbao/live/activity/SudGameActivity.java rename to live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java index 4a4fe96f1..eb6ee8efd 100644 --- a/live/src/main/java/com/yunbao/live/activity/SudGameActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java @@ -39,7 +39,7 @@ import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; -import com.yunbao.common.manager.imrongcloud.GameMicManager; +import com.yunbao.common.manager.imrongcloud.GameSwMicManager; import com.yunbao.common.sud.QuickStartGameViewModel; import com.yunbao.common.sud.model.GameConfigModel; import com.yunbao.common.sud.model.GameViewInfoModel; @@ -72,8 +72,8 @@ import io.rong.imlib.IRongCoreCallback; import io.rong.imlib.IRongCoreEnum; import io.rong.imlib.chatroom.base.RongChatRoomClient; -@Route(path = RouteUtil.PATH_SudGameActivity) -public class SudGameActivity extends AbsActivity implements GameMicManager.MeetingCallback { +@Route(path = RouteUtil.PATH_SudSwGameActivity) +public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.MeetingCallback { private FrameLayout gameContainer; private long mInteractionID; private String mLiveUid; @@ -81,7 +81,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti private CreateSudRoomModel mCreateSudRoomModel; private TextView roomName, roomNumber; - private GameMicManager gameMicManager; + private GameSwMicManager gameMicManager; private ImageView gameCloseWheat, gameSeat; private boolean disable = true, publishDefault = false; @@ -91,7 +91,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti private ProcessResultUtil mProcessResultUtil; private List muteUser = new ArrayList<>(); private boolean imOff; - private boolean isSw = true; + private boolean isSw = CommonAppConfig.getInstance().getConfig().isSw(); @Override protected int getLayoutId() { @@ -136,9 +136,9 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti LiveNetManager.get(mContext).getRoomMicStatus(new HttpCallback() { @Override public void onSuccess(RoomMicStatusModel data) { - gameMicManager = new GameMicManager(); - gameMicManager.attachView(SudGameActivity.this); - gameMicManager.config(SudGameActivity.this); + gameMicManager = new GameSwMicManager(); + gameMicManager.attachView(SudSwGameActivity.this); + gameMicManager.config(SudSwGameActivity.this); //初始化声网引擎 SWAuManager.get().initRtcEngineAudio(mContext); //语音 @@ -316,7 +316,7 @@ public class SudGameActivity extends AbsActivity implements GameMicManager.Meeti bundle.putString(Constants.STREAM, ""); bundle.putString(Constants.TO_UID, sudGameUserModel.getId() + ""); fragment.setArguments(bundle); - fragment.show(((SudGameActivity) mContext).getSupportFragmentManager(), "LiveUserDialogFragment"); + fragment.show(((SudSwGameActivity) mContext).getSupportFragmentManager(), "LiveUserDialogFragment"); } }); userList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false)); diff --git a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java index 42336041f..fd8598955 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java @@ -231,14 +231,12 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList goHomeUser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mContext instanceof LiveAnchorActivity) { - ((LiveAnchorActivity) mContext).superBackPressed(); + if (mContext instanceof LiveRyAnchorActivity) { + ((LiveRyAnchorActivity) mContext).superBackPressed(); } else if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); } else if (mContext instanceof LiveSwAnchorActivity) { ((LiveSwAnchorActivity) mContext).superBackPressed(); - }else if(mContext instanceof LiveRyAnchorActivity){ - ((LiveRyAnchorActivity) mContext).superBackPressed(); } Bus.get().post(new CloseEvent()); } @@ -264,8 +262,8 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mContext instanceof LiveAnchorActivity) { - ((LiveAnchorActivity) mContext).superBackPressed(); + if (mContext instanceof LiveRyAnchorActivity) { + ((LiveRyAnchorActivity) mContext).superBackPressed(); } else if (mContext instanceof LiveAudienceActivity) { ((LiveAudienceActivity) mContext).exitLiveRoom(); } else if (mContext instanceof LiveSwAnchorActivity) { diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index a301dd5e9..7eed8bad4 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -3685,32 +3685,34 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (isStayRoomfive) { showFollowDialog(mNameText, mAvatarUrl, mContext); } else { - - if(mContext instanceof LiveSwAnchorActivity){ - LiveSwAnchorActivity.backIndex = 1; - ((LiveSwAnchorActivity) mContext).onBackPressed(); - }else{ - LiveRyAnchorActivity.backIndex = 1; - ((LiveRyAnchorActivity) mContext).onBackPressed(); - } - } - } else { - if(mContext instanceof LiveSwAnchorActivity){ LiveSwAnchorActivity.backIndex = 1; ((LiveSwAnchorActivity) mContext).onBackPressed(); - }else{ + } + } else { + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); + } + } else { + LiveSwAnchorActivity.backIndex = 1; + ((LiveSwAnchorActivity) mContext).onBackPressed(); + } + }else if(mContext instanceof LiveRyAnchorActivity){ + if (forAct == 1) { + //是否关注0==没关注 + if (isAttention == 0) { + if (isStayRoomfive) { + showFollowDialog(mNameText, mAvatarUrl, mContext); + } else { LiveRyAnchorActivity.backIndex = 1; ((LiveRyAnchorActivity) mContext).onBackPressed(); } - } - } else { - if(mContext instanceof LiveSwAnchorActivity){ - LiveSwAnchorActivity.backIndex = 1; - ((LiveSwAnchorActivity) mContext).onBackPressed(); - }else{ + } else { LiveRyAnchorActivity.backIndex = 1; ((LiveRyAnchorActivity) mContext).onBackPressed(); } + } else { + LiveRyAnchorActivity.backIndex = 1; + ((LiveRyAnchorActivity) mContext).onBackPressed(); } } } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java index 4a9f40083..f53469f4b 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -1,5 +1,6 @@ package com.yunbao.live.views; +import static com.yunbao.live.activity.LiveActivity.isSw; import static com.yunbao.live.activity.LiveActivity.mLiveUid; import static com.yunbao.live.activity.LiveSwAnchorActivity.PKing; import static com.yunbao.live.activity.LiveSwAnchorActivity.pk_nub; @@ -174,7 +175,11 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (yaoqing.size() < 3) { if (PKing == false) { - ((LiveRyAnchorActivity) mContext).openLinkMicAnchorWindow(true); + if(isSw){ + ((LiveSwAnchorActivity) mContext).openLinkMicAnchorWindow(true); + }else{ + ((LiveRyAnchorActivity) mContext).openLinkMicAnchorWindow(true); + } } else { ToastUtil.show(WordUtil.isNewZh() ? "您已在PK中" : "You are already in the PK"); } @@ -242,7 +247,11 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 关闭直播 */ private void close() { - ((LiveRyAnchorActivity) mContext).closeLive(); + if(isSw){ + ((LiveSwAnchorActivity) mContext).closeLive(); + }else{ + ((LiveRyAnchorActivity) mContext).closeLive(); + } } @Override @@ -258,7 +267,11 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (mBtnFunction != null) { mBtnFunction.setImageDrawable(mDrawable1); } - ((LiveRyAnchorActivity) mContext).showFunctionDialog(); + if(isSw){ + ((LiveSwAnchorActivity) mContext).showFunctionDialog(); + }else{ + ((LiveRyAnchorActivity) mContext).showFunctionDialog(); + } } /** @@ -291,7 +304,11 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 发起主播连麦pk */ private void applyLinkMicPk() { - ((LiveRyAnchorActivity) mContext).applyLinkMicPk(); + if(isSw){ + ((LiveSwAnchorActivity) mContext).applyLinkMicPk(); + }else{ + ((LiveRyAnchorActivity) mContext).applyLinkMicPk(); + } } public void setLinkMicEnable(boolean linkMicEnable) { diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeGameViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeGameViewHolder.java index 97345b408..605e2e89f 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeGameViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeGameViewHolder.java @@ -17,7 +17,7 @@ import com.google.gson.Gson; import com.lxj.xpopup.XPopup; import com.lxj.xpopup.enums.PopupPosition; import com.yunbao.common.activity.AbsActivity; -import com.yunbao.live.activity.SudGameActivity; +import com.yunbao.live.activity.SudSwGameActivity; import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.adapter.SudGameListAdapter; import com.yunbao.common.bean.CreateSudRoomModel; @@ -158,7 +158,7 @@ public class MainHomeGameViewHolder extends AbsMainHomeChildViewHolder implement @Override public void onSuccess(CreateSudRoomModel data) { if (data != null) { - Intent intent = new Intent(context, SudGameActivity.class); + Intent intent = new Intent(context, SudSwGameActivity.class); intent.putExtra("CreateSudRoom", new Gson().toJson(data)); context.startActivity(intent); } else { From dc0ae1124fa7a43c642c894b350c1f49466a527f Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Wed, 22 May 2024 13:32:05 +0800 Subject: [PATCH 20/64] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E6=88=BF=E5=88=A4=E6=96=AD=E5=A3=B0=E7=BD=91?= =?UTF-8?q?=E6=88=96=E8=80=85=E8=9E=8D=E4=BA=91]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 1 - .../yunbao/common/bean/CheckLiveModel.java | 1 + .../com/yunbao/common/bean/ConfigBean.java | 23 +- .../common/views/SudGameListViewHolder.java | 4 +- .../beautyapi/faceunity/agora/SWManager.java | 72 ++- .../live/activity/SudRyGameActivity.java | 3 +- .../live/activity/SudSwGameActivity.java | 1 - .../presenter/LiveSwLinkMicPkPresenter.java | 493 ++---------------- .../yunbao/live/socket/SocketRyClient.java | 10 +- .../live/views/PortraitLiveManager.java | 8 +- .../src/main/res/layout/view_live_push_sw.xml | 46 +- .../main/dialog/MainStartDialogFragment.java | 2 +- 12 files changed, 135 insertions(+), 529 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index b49b1b844..4a8c1ec77 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -129,7 +129,6 @@ public class AppContext extends CommonAppContext { public void onActivityStarted(@NonNull Activity activity) { } - } @Override diff --git a/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java b/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java index 2d7d00c3e..4b4f7ca30 100644 --- a/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java +++ b/common/src/main/java/com/yunbao/common/bean/CheckLiveModel.java @@ -2,6 +2,7 @@ package com.yunbao.common.bean; import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; +import com.yunbao.common.BuildConfig; public class CheckLiveModel extends BaseModel { diff --git a/common/src/main/java/com/yunbao/common/bean/ConfigBean.java b/common/src/main/java/com/yunbao/common/bean/ConfigBean.java index 12fc45d1f..ec6d14242 100644 --- a/common/src/main/java/com/yunbao/common/bean/ConfigBean.java +++ b/common/src/main/java/com/yunbao/common/bean/ConfigBean.java @@ -2,6 +2,7 @@ package com.yunbao.common.bean; import com.alibaba.fastjson.annotation.JSONField; import com.google.gson.annotations.SerializedName; +import com.yunbao.common.BuildConfig; import com.yunbao.common.utils.StringUtil; import java.util.Arrays; @@ -60,8 +61,8 @@ public class ConfigBean extends BaseModel { private String txPlayUgcLicenceUrl;//腾讯短视频鉴权 private String txVideoUgcKey; private String google_isup; - @SerializedName("sud_game_speech")//(0否,1是) - private String sudGameSpeech; + + private String sud_game_speech; @SerializedName("is_return_user")//是否需要弹窗(0否,1是) private String isReturnUser=""; @@ -186,22 +187,18 @@ public class ConfigBean extends BaseModel { '}'; } + public boolean isSw(){ - if(StringUtil.isEmpty(sudGameSpeech)){ - return false; - }else if(sudGameSpeech.equals("1")){ - return true; - }else{ - return false; - } + return getSud_game_speech().equals("1"); } - public String getSudGameSpeech() { - return sudGameSpeech; + @JSONField(name = "sud_game_speech") + public String getSud_game_speech() { + return sud_game_speech; } - public void setSudGameSpeech(String sudGameSpeech) { - this.sudGameSpeech = sudGameSpeech; + public void setSud_game_speech(String sud_game_speech) { + this.sud_game_speech = sud_game_speech; } @JSONField(name = "apk_ver") diff --git a/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java b/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java index a3b89ce13..b2c36f106 100644 --- a/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java +++ b/common/src/main/java/com/yunbao/common/views/SudGameListViewHolder.java @@ -108,9 +108,9 @@ public class SudGameListViewHolder extends RecyclerView.ViewHolder { if (isHome) { if (TextUtils.equals(model.getLiveUid(), "0")) { if(CommonAppConfig.getInstance().getConfig().isSw()){ - RouteUtil.forwardSwSudGameActivity(new Gson().toJson(data),true,isHome); + RouteUtil.forwardSwSudGameActivity(new Gson().toJson(createSudRoomModel),true,isHome); }else{ - RouteUtil.forwardRySudGameActivity(new Gson().toJson(data),true,isHome); + RouteUtil.forwardRySudGameActivity(new Gson().toJson(createSudRoomModel),true,isHome); } } else { String yes = "是"; diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 1b7e3ebff..93ba3273d 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -33,6 +33,7 @@ import io.agora.rtc2.IRtcEngineEventHandler; import io.agora.rtc2.RtcConnection; import io.agora.rtc2.RtcEngineConfig; import io.agora.rtc2.RtcEngineEx; +import io.agora.rtc2.video.ContentInspectConfig; import io.agora.rtc2.video.VideoCanvas; import io.agora.rtc2.video.VideoEncoderConfiguration; @@ -66,6 +67,7 @@ public class SWManager extends BaseCacheManager { /** * 获取单列 + * * @return */ public static SWManager get() { @@ -123,7 +125,7 @@ public class SWManager extends BaseCacheManager { // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 SurfaceView surfaceView = new SurfaceView(mContext); anchorContainer.addView(surfaceView); - Config config = new Config(mContext, mRtcEngine, FURenderer.INSTANCE.mFURenderKit, null, CaptureMode.Agora, 0, false, new CameraConfig(MirrorMode.MIRROR_NONE,MirrorMode.MIRROR_NONE)); + Config config = new Config(mContext, mRtcEngine, FURenderer.INSTANCE.mFURenderKit, null, CaptureMode.Agora, 0, false, new CameraConfig(MirrorMode.MIRROR_NONE, MirrorMode.MIRROR_NONE)); faceUnityBeautyAPI.initialize(config); faceUnityBeautyAPI.enable(false); @@ -135,17 +137,19 @@ public class SWManager extends BaseCacheManager { //faceUnityBeautyAPI.updateCameraConfig(new CameraConfig(MirrorMode.MIRROR_NONE,MirrorMode.MIRROR_NONE)); //mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); setEnableBeauty(true); //默认开启美颜 - + setContentInspect(); //开启视频截图上传 } - public void setEnableBeauty(boolean flag){ - if(faceUnityBeautyAPI!=null){ + + public void setEnableBeauty(boolean flag) { + if (faceUnityBeautyAPI != null) { faceUnityBeautyAPI.enable(flag); } } /** * 设置清晰度 + * * @param selectClarity */ public void setDimensions(int selectClarity) { @@ -175,12 +179,12 @@ public class SWManager extends BaseCacheManager { /** * 设置镜像模式 */ - public void setMirrorMode(){ - if(cfg!=null&&mRtcEngine!=null){ - L.eSw("setMirrorMode设置镜像"+cfg.mirrorMode); - if(cfg.mirrorMode==VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_ENABLED){ + public void setMirrorMode() { + if (cfg != null && mRtcEngine != null) { + L.eSw("setMirrorMode设置镜像" + cfg.mirrorMode); + if (cfg.mirrorMode == VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_ENABLED) { cfg.mirrorMode = VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_DISABLED; //取消镜像 - }else{ + } else { cfg.mirrorMode = VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_ENABLED; //设置镜像 } mRtcEngine.setVideoEncoderConfiguration(cfg); @@ -190,11 +194,23 @@ public class SWManager extends BaseCacheManager { } } + public void setContentInspect() { + ContentInspectConfig config = new ContentInspectConfig(); + config.extraInfo = "YourExtraInfo"; + config.moduleCount = 1; + // 功能模块的类型为视频截图上传 + config.modules[0].type = ContentInspectConfig.CONTENT_INSPECT_TYPE_SUPERVISE; + // 视频截图上传的频率为 2 秒一次 + config.modules[0].interval = 2; + mRtcEngine.enableContentInspect(true, config); + } + + /** - * 设置镜像模式 + * 设置前後攝像頭 */ - public void switchCamera(){ - if(mRtcEngine!=null){ + public void switchCamera() { + if (mRtcEngine != null) { mRtcEngine.switchCamera(); } } @@ -212,6 +228,7 @@ public class SWManager extends BaseCacheManager { /** * 更新主播视图 + * * @param frameLayout */ public void updateMyChannelView(FrameLayout frameLayout) { @@ -220,13 +237,14 @@ public class SWManager extends BaseCacheManager { surfaceView.setZOrderMediaOverlay(true); frameLayout.addView(surfaceView); - VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN , uid); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid); mRtcEngine.setupLocalVideo(videoCanvas); } /** * PK-加入对方主播直播间 + * * @param strUid * @param token * @param toUid @@ -264,7 +282,7 @@ public class SWManager extends BaseCacheManager { SurfaceView surfaceView = new SurfaceView(mContext); surfaceView.setZOrderMediaOverlay(true); pkContainer.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); } }); @@ -286,12 +304,13 @@ public class SWManager extends BaseCacheManager { /** * 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; @@ -324,7 +343,7 @@ public class SWManager 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); } }); @@ -345,10 +364,11 @@ public class SWManager 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 @@ -358,8 +378,8 @@ public class SWManager extends BaseCacheManager { /** * 退出所有频道 */ - public void exitChannelAll(){ - if(mRtcEngine!=null){ + public void exitChannelAll() { + if (mRtcEngine != null) { mRtcEngine.leaveChannel(); } } @@ -367,6 +387,7 @@ public class SWManager extends BaseCacheManager { public void setAnchorContainer(FrameLayout anchorContainer) { this.anchorContainer = anchorContainer; } + //远程监听 private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { @Override @@ -384,7 +405,7 @@ public class SWManager extends BaseCacheManager { @Override public void onJoinChannelSuccess(String channel, int uid, int elapsed) { super.onJoinChannelSuccess(channel, uid, elapsed); - L.eSw("onJoinChannelSuccess 加入频道:channel"+channel+" uid:"+uid+" elapsed:"+elapsed); + L.eSw("onJoinChannelSuccess 加入频道:channel" + channel + " uid:" + uid + " elapsed:" + elapsed); if (onRtcEngineListener != null) { onRtcEngineListener.onOpenSuccess(channel, uid); } @@ -393,7 +414,7 @@ public class SWManager extends BaseCacheManager { @Override public void onError(int err) { super.onError(err); - L.eSw("onError 错误码:"+err); + L.eSw("onError 错误码:" + err); ToastUtil.show("onError:" + err); } @@ -420,7 +441,7 @@ public class SWManager extends BaseCacheManager { @Override public void onLocalVideoStateChanged(Constants.VideoSourceType source, int state, int error) { super.onLocalVideoStateChanged(source, state, error); - L.eSw("onLocalVideoStateChanged_source"+source+" state_"+state+" error_"+error); + L.eSw("onLocalVideoStateChanged_source" + source + " state_" + state + " error_" + error); } }; @@ -452,10 +473,11 @@ public class SWManager extends BaseCacheManager { public void setLinkUserContainer(FrameLayout linkUserContainer) { this.linkUserContainer = linkUserContainer; } + public static String getChannelName(String liveUid) { - if(liveUid.contains("g")){ + if (liveUid.contains("g")) { return liveUid; - }else{ + } else { return CommonAppConfig.SWChannelPrefix + liveUid; } } diff --git a/live/src/main/java/com/yunbao/live/activity/SudRyGameActivity.java b/live/src/main/java/com/yunbao/live/activity/SudRyGameActivity.java index 176330831..7ec1b109a 100644 --- a/live/src/main/java/com/yunbao/live/activity/SudRyGameActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/SudRyGameActivity.java @@ -19,6 +19,7 @@ import com.alibaba.android.arouter.facade.annotation.Route; import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import com.lxj.xpopup.XPopup; +import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.R; import com.yunbao.common.activity.AbsActivity; @@ -106,7 +107,7 @@ public class SudRyGameActivity extends AbsActivity implements GameRyMicManager.M private List customSidebarChildModels = new ArrayList<>(); private void initDate() { - + CommonAppConfig.getInstance().getConfig().isSw(); LiveNetManager.get(mContext) .getCustomSidebarInfo("1", new HttpCallback>() { @Override diff --git a/live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java b/live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java index eb6ee8efd..baa056c48 100644 --- a/live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/SudSwGameActivity.java @@ -196,7 +196,6 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M }); } - private void onJoinSuccess() { RongChatRoomClient.getInstance().joinChatRoom("v" + mLiveUid, -1, new IRongCoreCallback.OperationCallback() { @Override diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 0eefc39f1..8dc363a62 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -10,10 +10,7 @@ import static com.yunbao.live.views.LivePushSwViewHolder.rtcRoom; import android.app.Dialog; import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.Paint; import android.graphics.drawable.ColorDrawable; import android.os.Handler; import android.os.Looper; @@ -85,11 +82,7 @@ import cn.rongcloud.rtc.api.RCRTCOtherRoom; import cn.rongcloud.rtc.api.RCRTCRemoteUser; import cn.rongcloud.rtc.api.callback.IRCRTCOtherRoomEventsListener; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback; import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; -import cn.rongcloud.rtc.base.RCRTCMediaType; -import cn.rongcloud.rtc.base.RCRTCRoomType; import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.SWManager; import io.rong.imlib.IRongCallback; @@ -150,7 +143,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { private TextView textGrade1, textGrade2, textGrade3, textGrade4; private ImageView imageGrade1, imageGrade2, imageGrade3, imageGrade4; - public LivePushSwViewHolder livePushRyViewHolder; + public LivePushSwViewHolder livePushSwViewHolder; public static List inputStreamList = new ArrayList<>(); public static List inputStreamList1 = new ArrayList<>(); @@ -253,7 +246,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mIsAnchor = isAnchor; mRoot = root; mPkContainer = linkMicViewHolder.getPkContainer(); - livePushRyViewHolder = linkMicViewHolder; + livePushSwViewHolder = linkMicViewHolder; mPkTimeString1 = ""; mPkTimeString2 = mContext.getString(R.string.live_pk_time_2); //从本地取数据 @@ -385,8 +378,8 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); params.weight = 1; params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setLayoutParams(params); + livePushSwViewHolder.camera.setLayoutParams(params); + livePushSwViewHolder.mPreView1.setLayoutParams(params); } Log.i("tts2", s1); @@ -509,8 +502,8 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { public void onLinkDRMicPkApplyOk(UserBean u) { L.eSw("onLinkDRMicPkApplyOk(UserBean u) " + u.getUserNiceName()); int index = 0; - if (livePushRyViewHolder != null) { - livePushRyViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); + if (livePushSwViewHolder != null) { + livePushSwViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); } final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) .param("action", 3) @@ -577,7 +570,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); LiveSwAnchorActivity.isDRPK = 1; - livePushRyViewHolder.setAnPkRtc(u);//设置对方主播视图 + livePushSwViewHolder.setAnPkRtc(u);//设置对方主播视图 final SocketSendBean msg1 = new SocketSendBean() .param("_method_", SOCKET_LINK_MIC_PK).param("action", 4) @@ -595,9 +588,9 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); params.weight = 1; params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setLayoutParams(params); - livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); + livePushSwViewHolder.camera.setLayoutParams(params); + livePushSwViewHolder.mPreView1.setLayoutParams(params); + livePushSwViewHolder.mPreView1.setVisibility(View.VISIBLE); LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); LiveSwAnchorActivity.isDRPK = 1; @@ -640,7 +633,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { }); // TODO: 2024/4/12 视图渲染 - livePushRyViewHolder.setAnPkRtc(bean); + livePushSwViewHolder.setAnPkRtc(bean); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); @@ -653,71 +646,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { }); } - //与用户连麦 - public void setUserMic(String liveid) { - JSONObject msg1 = new JSONObject(); - msg1.put("uid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb()); - msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - - rtcRoom.getLocalUser().responseJoinOtherRoom(liveid, liveid, true, true, msg1.toString(), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - RCRTCEngine.getInstance().joinOtherRoom(liveid, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - Log.e("ry", liveid + "来了!!!!" + rcrtcOtherRoom.getRemoteUsers().size()); - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + rcrtcOtherRoom.getRemoteUsers().size()); - if (stream.getMediaType() == RCRTCMediaType.AUDIO) { - //音频只需要订阅 - inputStreamList.add(stream); - } - } - } - - Log.e("ry", "asa" + inputStreamList.size()); - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - - - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "订阅资源失败: " + rtcErrorCode); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", liveid + "加入其他房间失败 :" + rtcErrorCode); - Log.i("ry", liveid + "加入其他房间失败 :" + rtcErrorCode); - } - }); - - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - ToastUtil.show("接受失败"); - } - }); - } - /** * 显示申请PK的弹窗 */ @@ -800,25 +728,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } - - public static Bitmap fromText(float textSize, String text) { - Paint paint = new Paint(); - paint.setTextSize(textSize); - paint.setTextAlign(Paint.Align.LEFT); - paint.setColor(Color.BLACK); - - Paint.FontMetricsInt fm = paint.getFontMetricsInt(); - int width = (int) paint.measureText(text); - int height = fm.descent - fm.ascent; - - Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - canvas.drawText(text, 0, fm.leading - fm.ascent, paint); - canvas.save(); - - return bitmap; - } - private String TAG = "多人PK"; /** @@ -834,11 +743,11 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { public void run() { if (btn_close != null) { btn_close.setVisibility(View.GONE); - livePushRyViewHolder.timeTitle.setVisibility(View.GONE); + livePushSwViewHolder.timeTitle.setVisibility(View.GONE); } } }); - livePushRyViewHolder.exitChannelDrPk(drPkbeans); + livePushSwViewHolder.exitChannelDrPk(drPkbeans); leaveHandler.removeCallbacks(leaveRunnable); } @@ -847,17 +756,17 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { @Override public void run() { //恢复全屏画面 - livePushRyViewHolder.dr_pk_view.setVisibility(View.GONE); + livePushSwViewHolder.dr_pk_view.setVisibility(View.GONE); //删除之前其他主播的画面 - livePushRyViewHolder.dr1_preview.removeAllViews(); - livePushRyViewHolder.dr2_preview.removeAllViews(); - livePushRyViewHolder.dr3_preview.removeAllViews(); - livePushRyViewHolder.dr4_preview.removeAllViews(); - livePushRyViewHolder.cameraPreview3.removeAllViews(); + livePushSwViewHolder.dr1_preview.removeAllViews(); + livePushSwViewHolder.dr2_preview.removeAllViews(); + livePushSwViewHolder.dr3_preview.removeAllViews(); + livePushSwViewHolder.dr4_preview.removeAllViews(); + livePushSwViewHolder.cameraPreview3.removeAllViews(); leaveHandler.removeCallbacks(leaveRunnable); - livePushRyViewHolder.timeTitle.setVisibility(View.GONE); - livePushRyViewHolder.mPreView.removeView(detailsView1); - livePushRyViewHolder.cameraPreview3.setVisibility(View.GONE); + livePushSwViewHolder.timeTitle.setVisibility(View.GONE); + livePushSwViewHolder.mPreView.removeView(detailsView1); + livePushSwViewHolder.cameraPreview3.setVisibility(View.GONE); } }; @@ -1083,7 +992,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { }); // - int index = livePushRyViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); + int index = livePushSwViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); L.eSw("onLinkDRMicPkApplyOk(UserBean u)-点击接收 1 " + u.getUserNiceName()); L.eSw("發送action = 2"); @@ -1308,7 +1217,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { public void setMyDrPkDetailsView() { if (detailsView1 != null) { - livePushRyViewHolder.dr1_preview.removeView(detailsView1); + livePushSwViewHolder.dr1_preview.removeView(detailsView1); } detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); @@ -1317,7 +1226,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { textGrade1 = detailsView1.findViewById(R.id.text_grade1); textPkName1 = detailsView1.findViewById(R.id.text_pk_name1); imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.dr1_preview.addView(detailsView1); + livePushSwViewHolder.dr1_preview.addView(detailsView1); detailsLinearLayout1.setVisibility(View.GONE); linearGrade1.setVisibility(View.GONE); } @@ -1361,7 +1270,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { L.eSw("j == 0:" + j); //设置多人PK数据 if (detailsView2 != null) { - livePushRyViewHolder.dr2_preview.removeView(detailsView2); + livePushSwViewHolder.dr2_preview.removeView(detailsView2); } detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); @@ -1371,13 +1280,13 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { textGrade2 = detailsView2.findViewById(R.id.text_grade2); imageGrade2.setTag(String.valueOf(drPkbeanList.get(0).getId())); textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); - livePushRyViewHolder.dr2_preview.addView(detailsView2); + livePushSwViewHolder.dr2_preview.addView(detailsView2); detailsLinearLayout2.setVisibility(View.GONE); linearGrade2.setVisibility(View.GONE); } else if (j == 1) { L.eSw("j == 1:" + j); if (detailsView4 != null) { - livePushRyViewHolder.dr4_preview.removeView(detailsView4); + livePushSwViewHolder.dr4_preview.removeView(detailsView4); } detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); @@ -1387,14 +1296,14 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { textGrade4 = detailsView4.findViewById(R.id.text_grade4); imageGrade4.setTag(String.valueOf(drPkbeanList.get(1).getId())); textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); - livePushRyViewHolder.dr4_preview.addView(detailsView4); + livePushSwViewHolder.dr4_preview.addView(detailsView4); detailsLinearLayout4.setVisibility(View.GONE); linearGrade4.setVisibility(View.GONE); } else if (j == 2) { L.eSw("j == 2:" + j); if (detailsView4 != null) { - livePushRyViewHolder.dr4_preview.removeView(detailsView4); + livePushSwViewHolder.dr4_preview.removeView(detailsView4); } detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); @@ -1404,12 +1313,12 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { textGrade4 = detailsView4.findViewById(R.id.text_grade4); imageGrade4.setTag(String.valueOf(drPkbeanList.get(2).getId())); textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); - livePushRyViewHolder.dr4_preview.addView(detailsView4); + livePushSwViewHolder.dr4_preview.addView(detailsView4); detailsLinearLayout4.setVisibility(View.GONE); linearGrade4.setVisibility(View.GONE); if (detailsView3 != null) { - livePushRyViewHolder.dr3_preview.removeView(detailsView3); + livePushSwViewHolder.dr3_preview.removeView(detailsView3); } detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); @@ -1419,7 +1328,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { textGrade3 = detailsView3.findViewById(R.id.text_grade3); imageGrade3.setTag(String.valueOf(drPkbeanList.get(1).getId())); textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); - livePushRyViewHolder.dr3_preview.addView(detailsView3); + livePushSwViewHolder.dr3_preview.addView(detailsView3); detailsLinearLayout3.setVisibility(View.GONE); linearGrade3.setVisibility(View.GONE); @@ -1434,326 +1343,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } - /** - * 多人PK PK主播发过来的已经接受 - */ - public void onDRLinkMicToPk(String u) { - Log.e("eve", u + ""); - /** - * 加入副房间 - * - * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} 或 {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 - * - * @param roomId 房间 ID ,长度 64 个字符,可包含:`A-Z`、`a-z`、`0-9`、`+`、`=`、`-`、`_` - * @param callBack 加入房间回调 - * @group 房间管理 - */ - - /*RCRTCEngine.getInstance().joinOtherRoom(u, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { - rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - - if (livePushRyViewHolder.dr_pk_view.getVisibility() == View.GONE) { - ScreenDimenUtil util = ScreenDimenUtil.getInstance(); - int mScreenWdith = util.getScreenWdith(); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); - params.weight = 1; - params.topMargin = DpUtil.dp2px(123); - livePushRyViewHolder.dr_pk_view.setLayoutParams(params); - livePushRyViewHolder.camera.setLayoutParams(params); - livePushRyViewHolder.dr_pk_view.setVisibility(View.VISIBLE); - livePushRyViewHolder.dr1_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr2_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr3_preview.setVisibility(View.GONE); - livePushRyViewHolder.dr4_preview.setVisibility(View.GONE); - detailsView1 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout1 = detailsView1.findViewById(R.id.lin_pk1); - linearGrade1 = detailsView1.findViewById(R.id.linear_grade1); - imageGrade1 = detailsView1.findViewById(R.id.image_grade1); - textGrade1 = detailsView1.findViewById(R.id.text_grade1); - imageGrade1.setTag(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId())); - livePushRyViewHolder.mPreView.addView(detailsView1); - detailsLinearLayout1.setVisibility(View.VISIBLE); - linearGrade1.setVisibility(View.GONE); - } - - //遍历远端用户列表 - for (int i = 0; i < rcrtcOtherRoom.getRemoteUsers().size(); i++) { - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcOtherRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry111", stream.getMediaType() + ""); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - if (inputStreamList.size() == 0) { - livePushRyViewHolder.dr1_preview.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.dr1_preview.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.dr1_preview.addView(remoteView); - LiveNetManager.get(mContext).getLiveInfo(u, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(String.valueOf(u)); - textPkName2.setText(data.getUserNicename()); - livePushRyViewHolder.dr1_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.VISIBLE); - linearGrade2.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - - } - }); - } else if (inputStreamList.size() == 1) { - livePushRyViewHolder.dr3_preview.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.dr3_preview.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.dr3_preview.addView(remoteView); - LiveNetManager.get(mContext).getLiveInfo(u, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(u); - textPkName4.setText(data.getUserNicename()); - livePushRyViewHolder.dr3_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.VISIBLE); - linearGrade4.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - - } - }); - } else if (inputStreamList.size() == 2) { - livePushRyViewHolder.cameraPreview3.setVisibility(View.VISIBLE); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - livePushRyViewHolder.cameraPreview3.removeAllViews(); - remoteView.setScalingType(SCALE_ASPECT_FILL); - livePushRyViewHolder.cameraPreview3.addView(remoteView); - - LiveNetManager.get(mContext).getLiveInfo(u, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); - linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); - textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); - imageGrade3 = detailsView3.findViewById(R.id.image_grade3); - textGrade3 = detailsView3.findViewById(R.id.text_grade3); - imageGrade3.setTag(u); - textPkName3.setText(data.getUserNicename()); - livePushRyViewHolder.cameraPreview3.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.VISIBLE); - linearGrade3.setVisibility(View.GONE); - } - - @Override - public void onError(String error) { - - } - }); - } - inputStreamList.add(stream); - - } - inputStreamList1.add(stream); - - - } - - //开始订阅资源 - rtcRoom.getLocalUser().subscribeStreams(inputStreamList1, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.i("ry", "订阅资源成功"); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - - //2. 合流画布设置 - rcrtcLiveInfo.setMixConfig(create_Custom_MixConfig(false, inputStreamList), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", inputStreamList.size() + "混成功" + u); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } - - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.i("ry", "加入其他房间失败 :" + rtcErrorCode.getReason()); - } - });*/ - - } - - - /** - * 创建自定义合流布局配置 - * - * @param isCrop 是否裁减画布 - * @param streams 必须为视频流列表 - * @return - */ - private RCRTCMixConfig create_Custom_MixConfig(boolean isCrop, List streams) { - Log.e("视频合流", streams.toString()); - Log.e("视频合流", "视频长度:" + streams.size()); - RCRTCMixConfig config = new RCRTCMixConfig(); - //1. 设置自定义合流布局模式 - config.setLayoutMode(RCRTCMixConfig.MixLayoutMode.CUSTOM); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); - //视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); - //大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - videoConfig.setVideoLayout(normal); - //推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 - //如不设置宽高值则服务端将使用默认宽高 360 * 640 - //例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, - //所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig(); - int fps = defaultVideoConfig.getVideoFps().getFps(); - int width = 960; - int height = 720; - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(fps); //视频帧率 - - //2. 合流画布设置 - //(请参照画布和声音配置示例代码) - //3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高 - ArrayList list = new ArrayList<>(); - - if (streams.size() == 1) { - //user1的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video - videoLayout1.setX(0); //X 坐标 - videoLayout1.setY(0); //Y 坐标 - videoLayout1.setWidth(480); // 视频窗口的宽 - videoLayout1.setHeight(720); // 视频窗口的高 - list.add(videoLayout1); - - //user2的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video - videoLayout2.setX(480); //X 坐标 - videoLayout2.setY(0); //Y 坐标 - videoLayout2.setWidth(480); // 视频窗口的宽 - videoLayout2.setHeight(720); // 视频窗口的高 - list.add(videoLayout2); - - } else if (streams.size() == 2) { - //user1的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - list.add(videoLayout1); - videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video - videoLayout1.setX(0); //X 坐标 - videoLayout1.setY(0); //Y 坐标 - videoLayout1.setWidth(480); // 视频窗口的宽 - videoLayout1.setHeight(720); // 视频窗口的高 - - //user2的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video - videoLayout2.setX(480); //X 坐标 - videoLayout2.setY(0); //Y 坐标 - videoLayout2.setWidth(480); // 视频窗口的宽 - videoLayout2.setHeight(360); // 视频窗口的高 - list.add(videoLayout2); - - //user3的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout3 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout3.setVideoStream(streams.get(1)); // RCRTCStream#MediaType 必须是Video - videoLayout3.setX(480); //X 坐标 - videoLayout3.setY(360); //Y 坐标 - videoLayout3.setWidth(480); // 视频窗口的宽 - videoLayout3.setHeight(360); // 视频窗口的高 - list.add(videoLayout3); - - } else if (streams.size() == 3) { - //user1的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video - videoLayout1.setX(0); //X 坐标 - videoLayout1.setY(0); //Y 坐标 - videoLayout1.setWidth(480); // 视频窗口的宽 - videoLayout1.setHeight(720); // 视频窗口的高 - list.add(videoLayout1); - - //user2的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout2 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout2.setVideoStream(streams.get(0)); // RCRTCStream#MediaType 必须是Video - videoLayout2.setX(480); //X 坐标 - videoLayout2.setY(0); //Y 坐标 - videoLayout2.setWidth(480); // 视频窗口的宽 - videoLayout2.setHeight(360); // 视频窗口的高 - list.add(videoLayout2); - - //user3的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout3 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout3.setVideoStream(streams.get(1)); // RCRTCStream#MediaType 必须是Video - videoLayout3.setX(480); //X 坐标 - videoLayout3.setY(360); //Y 坐标 - videoLayout3.setWidth(480); // 视频窗口的宽 - videoLayout3.setHeight(360); // 视频窗口的高 - list.add(videoLayout3); - - //user3的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout4 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - videoLayout4.setVideoStream(streams.get(2)); // RCRTCStream#MediaType 必须是Video - videoLayout4.setX(0); //X 坐标 - videoLayout4.setY(360); //Y 坐标 - videoLayout4.setWidth(480); // 视频窗口的宽 - videoLayout4.setHeight(360); // 视频窗口的高 - list.add(videoLayout4); - } - config.setCustomLayouts(list); - return config; - } - @Override public void onClick(View v) { int i = v.getId(); @@ -2092,18 +1681,18 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { String userID1 = (String) imageGrade1.getTag(); String userID2 = (String) imageGrade2.getTag(); String userID4 = (String) imageGrade4.getTag(); - if (livePushRyViewHolder.timeTitle.getVisibility() == View.GONE) { + if (livePushSwViewHolder.timeTitle.getVisibility() == View.GONE) { mHandler.removeMessages(WHAT_PK_TIME2); - RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) livePushRyViewHolder.timeTitle.getLayoutParams(); + RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) livePushSwViewHolder.timeTitle.getLayoutParams(); layoutParams.topMargin = DpUtil.dp2px(123); - livePushRyViewHolder.timeTitle.setLayoutParams(layoutParams); - livePushRyViewHolder.timeTitle.setVisibility(View.VISIBLE); + livePushSwViewHolder.timeTitle.setLayoutParams(layoutParams); + livePushSwViewHolder.timeTitle.setVisibility(View.VISIBLE); String pkTime = StringUtil.getDurationText(time * 1000); - livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime)); + livePushSwViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime)); mPkTimeCount = time; if (time > 0) { String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); - livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); + livePushSwViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); mHandler.sendEmptyMessage(WHAT_PK_TIME2); } } @@ -2304,11 +1893,11 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { if (mPkTimeCount > 0) {// if (mHandler != null) { String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); - livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); + livePushSwViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME2, getNextSecondTime()); } } else { - livePushRyViewHolder.timeTitle.setVisibility(View.GONE); + livePushSwViewHolder.timeTitle.setVisibility(View.GONE); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index 57e2d62ae..26be83560 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -73,7 +73,7 @@ import com.yunbao.live.event.LiveAnchorEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.views.LiveEndViewHolder; import com.yunbao.live.views.LivePlayKsyViewHolder; -import com.yunbao.live.views.LivePlaySwViewHolder; +import com.yunbao.live.views.LivePlayRyViewHolder; import com.yunbao.live.views.LivePushRyViewHolder; import com.yunbao.live.views.LiveRoomViewHolder; @@ -277,15 +277,15 @@ public class SocketRyClient { if (LivePlayKsyViewHolder.leave != null) { LivePlayKsyViewHolder.leave.setVisibility(View.VISIBLE); } - if (LivePlaySwViewHolder.leave != null) { - LivePlaySwViewHolder.leave.setVisibility(View.VISIBLE); + if (LivePlayRyViewHolder.leave != null) { + LivePlayRyViewHolder.leave.setVisibility(View.VISIBLE); } } else if (action21 == 13 && map.getString("ct").contains("回來")) { if (LivePlayKsyViewHolder.leave != null) { LivePlayKsyViewHolder.leave.setVisibility(View.GONE); } - if (LivePlaySwViewHolder.leave != null) { - LivePlaySwViewHolder.leave.setVisibility(View.GONE); + if (LivePlayRyViewHolder.leave != null) { + LivePlayRyViewHolder.leave.setVisibility(View.GONE); } } break; diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index f0603a13e..51769d176 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -277,14 +277,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public PortraitLiveManager(Activity context, Intent intent) { this.mContext = context; this.mIntent = intent; - isSw = intent.getBooleanExtra("isSw", false); + isSw = intent.getBooleanExtra(Constants.LIVE_SDK_IS_SW, false); liveImDeletUtil = new LiveImDeletUtil(); portraitLiveManager = this; ininView(); AppManager.runDebugCode(() -> waitShowTopBannerTime = 1000); } - /** * 初始化布局 */ @@ -404,7 +403,6 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); } - mLivePlayViewHolder.addToParent(); mLivePlayViewHolder.subscribeActivityLifeCycle(); mLivePlayViewHolder.setLoadViewListener(new LiveRoomPlayViewHolder.LoadingListener() { @@ -434,8 +432,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } //去除主播离开画面 - if (LivePlayKsyViewHolder.leave != null) { - LivePlayKsyViewHolder.leave.setVisibility(View.GONE); + if (LivePlayRyViewHolder.leave != null) { + LivePlayRyViewHolder.leave.setVisibility(View.GONE); } if (LivePlaySwViewHolder.leave != null) { LivePlaySwViewHolder.leave.setVisibility(View.GONE); diff --git a/live/src/main/res/layout/view_live_push_sw.xml b/live/src/main/res/layout/view_live_push_sw.xml index d60609cbe..b6d31d27b 100644 --- a/live/src/main/res/layout/view_live_push_sw.xml +++ b/live/src/main/res/layout/view_live_push_sw.xml @@ -115,12 +115,34 @@ android:layout_height="match_parent" /> + + + + + + + + + - - - - - - - - - Date: Wed, 22 May 2024 13:46:52 +0800 Subject: [PATCH 21/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=90=88=E5=B9=B6]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/common/bean/AiAutomaticSpeechModel.java | 12 ------------ .../java/com/yunbao/common/utils/AppManager.java | 9 --------- .../main/java/com/yunbao/live/bean/LiveChatBean.java | 6 ------ .../yunbao/live/presenter/LiveGiftAnimPresenter.java | 2 +- .../yunbao/main/dialog/MainStartDialogFragment.java | 2 +- 5 files changed, 2 insertions(+), 29 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java b/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java index e912b9ac4..33d328d42 100644 --- a/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java +++ b/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java @@ -30,9 +30,6 @@ public class AiAutomaticSpeechModel extends BaseModel { //气泡背景 @SerializedName("system_bubble") private String systemBubble; - @SerializedName("icon_en") - @JSONField(name = "icon_en") - private String iconEn; public String getNameColor() { return nameColor; @@ -52,15 +49,6 @@ public class AiAutomaticSpeechModel extends BaseModel { return this; } - public String getIconEn() { - return iconEn; - } - - public AiAutomaticSpeechModel setIconEn(String iconEn) { - this.iconEn = iconEn; - return this; - } - public String getContent() { return content; } diff --git a/common/src/main/java/com/yunbao/common/utils/AppManager.java b/common/src/main/java/com/yunbao/common/utils/AppManager.java index 5b271108a..f27c2815a 100644 --- a/common/src/main/java/com/yunbao/common/utils/AppManager.java +++ b/common/src/main/java/com/yunbao/common/utils/AppManager.java @@ -62,15 +62,6 @@ public class AppManager { activityStack.add(activity); } - public Activity getMainActivity() { - for (Activity activity : activityStack) { - if (activity.getClass().getSimpleName().contains("MainActivity")) { - return activity; - } - } - return null; - } - /** * 移除Activity */ diff --git a/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java b/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java index 689d3d344..e074fd2fa 100644 --- a/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java +++ b/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java @@ -60,8 +60,6 @@ public class LiveChatBean { private String giftname_en; private String toUid; - private String medal_new_en; - public int getNORMAL() { return NORMAL; } @@ -214,10 +212,6 @@ public class LiveChatBean { return medal_new_en; } - public void setMedal_new_en(String medal_new_en) { - this.medal_new_en = medal_new_en; - } - public String getHot_card() { return hot_card; } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java index d5eea4f3f..6909894a4 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java @@ -459,7 +459,7 @@ public class LiveGiftAnimPresenter { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { if (liveBean == null) { return; } diff --git a/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java b/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java index f12065e51..7c8da569f 100644 --- a/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java +++ b/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java @@ -22,7 +22,6 @@ import android.widget.LinearLayout; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.umeng.analytics.MobclickAgent; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; @@ -32,6 +31,7 @@ import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.utils.PluginManager; import com.yunbao.common.utils.ProcessResultUtil; import com.yunbao.common.utils.ToastUtil; From 26a71ff82560caf1bf081ce616f963d80f3b3169 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Wed, 22 May 2024 18:29:11 +0800 Subject: [PATCH 22/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beautyapi/faceunity/agora/SWManager.java | 1 - .../yunbao/live/socket/SocketSwChatUtil.java | 48 +++++++++---------- .../yunbao/live/socket/SocketSwClient.java | 1 + .../live/views/LivePlaySwViewHolder.java | 6 +-- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 93ba3273d..3bf15d9d8 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -127,7 +127,6 @@ public class SWManager extends BaseCacheManager { anchorContainer.addView(surfaceView); Config config = new Config(mContext, mRtcEngine, FURenderer.INSTANCE.mFURenderKit, null, CaptureMode.Agora, 0, false, new CameraConfig(MirrorMode.MIRROR_NONE, MirrorMode.MIRROR_NONE)); faceUnityBeautyAPI.initialize(config); - faceUnityBeautyAPI.enable(false); faceUnityBeautyAPI.setBeautyPreset(BeautyPreset.CUSTOM); //FaceUnityBeautyManage.getInstance().mFURenderKit.setFaceBeauty(); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java index c1f1228e6..91f5e2239 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java @@ -64,8 +64,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -128,8 +128,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } LiveNetManager.get(CommonAppContext.sInstance) .addChatCount(LiveActivity.mStream, new com.yunbao.common.http.base.HttpCallback() { @@ -214,8 +214,8 @@ public class SocketSwChatUtil { } } }); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -263,8 +263,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -400,8 +400,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -470,8 +470,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -517,8 +517,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -554,8 +554,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -597,8 +597,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } @Override @@ -634,8 +634,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -674,8 +674,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } @@ -778,8 +778,8 @@ public class SocketSwChatUtil { @Override public void onSuccess(Message message) { Log.i("tx", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg.mResult.toString() + ""); } } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index aec44def7..f54c8eb66 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -1348,6 +1348,7 @@ public class SocketSwClient { .param("msgtype", 2) .param("uid", CommonAppConfig.getInstance().getUid()) .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("random_pk", "1") .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java index 2dbe65889..39ec37fa7 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -1086,11 +1086,7 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { public void UsertoRY() { userinputStreamList.clear(); Log.e("ry", "主播同意了UsertoRY"); - if (userJoinLinkMic) {//已经在房间内,不再joinRoom直接去连麦 - //subscribeMic(rcrtcRoom); - joinLiveMic(); - return; - } + joinLiveMic(); /*RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO).setLiveRole(RCRTCLiveRole.AUDIENCE).build(); From cf48be7d15001d245e3d95a63e7889f71f8548b3 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Tue, 28 May 2024 13:44:44 +0800 Subject: [PATCH 23/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/common/views/AbsViewHolder.java | 4 + gradle.properties | 4 +- .../faceunity/agora/LiveFloatView.java | 17 ++- .../faceunity/agora/SWAuManager.java | 76 +++++++++--- .../beautyapi/faceunity/agora/SWManager.java | 17 ++- .../live/activity/LiveAnchorActivity.java | 2 +- .../live/activity/LiveAudienceActivity.java | 9 +- .../live/activity/LiveRyAnchorActivity.java | 11 +- .../live/activity/LiveSwAnchorActivity.java | 8 +- .../adapter/AnchorUserMicInfoAdapter.java | 32 +++--- .../live/adapter/FreePkRecyclerAdapter.java | 2 +- .../java/com/yunbao/live/bean/LivePkBean.java | 14 +++ .../live/dialog/FreePkDialogFragment.java | 6 +- .../presenter/LiveRyLinkMicPkPresenter.java | 33 +++++- .../presenter/LiveSwLinkMicPkPresenter.java | 51 ++++++--- .../yunbao/live/socket/SocketSwClient.java | 108 +++++++++--------- .../live/socket/SocketSwLinkMicPkUtil.java | 7 +- .../live/views/LivePlaySwViewHolder.java | 68 ++++++++++- .../live/views/LivePushSwViewHolder.java | 6 +- .../live/views/PortraitLiveManager.java | 36 ++++-- .../src/main/res/layout/view_live_push_sw.xml | 46 ++++---- 21 files changed, 400 insertions(+), 157 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/views/AbsViewHolder.java b/common/src/main/java/com/yunbao/common/views/AbsViewHolder.java index 30a155779..fef359955 100644 --- a/common/src/main/java/com/yunbao/common/views/AbsViewHolder.java +++ b/common/src/main/java/com/yunbao/common/views/AbsViewHolder.java @@ -65,6 +65,10 @@ public abstract class AbsViewHolder implements LifeCycleListener { } } + public boolean isShow(){ + return mParentView.indexOfChild(mContentView)>-1; + } + public void removeFromParent() { ViewParent parent = mContentView.getParent(); if (parent != null) { diff --git a/gradle.properties b/gradle.properties index 38b11a081..f8c588910 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ # org.gradle.parallel=true #Thu Feb 04 00:05:45 CST 2021 android.injected.testOnly=false -org.gradle.daemon=true +org.gradle.daemon=true org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.parallel=true org.gradle.configureondemand=true @@ -25,4 +25,6 @@ systemProp.http.proxyHost=127.0.0.1 systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyPort=10809 systemProp.http.proxyPort=10809 + + #android.enableR8.fullMode=true \ No newline at end of file diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java index 7a336a381..26e22e858 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java @@ -94,7 +94,7 @@ public class LiveFloatView implements Function1 { swAuManager.initRtcEngine( mContext); swAuManager.setupRemoteVideo(Integer.parseInt(mLiveBean.getUid())); //进入主播房间 - swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(mLiveBean.getUid())); + swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,mLiveBean.getUid(), SWAuManager.getChannelName(mLiveBean.getUid())); }else{ videoView = magnetView.findViewById(R.id.video_view); mPlayer = new TXLivePlayer(mContext); @@ -145,7 +145,7 @@ public class LiveFloatView implements Function1 { }); if(mLiveSDK == Constants.LIVE_SDK_SW){ ViewClicksAntiShake.clicksAntiShake(videoFrameLayout, () -> { - mPlayer.stopPlay(true); + SWAuManager.get().exitChannelAll(); APPEasyFloat.getInstance().dismiss(mContext); new Handler().post(liveCheck); }); @@ -166,8 +166,13 @@ public class LiveFloatView implements Function1 { @Override public void dismiss() { - if (mPlayer != null) - mPlayer.stopPlay(true); + if(mLiveSDK == Constants.LIVE_SDK_SW){ + SWAuManager.get().exitChannelAll(); + }else{ + if (mPlayer != null) + mPlayer.stopPlay(true); + } + } }) .show(mContext); @@ -192,7 +197,7 @@ public class LiveFloatView implements Function1 { public LiveFloatView cacheLiveData(LiveBean mLiveBean, int mLiveType, int mLiveSDK, int mLiveTypeVal) { this.mLiveBean = mLiveBean; this.mLiveType = mLiveType; - this.mLiveSDK = Constants.LIVE_SDK_SW; + this.mLiveSDK = mLiveSDK; this.mLiveTypeVal = mLiveTypeVal; return instance; } @@ -249,7 +254,7 @@ public class LiveFloatView implements Function1 { swAuManager.initRtcEngine( mContext); swAuManager.setupRemoteVideo(Integer.parseInt(mLiveBean.getUid())); //进入主播房间 - swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(mLiveBean.getUid())); + swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, mLiveBean.getUid(),SWAuManager.getChannelName(mLiveBean.getUid())); }else{ TXCloudVideoView videoView = view.findViewById(R.id.video_view); mPlayer = new TXLivePlayer(mContext); diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index 26ceb75c6..63ca6e76a 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -2,15 +2,24 @@ package io.agora.beautyapi.faceunity.agora; import android.app.Activity; import android.content.Context; +import android.util.Log; import android.view.SurfaceView; import android.widget.FrameLayout; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.http.API; +import com.yunbao.common.http.ResponseModel; +import com.yunbao.common.manager.MicUserManager; +import com.yunbao.common.manager.MicedUserManager; import com.yunbao.common.manager.base.BaseCacheManager; +import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.L; import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; import io.agora.rtc2.ChannelMediaOptions; import io.agora.rtc2.Constants; @@ -19,6 +28,15 @@ import io.agora.rtc2.RtcConnection; import io.agora.rtc2.RtcEngineConfig; import io.agora.rtc2.RtcEngineEx; import io.agora.rtc2.video.VideoCanvas; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.functions.Consumer; +import io.reactivex.schedulers.Schedulers; +import io.rong.imkit.IMCenter; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; +import io.rong.message.TextMessage; /** * 声网主播管理类 @@ -37,6 +55,14 @@ public class SWAuManager extends BaseCacheManager { private FrameLayout pkContainer3; //pk主播视图3 private FrameLayout linkUserContainer;//连麦用户视图 + private int liveMicUid; + + private SwListener swListener; + + public void setSwListener(SwListener swListener) { + this.swListener = swListener; + } + public SWAuManager(Context context) { super(context); } @@ -57,13 +83,13 @@ public class SWAuManager extends BaseCacheManager { @Override public void onJoinChannelSuccess(String channel, int uid, int elapsed) { super.onJoinChannelSuccess(channel, uid, elapsed); - L.eSw("加入房间成功 channel"+channel+" uid"+uid); + L.eSw("加入房间成功 channel" + channel + " uid" + uid); } @Override public void onUserJoined(int uid, int elapsed) { super.onUserJoined(uid, elapsed); - L.eSw("用户加入房间成功"+uid); + L.eSw("用户加入房间成功" + uid); } }; @@ -84,8 +110,6 @@ public class SWAuManager extends BaseCacheManager { throw new RuntimeException("Check the error."); } mRtcEngine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING); // 直播模式,引擎級別 - // 启用视频模块 - mRtcEngine.enableVideo(); // 开启本地预览 //mRtcEngine.startPreview(); } @@ -112,19 +136,20 @@ public class SWAuManager extends BaseCacheManager { /** * 创建语音房 + * * @param token * @param channelName * @param uid */ - public void joinAudioRoom(String channelName,String token,int uid){ - L.eSw("加入房间"+channelName+" uid"+uid); + public void joinAudioRoom(String channelName, String token, int uid) { + L.eSw("加入房间" + channelName + " uid" + uid); + // 直播场景下,设置频道场景为 BROADCASTING (直播场景) + mRtcEngine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING); // 创建 ChannelMediaOptions 对象,并进行配置 ChannelMediaOptions options = new ChannelMediaOptions(); // 根据场景将用户角色设置为 AUDIENCE (观众) options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; - // 直播场景下,设置频道场景为 BROADCASTING (直播场景) - options.audienceLatencyLevel = Constants.CHANNEL_PROFILE_LIVE_BROADCASTING; // 觀眾走極速直播 - options.autoSubscribeVideo = false; + mRtcEngine.disableVideo(); options.autoSubscribeAudio = true; mRtcEngine.joinChannel(token, channelName, uid, options); } @@ -148,7 +173,8 @@ public class SWAuManager extends BaseCacheManager { /** * 加入房间 */ - public void joinRoom(String strUid, String token, String channelName) { + public void joinRoom(String strUid, String token, String liveUid, String channelName) { + liveMicUid = Integer.parseInt(liveUid); int uid; if (StringUtil.isEmpty(strUid)) { uid = 0; @@ -159,6 +185,13 @@ public class SWAuManager extends BaseCacheManager { SurfaceView surfaceView = new SurfaceView(mContext); audienceContainer.addView(surfaceView); + // 启用视频模块 + mRtcEngine.enableVideo(); + + //走媒体音量,和音质有关 + mRtcEngine.setAudioProfile(Constants.AUDIO_PROFILE_MUSIC_HIGH_QUALITY); + mRtcEngine.setAudioScenario(Constants.AUDIO_SCENARIO_GAME_STREAMING); + // 创建 ChannelMediaOptions 对象,并进行配置 ChannelMediaOptions options = new ChannelMediaOptions(); // 根据场景将用户角色设置为 AUDIENCE (观众) @@ -229,10 +262,11 @@ public class SWAuManager extends BaseCacheManager { mRtcEngine.updateChannelMediaOptions(options); } - public void setMicAudio(int toUid,boolean isEn) { - L.eSw("setMicAudio:toUid" +toUid+"isEn "+ isEn); - mRtcEngine.muteRemoteAudioStream(toUid,isEn); + public void setMicAudio(int toUid, boolean isEn) { + L.eSw("setMicAudio:toUid" + toUid + "isEn " + isEn); + mRtcEngine.muteRemoteAudioStream(toUid, isEn); } + /** * PK-加入对方主播直播间 * @@ -310,7 +344,7 @@ public class SWAuManager extends BaseCacheManager { */ public void exitChannelAll() { L.eSw("exitChannelAll exitChannelAll exitChannelAll"); - if(mRtcEngine!=null){ + if (mRtcEngine != null) { mRtcEngine.leaveChannel(); } } @@ -336,6 +370,17 @@ public class SWAuManager extends BaseCacheManager { } }); } + + @Override + public void onUserOffline(int uid, int reason) { + super.onUserOffline(uid, reason); + L.eSw("onUserOffline: uid " + uid + " reason" + reason); + if (liveMicUid == uid) { + if (swListener != null) { + swListener.onUserOffline(liveMicUid); + } + } + } }; //设置对方主播视图 @@ -367,4 +412,7 @@ public class SWAuManager extends BaseCacheManager { this.linkUserContainer = linkUserContainer; } + public interface SwListener { + void onUserOffline(int liveUid); + } } diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 3bf15d9d8..2b7934d3b 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -117,7 +117,7 @@ public class SWManager extends BaseCacheManager { cfg.dimensions = VideoEncoderConfiguration.VD_1920x1080; break; } - cfg.frameRate = 24; + cfg.frameRate = 20; cfg.bitrate = 0; cfg.mirrorMode = VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_ENABLED; //镜像 mRtcEngine.setVideoEncoderConfiguration(cfg); @@ -148,7 +148,10 @@ public class SWManager extends BaseCacheManager { /** * 设置清晰度 - * + * 单人直播:720x1280 + * 2人连麦PK:360x640 + * 3人连麦PK:左侧主播 360x640,右侧两个主播 360x320 + * 4人连麦PK:360X320 * @param selectClarity */ public void setDimensions(int selectClarity) { @@ -221,6 +224,10 @@ public class SWManager extends BaseCacheManager { ChannelMediaOptions options = new ChannelMediaOptions(); // 设置角色 BROADCASTER (主播) 或 AUDIENCE (观众) options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; + + mRtcEngine.setAudioProfile(Constants.AUDIO_PROFILE_MUSIC_HIGH_QUALITY); + mRtcEngine.setAudioScenario(Constants.AUDIO_SCENARIO_GAME_STREAMING); + // 加入频道 mRtcEngine.joinChannel(token, channelName, uid, options); } @@ -297,6 +304,12 @@ public class SWManager extends BaseCacheManager { super.onError(err); L.eSw("onError:" + err); } + + @Override + public void onVideoSizeChanged(Constants.VideoSourceType source, int uid, int width, int height, int rotation) { + super.onVideoSizeChanged(source, uid, width, height, rotation); + L.eSw("uid:"+uid+"\nwidth:"+width+"\nheight:"+height); + } }); } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java index 250c1ffbe..75e1bbd4b 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAnchorActivity.java @@ -941,7 +941,7 @@ public class LiveAnchorActivity extends LiveActivity implements LiveFunctionClic } }); } else { - ToastUtil.show("主播正在PK,稍後再試"); + ToastUtil.show(mContext.getString(R.string.pking_over)); } } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 5ab28a083..c17dc9e25 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -366,8 +366,6 @@ public class LiveAudienceActivity extends LiveActivity { loadData(viewGroup, mCurrentItem); } } - - }); getDrawer(); @@ -412,7 +410,9 @@ public class LiveAudienceActivity extends LiveActivity { } else { new LiveRoomCheckLivePresenter(mContext, data.getUid(), data.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw1) { + L.eSw("onLiveRoomChanged:"+isSw1); + isSw = isSw1; liveIndex = false; try { mLiveSDK = Integer.parseInt(liveSdk); @@ -915,10 +915,11 @@ public class LiveAudienceActivity extends LiveActivity { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw1) { if (liveBean == null) { return; } + isSw = isSw1; if (MicStatusManager.getInstance().isMic(liveUid)) { MicStatusManager.getInstance().showDownMicDialog(mContext); return; diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 77684997f..2a8a7fc6c 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -1237,8 +1237,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl JSONObject obj = JSON.parseObject(info[0]); if (obj != null) { if (obj.getString("ispk").equals("0")) { - - IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { @Override public void onSuccess() { @@ -1270,7 +1268,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl }); } else { - ToastUtil.show("主播正在PK,稍後再試"); + ToastUtil.show(mContext.getString(R.string.pking_over)); if (RandomPkManager.getInstance().isRandomModel()) { RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); } @@ -1345,7 +1343,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl } }); } else { - ToastUtil.show("主播正在PK,稍後再試"); + ToastUtil.show(mContext.getString(R.string.pking_over)); } } } @@ -1648,7 +1646,10 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl } if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.seisShowGif(true); - mLiveRoomViewHolder.endDRGif(); + if(isDRPK==1){ + mLiveRoomViewHolder.endDRGif(); + } + } // if (mLiveRoomViewHolder != null) { // mLiveRoomViewHolder.hotAddVisibility(false); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index c3e5a1265..25fe644df 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -1262,7 +1262,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl } }); } else { - ToastUtil.show("主播正在PK,稍後再試"); + ToastUtil.show(mContext.getString(R.string.pking_over)); if (RandomPkManager.getInstance().isRandomModel()) { RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); } @@ -1341,7 +1341,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl } }); } else { - ToastUtil.show("主播正在PK,稍後再試"); + ToastUtil.show(mContext.getString(R.string.pking_over)); } } } @@ -1645,7 +1645,9 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl } if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.seisShowGif(true); - mLiveRoomViewHolder.endDRGif(); + if(isDRPK==1){ + mLiveRoomViewHolder.endDRGif(); + } } // if (mLiveRoomViewHolder != null) { // mLiveRoomViewHolder.hotAddVisibility(false); diff --git a/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java b/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java index 923055085..7304344a7 100644 --- a/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java @@ -21,6 +21,7 @@ import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.MsgSwitchFollowlModel; import com.yunbao.common.bean.UserBean; import com.yunbao.common.custom.CommonRefreshView; import com.yunbao.common.dialog.AbsDialogFragment; @@ -34,6 +35,7 @@ import com.yunbao.common.utils.CommonIconUtil; import com.yunbao.common.utils.SVGAViewUtils; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.socket.SocketSendBean; @@ -123,23 +125,23 @@ public class AnchorUserMicInfoAdapter extends RefreshAdapter { if (MicedUserManager.get().getMicUserList().size() < 3) { if (v.getTag() != null) { UserBean tag = (UserBean) v.getTag(); - if (tag.getTypeMic() == TYPE_MIC_REQUEST) { - SocketSendBean bean = createSocketSendBean().param("targetId", tag.getId()); - applyMic(tag, 1, bean); - ToastUtil.show(mContext.getString(R.string.live_mic_invite)); - } else if (tag.getTypeMic() == TYPE_MIC_INVITE) { - applyMic(tag, 4, createSocketSendBean()); - ToastUtil.show(mContext.getString(R.string.live_mic_request)); - for (int i = 0; i < mList.size(); i++) { - if (TextUtils.equals(mList.get(i).getId(), tag.getId())) { - mList.get(i).setRequest(true); - notifyItemChanged(i); + ViewClicksAntiShake.clicksAntiShake(mBtn, () -> { + if (tag.getTypeMic() == TYPE_MIC_REQUEST) { + applyMic(tag, 4, createSocketSendBean()); + ToastUtil.show(mContext.getString(R.string.live_mic_request)); + for (int i = 0; i < mList.size(); i++) { + if (TextUtils.equals(mList.get(i).getId(), tag.getId())) { + mList.get(i).setRequest(true); + notifyItemChanged(i); + } } + } else if (tag.getTypeMic() == TYPE_MIC_INVITE) { + SocketSendBean bean = createSocketSendBean().param("targetId", tag.getId()); + applyMic(tag, 1, bean); + ToastUtil.show(mContext.getString(R.string.live_mic_invite)); } - - } + }); } - }else { ToastUtil.show(mContext.getString(R.string.live_mic_max)); } @@ -167,7 +169,7 @@ public class AnchorUserMicInfoAdapter extends RefreshAdapter { return new SocketSendBean() .param("_method_", Constants.LIAN_MAI) .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("avatar", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("uid", CommonAppConfig.getInstance().getUid()); } diff --git a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java index 065f13413..648a042cf 100644 --- a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java @@ -132,7 +132,7 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { } if (freePkNum == 0 && mDrPkNum == -1) { ToastUtil.show(mContext.getString(R.string.free_pk_num_null)); - // return; + return; } LiveHttpUtil.getMicList(liveUid, 0, new com.yunbao.common.http.HttpCallback() { @Override diff --git a/live/src/main/java/com/yunbao/live/bean/LivePkBean.java b/live/src/main/java/com/yunbao/live/bean/LivePkBean.java index 14dde6181..5522c0e76 100644 --- a/live/src/main/java/com/yunbao/live/bean/LivePkBean.java +++ b/live/src/main/java/com/yunbao/live/bean/LivePkBean.java @@ -17,6 +17,7 @@ public class LivePkBean { private String avatar; private String stream; private String pkUid; + private String drpkStatus; private int level; private int levelAnchor; private int sex; @@ -69,6 +70,19 @@ public class LivePkBean { this.stream = stream; } + @JSONField(name="drpk_status") + public String getDrpkStatus(){ + if (drpkStatus == null) { + drpkStatus = "0"; + } + return drpkStatus; + } + + @JSONField(name = "drpk_status") + public void setDrpkStatus(String drpkStatus) { + this.drpkStatus = drpkStatus; + } + @JSONField(name = "pkuid") public String getPkUid() { if (pkUid == null) { diff --git a/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java index 18275126c..b5520e1f5 100644 --- a/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java @@ -343,7 +343,11 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl userBean.setId(bean.getUid()); userBean.setUserNiceName(bean.getUserNiceName()); userBean.setAvatar(bean.getAvatar()); - userBean.setPk(bean.getPkUid().equals("0") ? 0 : 1); + if(bean.getPkUid().equals("0")||bean.getDrpkStatus().equals("0")){ + userBean.setPk(0); + }else{ + userBean.setPk(1); + } userBean.setAttention("1"); list.add(userBean); } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 4c4f563ed..80ed11380 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -35,6 +35,7 @@ import android.widget.PopupWindow; import android.widget.RelativeLayout; import android.widget.TextView; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.tencent.trtc.TRTCCloud; @@ -45,6 +46,7 @@ import com.yunbao.common.event.AnchorInfoEvent; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMRTCManager; @@ -1047,7 +1049,20 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); } if (mAcceptPk) { - isPK(u); + + LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (obj.getString("ispk").equals("0")) { + isPK(u); + }else{ + ToastUtil.show(mContext.getString(R.string.pking_over)); + } + } + }}}); } else { if (mPkWaitCount < 0) { rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { @@ -1391,7 +1406,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); } if (mAcceptPk) { - HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive") .params("uid", CommonAppConfig.getInstance().getUid()) .params("pkuid", u.getId()) @@ -1522,6 +1536,21 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } }); + /*LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (obj.getString("ispk").equals("0")) { + + + }else{ + ToastUtil.show(mContext.getString(R.string.pking_over)); + } + } + } + }});*/ } else { if (mPkWaitCount < 0) { diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 8dc363a62..fd690e02c 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -29,16 +29,22 @@ import android.widget.PopupWindow; import android.widget.RelativeLayout; import android.widget.TextView; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; +import com.tencent.imsdk.v2.V2TIMManager; +import com.tencent.imsdk.v2.V2TIMMessage; +import com.tencent.imsdk.v2.V2TIMSendCallback; import com.tencent.trtc.TRTCCloud; import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.Constants; import com.yunbao.common.bean.UserBean; import com.yunbao.common.event.AnchorInfoEvent; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMRTCManager; @@ -109,7 +115,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { private Context mContext; private View mRoot; private boolean mIsAnchor;//自己是否是主播 - private SocketSwClient mSocketRyClient; + private SocketSwClient mSocketSwClient; private ViewGroup mPkContainer; private boolean mIsApplyDialogShow;//是否显示了申请PK的弹窗 private boolean mAcceptPk;//是否接受连麦 @@ -285,7 +291,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } public void setSocketRyClient(SocketSwClient SocketRyClient) { - mSocketRyClient = SocketRyClient; + mSocketSwClient = SocketRyClient; } public void setLiveUid(String liveUid, String url) { @@ -471,7 +477,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { return; } mPkSend = true; - SocketSwLinkMicPkUtil.linkMicPkApply(mSocketRyClient, pkUid, stream); + SocketSwLinkMicPkUtil.linkMicPkApply(mSocketSwClient, pkUid, stream); ToastUtil.show(mContext.getString(R.string.link_mic_apply_pk)); if (mLiveLinkMicPkViewHolder == null) { @@ -571,13 +577,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); LiveSwAnchorActivity.isDRPK = 1; livePushSwViewHolder.setAnPkRtc(u);//设置对方主播视图 - - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK).param("action", 4) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", u.getId()).param("uid", CommonAppConfig.getInstance().getUid()) - .param("pkhead", u.getAvatar()).param("pkname", u.getUserNiceName()); - msg1.create(); LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); } @@ -639,7 +638,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); LiveSwAnchorActivity.isDRPK = 1; LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); - SocketSwLinkMicPkUtil.linkMicPkAccept(mSocketRyClient, mApplyUid, mApplyUrl, mApplyNmae); + SocketSwLinkMicPkUtil.linkMicPkAccept(mSocketSwClient, mApplyUid, mApplyUrl, mApplyNmae); EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid)); onLinkMicPkStart(mApplyUid, 2); } @@ -668,6 +667,19 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } if (mAcceptPk) { isPK(u); + /*LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (obj.getString("ispk").equals("0")) { + isPK(u); + }else{ + ToastUtil.show(mContext.getString(R.string.pking_over)); + } + } + }}});*/ } else { if (mPkWaitCount < 0) { if(rtcRoom==null){ @@ -908,7 +920,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); } if (mAcceptPk) { - HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive").params("uid", CommonAppConfig.getInstance().getUid()).params("pkuid", u.getId()).params("type", "1").params("sign", "1").execute(new HttpCallback() { @Override public void onSuccess(int code, String msgs, String[] info) { @@ -1118,8 +1129,22 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } }); + /*LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (obj.getString("ispk").equals("0")) { + } else { + ToastUtil.show(mContext.getString(R.string.pking_over)); + } + } + } + } + });*/ } else { if (mPkWaitCount < 0) { IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { @@ -1637,7 +1662,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mHandler.removeCallbacksAndMessages(null); } mHandler = null; - mSocketRyClient = null; + mSocketSwClient = null; if (mLiveLinkMicPkViewHolder != null) { mLiveLinkMicPkViewHolder.release(); } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index f54c8eb66..658f3528f 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -312,14 +312,13 @@ public class SocketSwClient { u.setUserNiceName(map.getString("uname")); u.setId(map.getString("uid")); mListener.onLinkDRMicPkApply(u); - } - //收到对方同意多人PK邀请 - else if (action3 == 2) { + } else if (action3 == 2) { + //收到对方同意多人PK邀请 if("0".equals(map.getString("msgtype"))){ return; } UserBean u = new UserBean(); -// u.setUserNiceName(map.getString("uname")); +// u.setUserNiceName(map.getString("uname")); u.setId(map.getString("pkuid")); L.eSw("action3 == 2:"+u.getId()); L.eSw("收到对方同意多人PK邀请"); @@ -1280,8 +1279,8 @@ public class SocketSwClient { case 1://收到对方主播PK回调 UserBean u = new UserBean(); u.setId(map.getString("uid")); - u.setUserNiceName(map.getString("pkname")); - u.setAvatar(map.getString("pkhead")); + u.setUserNiceName(map.getString("uname")); + u.setAvatar(map.getString("uhead")); u.setRandomPk("11".equals(map.getString("msgtype"))); mListener.onLinkMicPkApply(u, map.getString("stream"), "11".equals(map.getString("msgtype"))?2:1); break; @@ -1306,7 +1305,7 @@ public class SocketSwClient { L.eSw("所有人收到PK开始址的回调"); // RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(map.getString("pkuid"))); - mListener.onLinkMicPkStart(map.getString("pkuid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders")); + mListener.onLinkMicPkStart(map.getString("pkuid"), map.getString("uhead"), map.getString("uname"), map.getString("is_ladders")); break; case 5://PK时候断开连麦的回调 // if (rtcRoom != null) { @@ -1341,61 +1340,62 @@ public class SocketSwClient { } break; case 10://系统发起PK回调 - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 2) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 2) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("random_pk", "1") - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(map.getString("uid"), conversationType, messageContent); + if(livePushSwViewHolder!=null){ + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 2) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 2) + .param("uid", CommonAppConfig.getInstance().getUid()) + .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("random_pk", "1") + .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(map.getString("uid"), conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { - } + } - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - } + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); - RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); + + LiveNetManager.get(mContext).getLiveInfo(map.getString("uid"), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + mListener.onLinkMicToPk(map.getString("uid"), data.getAvatar(), map.getString("uhead")); + mListener.onLinkMicPkStart(map.getString("uid"), data.getAvatar(), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); + if (livePushSwViewHolder != null) { + UserBean userBean = new UserBean(); + userBean.setId(map.getString("uid")); + userBean.setAvatar(data.getAvatar()); + userBean.setUserNiceName(map.getString("uname")); + livePushSwViewHolder.setAnPkRtc(userBean); + } + } + + @Override + public void onError(String error) { - LiveNetManager.get(mContext).getLiveInfo(map.getString("uid"), new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - mListener.onLinkMicToPk(map.getString("uid"), data.getAvatar(), map.getString("uhead")); - mListener.onLinkMicPkStart(map.getString("uid"), data.getAvatar(), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); - if (livePushSwViewHolder != null) { - UserBean userBean = new UserBean(); - userBean.setId(map.getString("uid")); - userBean.setAvatar(data.getAvatar()); - userBean.setUserNiceName(map.getString("uname")); - livePushSwViewHolder.setAnPkRtc(userBean); } } - - @Override - public void onError(String error) { - - } - } - ); - + ); + } /*JSONObject msg1 = new JSONObject(); msg1.put("type", "autoLivePK"); msg1.put("uid", CommonAppConfig.getInstance().getUid()); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java index 9c7281eb9..34cc7bb6f 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwLinkMicPkUtil.java @@ -7,6 +7,7 @@ import com.yunbao.common.Constants; import com.yunbao.common.bean.UserBean; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.utils.L; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; @@ -47,7 +48,7 @@ public class SocketSwLinkMicPkUtil { @Override public void onSuccess(int code, String msgs, String[] info) { if (code == 0) { - + L.eSw("1111111111111111111111111111"); HttpClient.getInstance().get("Livepk.setPK", "Livepk.setPK") .params("uid", CommonAppConfig.getInstance().getUid()) .params("pkuid", pkUid) @@ -58,10 +59,12 @@ public class SocketSwLinkMicPkUtil { public void onSuccess(int code, String msgs, String[] info) { if (code == 0) { Log.e("ry",name+"啊啊"+url); + L.eSw("2222222222222222222222"); final SocketSendBean msg1 = new SocketSendBean() .param("_method_", Constants.SOCKET_LINK_MIC_PK) .param("action", 4) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("uname", url) + .param("uhead", name) .param("pkuid", pkUid) .param("uid", CommonAppConfig.getInstance().getUid()) .param("pkhead", url) diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java index 39ec37fa7..f57b6e365 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -35,13 +35,20 @@ import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; import com.lzy.okserver.OkDownload; import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.Constants; +import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.UserBean; import com.yunbao.common.dialog.LiveFontSizeSettingDialog; +import com.yunbao.common.http.API; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.ResponseModel; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.manager.MicUserManager; +import com.yunbao.common.manager.MicedUserManager; +import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; @@ -57,6 +64,7 @@ import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.socket.SocketSendBean; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -88,6 +96,15 @@ import cn.rongcloud.rtc.base.RCRTCStreamType; import cn.rongcloud.rtc.base.RTCErrorCode; import cn.rongcloud.rtc.core.RendererCommon; import io.agora.beautyapi.faceunity.agora.SWAuManager; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.functions.Consumer; +import io.reactivex.schedulers.Schedulers; +import io.rong.imkit.IMCenter; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; +import io.rong.message.TextMessage; public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { @@ -205,8 +222,57 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { swAuManager.setAudienceContainer(ry_view); swAuManager.initRtcEngine((Activity) mContext); swAuManager.setupRemoteVideo(Integer.parseInt(liveUid)); + swAuManager.setSwListener(new SWAuManager.SwListener() { + @Override + public void onUserOffline(int liveUid) { + API.get().createPDLiveApi(false) + .killDrLm(CommonAppConfig.getInstance().getUid(), String.valueOf(liveUid)) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel stringResponseModel) throws Exception { + + SocketSendBean socketSendBean = new SocketSendBean() + .param("_method_", Constants.LIAN_MAI) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("avatar", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("uid", CommonAppConfig.getInstance().getUid()); + + ToastUtil.show(mContext.getString(R.string.live_mic_user_down)); + + socketSendBean.param("action", 8); + socketSendBean.create(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(socketSendBean.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(CommonAppConfig.getInstance().getUid(), conversationType, messageContent); + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + + IMCenter.getInstance().deleteRemoteMessages(Conversation.ConversationType.PRIVATE, message.getTargetId(), new Message[]{message}, null); + IMCenter.getInstance().clearMessagesUnreadStatus(Conversation.ConversationType.PRIVATE, message.getTargetId(), null); + MicedUserManager.get().removeMiscUser(CommonAppConfig.getInstance().getUid()); + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + errorCode.toString()); + } + }); + + } + }, Throwable::printStackTrace).isDisposed(); + } + }); //进入主播房间 - swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid)); + swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,liveUid, SWAuManager.getChannelName(liveUid)); } /** diff --git a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java index d5a2402c8..c98f319ca 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -303,9 +303,11 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX final SocketSendBean msg1 = new SocketSendBean() .param("_method_", Constants.SOCKET_LINK_MIC_PK) .param("action", 4) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("pkname", u.getUserNiceName()) .param("pkuid", u.getId()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("pkhead", u.getAvatar()) + .param("uname", u.getUserNiceName()) + .param("uhead", u.getAvatar()) .param("uid", CommonAppConfig.getInstance().getUid()); msg1.create(); diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 9d0196c0d..cda10a56c 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -344,15 +344,24 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } }; + boolean isChangeSdk = false; @Override - public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk, boolean isSw) { + public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk, boolean isSw1) { + if(isSw==isSw1){ + L.eSw("直播SDK 没有改变了 "+isSw1); + isChangeSdk = false; + }else{ + L.eSw("直播SDK 改变了 "+isSw1); + isChangeSdk = true; + } + isSw = isSw1; isEnterRoom = false; MobclickAgent.onEvent(mContext, "live_room_chat_list", "滑动直播间聊天列表"); openParametersModel = new OpenParametersModel(); - if (mLiveRoomViewHolder != null) { + /*if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.UpPkTwo(); - } + }*/ mContext.runOnUiThread(new Runnable() { @Override @@ -387,23 +396,28 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe frameAnimation.start(); liveHandler.removeCallbacks(loadRunnableGone); liveHandler.removeCallbacks(loadTimeoutRunnableGone); - if (mLivePlayViewHolder == null) { + + if (mLivePlayViewHolder == null|| isChangeSdk) { + if (isSw) { mLivePlayViewHolder = new LivePlaySwViewHolder(mContext, playContainer, 1); } else { mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); } + mLivePlayViewHolder.initSwEngine(mLiveBean.getUid()); mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager(),isSw); mLiveAudienceViewHolder = new LiveAudienceViewHolder(mContext, mContainer); mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, mLiveAudienceViewHolder.getContentView()); mLiveLinkMicAnchorPresenter = new LiveLinkMicAnchorPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, null); + if (isSw) { mLiveSwLinkMicPkPresenter = new LiveSwLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); } else { mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); } + mLivePlayViewHolder.removeFromParent(); mLivePlayViewHolder.addToParent(); mLivePlayViewHolder.subscribeActivityLifeCycle(); mLivePlayViewHolder.setLoadViewListener(new LiveRoomPlayViewHolder.LoadingListener() { @@ -413,11 +427,15 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe liveHandler.removeCallbacks(loadTimeoutRunnableGone); } }); - mLiveRoomViewHolder.subscribeActivityLifeCycle(); - mLiveAudienceViewHolder.addToParent(); + mLiveRoomViewHolder.removeFromParent(); mLiveRoomViewHolder.addToParent(); + mLiveRoomViewHolder.subscribeActivityLifeCycle(); + + mLiveAudienceViewHolder.removeFromParent(); + mLiveAudienceViewHolder.addToParent(); mLiveAudienceViewHolder.subscribeActivityLifeCycle(); } else { + mLivePlayViewHolder.initSwEngine(mLiveBean.getUid()); mLivePlayViewHolder.setLiveBeanLandscape(1); mLiveLinkMicPresenter.setLiveSdk(mLiveSDK); mLiveLinkMicAnchorPresenter.setLiveSdk(mLiveSDK); @@ -1012,7 +1030,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter = null; if (PermissionUtils.checkPermission(mContext) && !kick) { LiveFloatView.getInstance() - .cacheLiveData(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal) + .cacheLiveData(mLiveBean, mLiveType, isSw? Constants.LIVE_SDK_SW:Constants.LIVE_SDK_KSY, mLiveTypeVal) .builderSystemFloat(mContext, mLiveBean.getPull()); mContext.finish(); } else { @@ -1020,7 +1038,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe EventBus.getDefault() .post(new LiveFloatEvent() .setmLiveBean(mLiveBean) - .setmLiveSDK(mLiveSDK) + .setmLiveSDK(isSw? Constants.LIVE_SDK_SW:Constants.LIVE_SDK_KSY) .setmLiveType(mLiveType) .setmLiveTypeVal(mLiveTypeVal)); } @@ -1059,7 +1077,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe boolean floatPermission = PermissionUtils.checkPermission(mContext); if (mLiveBean != null && !isQuitF && !isForeground && floatPermission) { LiveFloatView.getInstance() - .cacheLiveData(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal) + .cacheLiveData(mLiveBean, mLiveType, isSw? Constants.LIVE_SDK_SW:Constants.LIVE_SDK_KSY, mLiveTypeVal) .builderSystemFloat(mContext, mLiveBean.getPull()); mContext.finish(); } diff --git a/live/src/main/res/layout/view_live_push_sw.xml b/live/src/main/res/layout/view_live_push_sw.xml index b6d31d27b..4cd13440a 100644 --- a/live/src/main/res/layout/view_live_push_sw.xml +++ b/live/src/main/res/layout/view_live_push_sw.xml @@ -2,7 +2,8 @@ + android:layout_height="match_parent" + xmlns:tools="http://schemas.android.com/tools"> @@ -38,51 +40,53 @@ + android:orientation="horizontal" + android:visibility="visible"> + android:orientation="vertical"> + android:background="@mipmap/live_icon_vacancy" + tools:ignore="NestedWeights" /> + android:orientation="vertical"> + android:background="@mipmap/live_icon_vacancy" + tools:ignore="NestedWeights" /> From d5f78cc83a9a3aeaefc8e1ca3faeae83f5ba8437 Mon Sep 17 00:00:00 2001 From: 18142669586 <1669783059@qq.com> Date: Tue, 28 May 2024 14:26:29 +0800 Subject: [PATCH 24/64] =?UTF-8?q?=E4=BF=AE=E6=94=B9pk=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java index 648a042cf..03130178a 100644 --- a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java @@ -236,13 +236,13 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { mId.setText(bean.getId()); if (bean.isPk()) { mStatus.setText("PK中"); - ImgLoader.display(mContext, R.mipmap.ic_random_pk_pk, mPkStatus); + ImgLoader.display(mContext, R.mipmap.ic_random_pk_pk_unselect, mPkStatus); if (!WordUtil.isNewZh()) { mStatus.setText("PK"); } } else { + ImgLoader.display(mContext, R.mipmap.ic_random_pk_pk, mPkStatus); mStatus.setText("空闲"); - ImgLoader.display(mContext, R.mipmap.ic_random_pk_pk_unselect, mPkStatus); if (!WordUtil.isNewZh()) { mStatus.setText("free"); } From 0afee3543ea41a2b54e8f943a219cdf5fa8cf165 Mon Sep 17 00:00:00 2001 From: 18142669586 <1669783059@qq.com> Date: Tue, 28 May 2024 15:20:43 +0800 Subject: [PATCH 25/64] =?UTF-8?q?=E9=82=80=E8=AF=B7=E5=90=8E=E4=B8=8D?= =?UTF-8?q?=E6=8E=A5=E5=8F=97=E5=80=92=E8=AE=A1=E6=97=B6=E5=AE=8C=E4=BA=86?= =?UTF-8?q?=E5=9C=A8=E9=82=80=E8=AF=B7=20=E4=B8=8D=E6=98=BE=E7=A4=BApk?= =?UTF-8?q?=E5=BC=B9=E5=87=BA=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index fd690e02c..b0aa3128c 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -554,14 +554,18 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mApplyUrl = u.getAvatar(); mApplyNmae = u.getUserNiceName(); if (by != 1) { + Log.e("ry", "1"+u.getUserNiceName() + "单人收到" + u.getAvatar()); if (mIsApplyDialogShow == false) { if (u.isRandomPk()) { + Log.e("ry", "2"+u.getUserNiceName() + "单人收到" + u.getAvatar()); showPkDialog(u); } else { + Log.e("ry", "3"+u.getUserNiceName() + "单人收到" + u.getAvatar()); showApplyDialog(u); } } } else { + Log.e("ry", "4"+u.getUserNiceName() + "单人收到" + u.getAvatar()); isPK(u); } } @@ -683,6 +687,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } else { if (mPkWaitCount < 0) { if(rtcRoom==null){ + mIsApplyDialogShow = false; return; } rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { From 01dfb81a46c3762b16bcb0b0c63d3c80beb2878e Mon Sep 17 00:00:00 2001 From: 18142669586 <1669783059@qq.com> Date: Tue, 28 May 2024 16:58:39 +0800 Subject: [PATCH 26/64] =?UTF-8?q?=E7=82=B9=E5=87=BB=E3=80=90=E9=82=80?= =?UTF-8?q?=E8=AF=B7=E3=80=91=E5=8A=A0=E4=B8=8A=E9=98=B2=E6=8A=96=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/http/PDLiveApi.java | 2 +- .../adapter/AnchorUserMicInfoAdapter.java | 19 ++++---- .../presenter/LiveSwLinkMicPkPresenter.java | 48 ++++++++----------- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index 13a2a4524..79932a5a6 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -216,7 +216,7 @@ public interface PDLiveApi { ); /** - * 关注主播 + * 关注主播··································································· * * @param liveuid * @return diff --git a/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java b/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java index 7304344a7..68d50d2f7 100644 --- a/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java @@ -121,11 +121,12 @@ public class AnchorUserMicInfoAdapter extends RefreshAdapter { gift_svga = (SVGAImageView) itemView.findViewById(R.id.gift_svga); mBtn = itemView.findViewById(R.id.mic_btn); mClose = itemView.findViewById(R.id.mic_exit); - mBtn.setOnClickListener(v -> { - if (MicedUserManager.get().getMicUserList().size() < 3) { - if (v.getTag() != null) { - UserBean tag = (UserBean) v.getTag(); - ViewClicksAntiShake.clicksAntiShake(mBtn, () -> { + ViewClicksAntiShake.clicksAntiShake(mBtn, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + if (MicedUserManager.get().getMicUserList().size() < 3) { + if (mBtn.getTag() != null) { + UserBean tag = (UserBean) mBtn.getTag(); if (tag.getTypeMic() == TYPE_MIC_REQUEST) { applyMic(tag, 4, createSocketSendBean()); ToastUtil.show(mContext.getString(R.string.live_mic_request)); @@ -140,12 +141,14 @@ public class AnchorUserMicInfoAdapter extends RefreshAdapter { applyMic(tag, 1, bean); ToastUtil.show(mContext.getString(R.string.live_mic_invite)); } - }); + } + }else { + ToastUtil.show(mContext.getString(R.string.live_mic_max)); } - }else { - ToastUtil.show(mContext.getString(R.string.live_mic_max)); } }); + + mClose.setOnClickListener(v -> { if (v.getTag() != null) { API.get().createPDLiveApi(false) diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index b0aa3128c..8eab1626e 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -690,43 +690,33 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mIsApplyDialogShow = false; return; } - rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override - public void onFailed(RTCErrorCode errorCode) { + public void onAttached(io.rong.imlib.model.Message message) { } @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); - msg1.create(); + public void onSuccess(io.rong.imlib.model.Message message) { - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + Log.e("ry", "发送成功"); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - - Log.e("ry", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + u.getId()); - } - }); + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + u.getId()); } }); From ff8e75768eb10bb76f529e8b85a130c24d4a95c3 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Tue, 28 May 2024 17:12:52 +0800 Subject: [PATCH 27/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 6 +- .../yunbao/common/views/AbsViewHolder.java | 6 + .../faceunity/agora/LiveFloatView.java | 20 ++-- .../presenter/LiveLinkMicPkPresenter.java | 2 +- .../presenter/LiveRyLinkMicPkPresenter.java | 3 +- .../presenter/LiveSwLinkMicPkPresenter.java | 103 ++++-------------- .../yunbao/live/socket/SocketSwClient.java | 2 +- .../live/views/LivePushSwViewHolder.java | 1 + .../live/views/PortraitLiveManager.java | 37 ++----- .../yunbao/main/activity/MainActivity.java | 2 +- 10 files changed, 55 insertions(+), 127 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 37aa91b60..f23dc1ea8 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -210,7 +210,7 @@ public class AppContext extends CommonAppContext { if (content.getContent().contains("_method_")) { msg.obj = content.getContent(); //观众页面 - if(CommonAppConfig.getInstance().getConfig().isSw()){ + //声网 if (SocketSwClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { SocketSwClient.mSocketHandler.sendMessage(msg); } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 @@ -227,7 +227,8 @@ public class AppContext extends CommonAppContext { if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketSwClient.mSocketHandler != null) { SocketSwClient.mSocketHandler.sendMessage(msg); } - }else{ + + //融云 if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { SocketRyClient.mSocketHandler.sendMessage(msg); } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 @@ -244,7 +245,6 @@ public class AppContext extends CommonAppContext { if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketRyClient.mSocketHandler != null) { SocketRyClient.mSocketHandler.sendMessage(msg); } - } } else if (message.getConversationType() == Conversation.ConversationType.PRIVATE) {//私聊信息 EventBus.getDefault().post(message); } diff --git a/common/src/main/java/com/yunbao/common/views/AbsViewHolder.java b/common/src/main/java/com/yunbao/common/views/AbsViewHolder.java index fef359955..5394291af 100644 --- a/common/src/main/java/com/yunbao/common/views/AbsViewHolder.java +++ b/common/src/main/java/com/yunbao/common/views/AbsViewHolder.java @@ -65,6 +65,12 @@ public abstract class AbsViewHolder implements LifeCycleListener { } } + public void removeView(){ + if (mParentView != null && mContentView != null) { + mParentView.removeView(mContentView); + } + } + public boolean isShow(){ return mParentView.indexOfChild(mContentView)>-1; } diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java index 26e22e858..0b43f7d0a 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/LiveFloatView.java @@ -50,7 +50,7 @@ public class LiveFloatView implements Function1 { private String url; private LiveBean mLiveBean; private int mLiveType; - private int mLiveSDK; + private boolean mLiveSDK; private int mLiveTypeVal; private FloatCallbacks.Builder builder; private String TAG = "LiveFloatView"; @@ -86,7 +86,7 @@ public class LiveFloatView implements Function1 { cardParams.height = DpUtil.dp2px(224); cardParams.width = DpUtil.dp2px(126); } - if(mLiveSDK == Constants.LIVE_SDK_SW){ + if(mLiveSDK){ L.eSw("mLiveSDK == Constants.LIVE_S2222222222222222"); videoFrameLayout = magnetView.findViewById(R.id.videoFrameLayout); swAuManager = SWAuManager.get(); @@ -128,7 +128,7 @@ public class LiveFloatView implements Function1 { ViewClicksAntiShake.clicksAntiShake(magnetView.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { - if(mLiveSDK == Constants.LIVE_SDK_SW){ + if(mLiveSDK){ SWAuManager.get().exitChannelAll(); }else{ mPlayer.stopPlay(true); @@ -143,7 +143,7 @@ public class LiveFloatView implements Function1 { } } }); - if(mLiveSDK == Constants.LIVE_SDK_SW){ + if(mLiveSDK){ ViewClicksAntiShake.clicksAntiShake(videoFrameLayout, () -> { SWAuManager.get().exitChannelAll(); APPEasyFloat.getInstance().dismiss(mContext); @@ -166,7 +166,7 @@ public class LiveFloatView implements Function1 { @Override public void dismiss() { - if(mLiveSDK == Constants.LIVE_SDK_SW){ + if(mLiveSDK){ SWAuManager.get().exitChannelAll(); }else{ if (mPlayer != null) @@ -194,7 +194,7 @@ public class LiveFloatView implements Function1 { .show(); } - public LiveFloatView cacheLiveData(LiveBean mLiveBean, int mLiveType, int mLiveSDK, int mLiveTypeVal) { + public LiveFloatView cacheLiveData(LiveBean mLiveBean, int mLiveType, boolean mLiveSDK, int mLiveTypeVal) { this.mLiveBean = mLiveBean; this.mLiveType = mLiveType; this.mLiveSDK = mLiveSDK; @@ -247,7 +247,7 @@ public class LiveFloatView implements Function1 { cardParams.width = DpUtil.dp2px(126); } layout.setLayoutParams(cardParams); - if(mLiveSDK == Constants.LIVE_SDK_SW){ + if(mLiveSDK){ L.eSw("mLiveSDK == Constants.LIVE_SDK_SW mLive1111111"); swAuManager = SWAuManager.get(); swAuManager.setAudienceContainer(videoFrameLayout); @@ -289,7 +289,7 @@ public class LiveFloatView implements Function1 { ViewClicksAntiShake.clicksAntiShake(view.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { - if(mLiveSDK == Constants.LIVE_SDK_SW){ + if(mLiveSDK){ SWAuManager.get().exitChannelAll(); }else{ mPlayer.stopPlay(true); @@ -306,7 +306,7 @@ public class LiveFloatView implements Function1 { } }); ViewClicksAntiShake.clicksAntiShake(view, () -> { - if(mLiveSDK == Constants.LIVE_SDK_SW){ + if(mLiveSDK){ SWAuManager.get().exitChannelAll(); }else{ mPlayer.stopPlay(true); @@ -341,7 +341,7 @@ public class LiveFloatView implements Function1 { public void onSuccess(int code, String msg, String[] info) { if (code == 0) { - RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal,mLiveSDK == Constants.LIVE_SDK_SW); + RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK ? Constants.LIVE_SDK_SW:Constants.LIVE_SDK_TX, mLiveTypeVal,mLiveSDK); } else { //判断是否有直播悬浮窗,有直接关闭 diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java index 6c18b6bf8..6b502f695 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java @@ -450,7 +450,7 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { LivePushTxViewHolder.mPreView.setLayoutParams(params); LivePushTxViewHolder.mPreView1.setLayoutParams(params); - + L.eSw("33333333333333333333333333"); final SocketSendBean msg1 = new SocketSendBean() .param("_method_", Constants.SOCKET_LINK_MIC_PK) .param("action", 4) diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 80ed11380..b911365d6 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -55,6 +55,7 @@ import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.ScreenDimenUtil; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; @@ -793,7 +794,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { livePushRyViewHolder.camera.setLayoutParams(params); livePushRyViewHolder.mPreView1.setLayoutParams(params); livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); - + L.eSw("4444444444444444444444444444"); final SocketSendBean msg1 = new SocketSendBean() .param("_method_", SOCKET_LINK_MIC_PK) .param("action", 4) diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index b0aa3128c..73d4e1991 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -162,51 +162,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { return this; } - private IRCRTCOtherRoomEventsListener otherRoomEventsListener = new IRCRTCOtherRoomEventsListener() { - - @Override - public void onRemoteUserPublishResource(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, List streams) { - } - - @Override - public void onRemoteUserMuteAudio(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - } - - @Override - public void onRemoteUserMuteVideo(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - } - - @Override - public void onRemoteUserUnpublishResource(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser, List streams) { - } - - @Override - public void onUserJoined(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) { - } - - @Override - public void onUserLeft(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) { - } - - @Override - public void onUserOffline(RCRTCOtherRoom room, RCRTCRemoteUser remoteUser) { - RCRTCEngine.getInstance().leaveOtherRoom(room.getRoomId(), true, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - } - }); - } - - @Override - public void onLeaveRoom(RCRTCOtherRoom room, int reasonCode) { - Log.d("RYM_DG", "Other onLeaveRoom: room = " + room.getRoomId()); - } - }; - public LiveSwLinkMicPkPresenter(Context context, ILiveLinkMicViewHolder linkMicViewHolder, boolean isAnchor, View root) { mContext = context; mIsAnchor = isAnchor; @@ -642,7 +597,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); LiveSwAnchorActivity.isDRPK = 1; LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); - SocketSwLinkMicPkUtil.linkMicPkAccept(mSocketSwClient, mApplyUid, mApplyUrl, mApplyNmae); + //SocketSwLinkMicPkUtil.linkMicPkAccept(mSocketSwClient, mApplyUid, mApplyUrl, mApplyNmae); EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid)); onLinkMicPkStart(mApplyUid, 2); } @@ -670,8 +625,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); } if (mAcceptPk) { - isPK(u); - /*LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { + LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { if (code == 0 && info.length > 0) { @@ -683,53 +637,36 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { ToastUtil.show(mContext.getString(R.string.pking_over)); } } - }}});*/ + }}}); } else { if (mPkWaitCount < 0) { - if(rtcRoom==null){ - mIsApplyDialogShow = false; - return; - } - rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + msg1.create(); + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override - public void onFailed(RTCErrorCode errorCode) { + public void onAttached(io.rong.imlib.model.Message message) { } @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); - msg1.create(); + public void onSuccess(io.rong.imlib.model.Message message) { - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + Log.e("ry", "发送成功"); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - - Log.e("ry", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + u.getId()); - } - }); + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + u.getId()); } }); - } mApplyUid = null; mApplyStream = null; diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index 658f3528f..e8b726e08 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -1305,7 +1305,7 @@ public class SocketSwClient { L.eSw("所有人收到PK开始址的回调"); // RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TWO_START).setObject(map.getString("pkuid"))); - mListener.onLinkMicPkStart(map.getString("pkuid"), map.getString("uhead"), map.getString("uname"), map.getString("is_ladders")); + mListener.onLinkMicPkStart(map.getString("pkuid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders")); break; case 5://PK时候断开连麦的回调 // if (rtcRoom != null) { diff --git a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java index c98f319ca..712888d0a 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -300,6 +300,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onSuccess(int code, String msgs, String[] info) { if (code == 0) { + L.eSw("555555555555555555555555555555555555"); final SocketSendBean msg1 = new SocketSendBean() .param("_method_", Constants.SOCKET_LINK_MIC_PK) .param("action", 4) diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index cda10a56c..b159a5fe5 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -344,24 +344,15 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } }; - boolean isChangeSdk = false; @Override - public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk, boolean isSw1) { - if(isSw==isSw1){ - L.eSw("直播SDK 没有改变了 "+isSw1); - isChangeSdk = false; - }else{ - L.eSw("直播SDK 改变了 "+isSw1); - isChangeSdk = true; - } - isSw = isSw1; + public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk, boolean isSw) { isEnterRoom = false; MobclickAgent.onEvent(mContext, "live_room_chat_list", "滑动直播间聊天列表"); openParametersModel = new OpenParametersModel(); - /*if (mLiveRoomViewHolder != null) { + if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.UpPkTwo(); - }*/ + } mContext.runOnUiThread(new Runnable() { @Override @@ -396,28 +387,23 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe frameAnimation.start(); liveHandler.removeCallbacks(loadRunnableGone); liveHandler.removeCallbacks(loadTimeoutRunnableGone); - - if (mLivePlayViewHolder == null|| isChangeSdk) { - + if (mLivePlayViewHolder == null) { if (isSw) { mLivePlayViewHolder = new LivePlaySwViewHolder(mContext, playContainer, 1); } else { mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); } - mLivePlayViewHolder.initSwEngine(mLiveBean.getUid()); mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager(),isSw); mLiveAudienceViewHolder = new LiveAudienceViewHolder(mContext, mContainer); mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, mLiveAudienceViewHolder.getContentView()); mLiveLinkMicAnchorPresenter = new LiveLinkMicAnchorPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, null); - if (isSw) { mLiveSwLinkMicPkPresenter = new LiveSwLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); } else { mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); } - - mLivePlayViewHolder.removeFromParent(); + mLivePlayViewHolder.initSwEngine(mLiveBean.getUid()); mLivePlayViewHolder.addToParent(); mLivePlayViewHolder.subscribeActivityLifeCycle(); mLivePlayViewHolder.setLoadViewListener(new LiveRoomPlayViewHolder.LoadingListener() { @@ -427,15 +413,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe liveHandler.removeCallbacks(loadTimeoutRunnableGone); } }); - mLiveRoomViewHolder.removeFromParent(); - mLiveRoomViewHolder.addToParent(); mLiveRoomViewHolder.subscribeActivityLifeCycle(); - - mLiveAudienceViewHolder.removeFromParent(); mLiveAudienceViewHolder.addToParent(); + mLiveRoomViewHolder.addToParent(); mLiveAudienceViewHolder.subscribeActivityLifeCycle(); } else { - mLivePlayViewHolder.initSwEngine(mLiveBean.getUid()); + mLivePlayViewHolder.initSwEngine(liveID); mLivePlayViewHolder.setLiveBeanLandscape(1); mLiveLinkMicPresenter.setLiveSdk(mLiveSDK); mLiveLinkMicAnchorPresenter.setLiveSdk(mLiveSDK); @@ -1030,7 +1013,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter = null; if (PermissionUtils.checkPermission(mContext) && !kick) { LiveFloatView.getInstance() - .cacheLiveData(mLiveBean, mLiveType, isSw? Constants.LIVE_SDK_SW:Constants.LIVE_SDK_KSY, mLiveTypeVal) + .cacheLiveData(mLiveBean, mLiveType, isSw, mLiveTypeVal) .builderSystemFloat(mContext, mLiveBean.getPull()); mContext.finish(); } else { @@ -1038,7 +1021,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe EventBus.getDefault() .post(new LiveFloatEvent() .setmLiveBean(mLiveBean) - .setmLiveSDK(isSw? Constants.LIVE_SDK_SW:Constants.LIVE_SDK_KSY) + .setmLiveSDK(isSw?2:mLiveSDK) .setmLiveType(mLiveType) .setmLiveTypeVal(mLiveTypeVal)); } @@ -1077,7 +1060,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe boolean floatPermission = PermissionUtils.checkPermission(mContext); if (mLiveBean != null && !isQuitF && !isForeground && floatPermission) { LiveFloatView.getInstance() - .cacheLiveData(mLiveBean, mLiveType, isSw? Constants.LIVE_SDK_SW:Constants.LIVE_SDK_KSY, mLiveTypeVal) + .cacheLiveData(mLiveBean, mLiveType, isSw, mLiveTypeVal) .builderSystemFloat(mContext, mLiveBean.getPull()); mContext.finish(); } diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index 377949726..e4cd2d6c6 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -1510,7 +1510,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene @Subscribe(threadMode = ThreadMode.MAIN) public void onLiveFloatEvent(LiveFloatEvent event) { if (event != null && event.getmLiveBean() != null && !TextUtils.isEmpty(event.getmLiveBean().getPull())) { - new Handler().post(() -> LiveFloatView.getInstance().cacheLiveData(event.getmLiveBean(), event.getmLiveType(), event.getmLiveSDK(), event.getmLiveTypeVal()).builderFloat(mContext, event.getmLiveBean().getPull(), LiveAudienceActivity.class)); + new Handler().post(() -> LiveFloatView.getInstance().cacheLiveData(event.getmLiveBean(), event.getmLiveType(), event.getmLiveSDK() ==Constants.LIVE_SDK_SW, event.getmLiveTypeVal()).builderFloat(mContext, event.getmLiveBean().getPull(), LiveAudienceActivity.class)); } } From 9711b1f8d46fff67573ca59387d37b665dd954e6 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Tue, 28 May 2024 21:28:20 +0800 Subject: [PATCH 28/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 8 ++--- .../live/activity/LiveAudienceActivity.java | 1 - .../live/views/LivePlaySwViewHolder.java | 3 +- .../live/views/LiveRyAnchorViewHolder.java | 33 ++++++++++--------- .../live/views/PortraitLiveManager.java | 3 ++ .../src/main/res/layout/view_live_play_sw.xml | 2 +- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/gradle.properties b/gradle.properties index f8c588910..64e5acf4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,10 +21,10 @@ org.gradle.configureondemand=true android.useAndroidX=true android.enableJetifier=true -systemProp.http.proxyHost=127.0.0.1 -systemProp.https.proxyHost=127.0.0.1 -systemProp.https.proxyPort=10809 -systemProp.http.proxyPort=10809 +#systemProp.http.proxyHost=127.0.0.1 +#systemProp.https.proxyHost=127.0.0.1 +#systemProp.https.proxyPort=10809 +#systemProp.http.proxyPort=10809 #android.enableR8.fullMode=true \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index c17dc9e25..5737cd95a 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -187,7 +187,6 @@ public class LiveAudienceActivity extends LiveActivity { private boolean liveIndex = true; private boolean isPk = false; private boolean isRadPacetModle = false; - public boolean isSw; @Override public T findViewById(@IdRes int id) { diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java index f57b6e365..26dac4602 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -733,12 +733,13 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { mCover.setVisibility(View.VISIBLE); } } + swAuManager.exitChannelAll(); stopPlay2(); } @Override public void stopPlay2() { - + drMicUserList = new ArrayList<>(); } @Override diff --git a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java index f53469f4b..02e100b65 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -130,22 +130,25 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { btn_start_dr_pk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (pk_nub <= 0) return; - //開始多人PK - HttpClient.getInstance().get("live.startDRPK", "live.startDRPK") - .params("roomid", CommonAppConfig.getInstance().getUid()) - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - PKing = true; - pk_nub = pk_nub - 1; - btn_dr_pk_nub.setText("剩餘次數:" + pk_nub); - } else { - ToastUtil.show(msg); + if(pk_nub<= 0){ + ToastUtil.show("多人PK次数已用完"); + }else{ + //開始多人PK + HttpClient.getInstance().get("live.startDRPK", "live.startDRPK") + .params("roomid", CommonAppConfig.getInstance().getUid()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + PKing = true; + pk_nub = pk_nub - 1; + btn_dr_pk_nub.setText("剩餘次數:" + pk_nub); + } else { + ToastUtil.show(msg); + } } - } - }); + }); + } } }); diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index b159a5fe5..12e1183bc 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -983,6 +983,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter.release(); mLiveRyLinkMicPkPresenter = null; } + if(mLivePlayViewHolder!=null){ + mLivePlayViewHolder.stopPlay2(); + } if (mLiveEndViewHolder != null) { removeLiveEnd(); } diff --git a/live/src/main/res/layout/view_live_play_sw.xml b/live/src/main/res/layout/view_live_play_sw.xml index f7c596dc0..cdcd20495 100644 --- a/live/src/main/res/layout/view_live_play_sw.xml +++ b/live/src/main/res/layout/view_live_play_sw.xml @@ -69,7 +69,7 @@ From d9b114983286e8d55ebdb6197c34d94eff7e6bf1 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Wed, 29 May 2024 21:24:05 +0800 Subject: [PATCH 29/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/live/activity/LiveActivity.java | 7 + .../live/activity/LiveAudienceActivity.java | 5 + .../live/activity/LiveSwAnchorActivity.java | 8 + .../yunbao/live/event/LiveAudienceEvent.java | 3 +- .../presenter/LiveSwLinkMicPkPresenter.java | 164 ++--- .../live/socket/SocketMessageListener.java | 2 + .../yunbao/live/socket/SocketSwClient.java | 120 ++-- .../live/views/LivePlayKsyViewHolder.java | 5 + .../live/views/LivePlayRyViewHolder.java | 5 + .../live/views/LivePlaySwViewHolder.java | 565 +----------------- .../live/views/LivePlayTxViewHolder.java | 5 + .../live/views/LivePushSwViewHolder.java | 211 +++---- .../live/views/LiveRoomPlayViewHolder.java | 2 + .../live/views/LiveRyAnchorViewHolder.java | 42 ++ .../live/views/PortraitLiveManager.java | 15 +- .../src/main/res/layout/view_live_push_sw.xml | 2 +- .../main/res/layout/view_ry_live_anchor.xml | 23 + 17 files changed, 323 insertions(+), 861 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index ec6e0e055..e4fb57369 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -1649,6 +1649,13 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL } } + @Override + public void onLinkDRMicPkQuit(String uid) { + if(mLiveSwLinkMicPkPresenter!=null){ + mLiveSwLinkMicPkPresenter.onLinkDRMicPkQuit(uid); + } + } + @Override public boolean isSoftInputShowed() { if (mKeyBoardHeightUtil != null) { diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 5737cd95a..7493e4e30 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -551,6 +551,11 @@ public class LiveAudienceActivity extends LiveActivity { //manager.getmLivePlayViewHolder().setDrMicInfo(u); } + @Override + public void onLinkDRMicPkQuit(String uid) { + + } + @Override public void onLinkDRMicPkApplyOk(UserBean u) { L.eSw("onLinkDRMicPkApplyOk:" + u.getId()); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index 25fe644df..01e860dd1 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -1288,6 +1288,13 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl } } + public void linkDrMicRemoveListUid(String uid){ + if (mLiveAnchorViewHolder != null) { + mLiveAnchorViewHolder.removeYaoqing(uid); + } + } + + /** * 发起多人主播连麦PK申请 * @@ -1655,6 +1662,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl break; case LEAVE_PK_SCORE: if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.closeButtonGone(); mLiveSwLinkMicPkPresenter.upDataPkScore(event.getPkScores(), event.getUid(), event.getTime()); } if (mLiveRoomViewHolder != null) { diff --git a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index 4a8c493d2..470923b0f 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -490,7 +490,8 @@ public class LiveAudienceEvent extends BaseModel { SUD_GAME_CREATE_ROOM(75, "主播创建sud游戏"), PK_RANK_START(76, "PK排位赛开始"), GuardSpecialEffect(77, "PK排位赛开始"), - LIVE_DIALOG_ANCHOR_TIPS(78, "主播公会赛tips"); + LIVE_DIALOG_ANCHOR_TIPS(78, "主播公会赛tips"), + LIVE_REMOVE_LIVEUID(79, "主播退出多人PK"); private int type; private String name; diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 874d557c7..acba3a23a 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -5,6 +5,7 @@ import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import static com.yunbao.live.activity.LiveSwAnchorActivity.PKing; import static com.yunbao.live.activity.LiveSwAnchorActivity.isDRPK; +import static com.yunbao.live.activity.LiveSwAnchorActivity.mLiveAnchorViewHolder; import static com.yunbao.live.views.LivePushSwViewHolder.btn_close; import static com.yunbao.live.views.LivePushSwViewHolder.rtcRoom; @@ -457,6 +458,30 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { showDRApplyDialog(u); } + public void onLinkDRMicPkQuit(String uid) { + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + //退出所有直播間 + livePushSwViewHolder.exitChannelDrPk(drPkbeans); + + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + + for (int i = 0; i < drPkbeans.size(); i++) { + if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + livePushSwViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); + } + } + if(drPkbeans.size()==1){ + mLiveAnchorViewHolder.closeEndPkBt(); + } + } + } + }); + } + /** * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 */ @@ -466,14 +491,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { if (livePushSwViewHolder != null) { livePushSwViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); } - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 3) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("type", 3) - .param("uid", u.getId()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("type", 3).param("uid", u.getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); String targetId = "g" + CommonAppConfig.getInstance().getUid(); @@ -498,6 +516,8 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } }); dRjoinOtherRoom(u); + //展示结束连麦按钮 + mLiveAnchorViewHolder.showEndPkBt(); } /** @@ -509,18 +529,18 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mApplyUrl = u.getAvatar(); mApplyNmae = u.getUserNiceName(); if (by != 1) { - Log.e("ry", "1"+u.getUserNiceName() + "单人收到" + u.getAvatar()); + Log.e("ry", "1" + u.getUserNiceName() + "单人收到" + u.getAvatar()); if (mIsApplyDialogShow == false) { if (u.isRandomPk()) { - Log.e("ry", "2"+u.getUserNiceName() + "单人收到" + u.getAvatar()); + Log.e("ry", "2" + u.getUserNiceName() + "单人收到" + u.getAvatar()); showPkDialog(u); } else { - Log.e("ry", "3"+u.getUserNiceName() + "单人收到" + u.getAvatar()); + Log.e("ry", "3" + u.getUserNiceName() + "单人收到" + u.getAvatar()); showApplyDialog(u); } } } else { - Log.e("ry", "4"+u.getUserNiceName() + "单人收到" + u.getAvatar()); + Log.e("ry", "4" + u.getUserNiceName() + "单人收到" + u.getAvatar()); isPK(u); } } @@ -553,14 +573,8 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { LiveSwAnchorActivity.isDRPK = 1; /*---------------------------------------------------------------- */ - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 2) //回复PK申请 2 - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", bean.getId()) - .param("uid", CommonAppConfig.getInstance().getUid()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 2) //回复PK申请 2 + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", bean.getId()).param("uid", CommonAppConfig.getInstance().getUid()).param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); if (RandomPkManager.getInstance().isRankModel()) { L.eSw("排位赛"); msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); @@ -570,7 +584,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { System.out.println("PK回执 = " + msg1.toString()); Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain( bean.getId(), conversationType, messageContent); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(bean.getId(), conversationType, messageContent); RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { @Override @@ -633,11 +647,13 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { if (obj != null) { if (obj.getString("ispk").equals("0")) { isPK(u); - }else{ + } else { ToastUtil.show(mContext.getString(R.string.pking_over)); } } - }}}); + } + } + }); } else { if (mPkWaitCount < 0) { final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); @@ -701,6 +717,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } }); + mLiveAnchorViewHolder.closeEndPkBt(); livePushSwViewHolder.exitChannelDrPk(drPkbeans); leaveHandler.removeCallbacks(leaveRunnable); } @@ -911,17 +928,9 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); for (int i = 0; i < drPkbeans.size(); i++) { if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 2) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 2) - .param("uid", drPkbeans.get(i).getId()) - .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 2).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("msgtype", 2).param("uid", drPkbeans.get(i).getId()).param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); - L.eSw("uiduiduiduiduiduiduiduid"+drPkbeans.get(i).getId()); + L.eSw("uiduiduiduiduiduiduiduid" + drPkbeans.get(i).getId()); String targetId = String.valueOf(drPkbeans.get(i).getId()); Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); @@ -953,16 +962,9 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 3) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 3) - .param("uid", drPkbeans.get(i).getId()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("msgtype", 3).param("uid", drPkbeans.get(i).getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); - L.eSw("發送給自己直播間"+drPkbeans.get(i).getId()); + L.eSw("發送給自己直播間" + drPkbeans.get(i).getId()); String targetId = "g" + CommonAppConfig.getInstance().getUid(); Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); @@ -987,17 +989,10 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } - if(!mApplyUid.equals(String.valueOf(drPkbeans.get(i).getId()))&&!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))){ - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK) - .param("action", 3) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 3) - .param("uid", drPkbeans.get(i).getId()) - .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + if (!mApplyUid.equals(String.valueOf(drPkbeans.get(i).getId())) && !CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("msgtype", 3).param("uid", drPkbeans.get(i).getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); - L.eSw("發送給其他主播直播间"+drPkbeans.get(i).getId()); + L.eSw("發送給其他主播直播间" + drPkbeans.get(i).getId()); String targetId = "g" + drPkbeans.get(i).getId(); Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); @@ -1022,41 +1017,13 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } dRjoinOtherRoom(u); + //展示结束连麦按钮 + //设置多人PK 房主ROOM UID + mLiveAnchorViewHolder.setDrpkRoomId(mApplyUid); + mLiveAnchorViewHolder.showEndPkBt(); } } }); - - - /*for (int i = 0; i < users.size(); i++) { - JSONObject user = users.getJSONObject(i); - Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { - *//** - * 向指定用户发送跨房间连麦请求 - *

- * 1: inviterAutoMix为true时: - * - * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 - * - * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 - * - * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 - *

- *//* - IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - }); - } - } - }*/ } }); } @@ -1071,22 +1038,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } }); - /*LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - JSONObject obj = JSON.parseObject(info[0]); - if (obj != null) { - if (obj.getString("ispk").equals("0")) { - - - } else { - ToastUtil.show(mContext.getString(R.string.pking_over)); - } - } - } - } - });*/ } else { if (mPkWaitCount < 0) { IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { @@ -1199,7 +1150,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } - public void setPkUserInfoView(UserBean userBean){ + public void setPkUserInfoView(UserBean userBean) { } @@ -1431,7 +1382,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { * 主播与主播PK 所有人收到PK开始的回调 */ public void onLinkMicPkStart(String pkUid, int i) { - L.eSw("onLinkMicPkStart pkUid "+pkUid+" "+i); + L.eSw("onLinkMicPkStart pkUid " + pkUid + " " + i); Log.d("tag", i + "mPkTimeCount2"); mIsPk = true; hideSendPkWait(); @@ -1440,7 +1391,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mPkUid = pkUid; mApplyUid = null; mApplyStream = null; - isDRPK=1; + isDRPK = 1; if (mLiveLinkMicPkViewHolder == null) { mLiveLinkMicPkViewHolder = new LiveLinkMicPkViewHolder(mContext, mPkContainer); mLiveLinkMicPkViewHolder.addToParent(); @@ -1611,7 +1562,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mLiveLinkMicPkViewHolder = null; } - public void clearData() { mIsApplyDialogShow = false; mAcceptPk = false; @@ -1635,11 +1585,14 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mLiveLinkMicPkViewHolder = null; } - public void setSelfStream(String selfStream) { mSelfStream = selfStream; } + public void closeButtonGone() { + mLiveAnchorViewHolder.closeEndPkBt(); + } + /** * 更新Pk分数 */ @@ -1864,6 +1817,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME2, getNextSecondTime()); } } else { + mLiveAnchorViewHolder.showEndPkBt(); livePushSwViewHolder.timeTitle.setVisibility(View.GONE); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java b/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java index 6ac19c675..98e54cd41 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java @@ -247,6 +247,8 @@ public interface SocketMessageListener { //接受多人PK void onLinkDRMicPkApplyOk(UserBean u); + void onLinkDRMicPkQuit(String uid); + /** * 主播与主播PK 所有人收到PK开始的回调 */ diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index e8b726e08..324b8db5a 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -199,7 +199,7 @@ public class SocketSwClient { //用户连麦 case Constants.LIAN_MAI: int actions = map.getIntValue("action"); - L.eSw("用户连麦:actions"+actions); + L.eSw("用户连麦:actions" + actions); //主播邀请用户连麦消息 if (actions == 1) { EventBus.getDefault().post("inviteMic"); @@ -304,7 +304,7 @@ public class SocketSwClient { // break; case Constants.SOCKET_LIVE_DRPK_RANDOM: case Constants.SOCKET_LIVE_DRPK://多人PK - L.eSw("map"+new Gson().toJson(map)); + L.eSw("map" + new Gson().toJson(map)); int action3 = map.getIntValue("action"); //收到多人PK邀请 if (action3 == 1) { @@ -314,13 +314,13 @@ public class SocketSwClient { mListener.onLinkDRMicPkApply(u); } else if (action3 == 2) { //收到对方同意多人PK邀请 - if("0".equals(map.getString("msgtype"))){ + if ("0".equals(map.getString("msgtype"))) { return; } UserBean u = new UserBean(); // u.setUserNiceName(map.getString("uname")); u.setId(map.getString("pkuid")); - L.eSw("action3 == 2:"+u.getId()); + L.eSw("action3 == 2:" + u.getId()); L.eSw("收到对方同意多人PK邀请"); mListener.onLinkDRMicPkApplyOk(u); SWManager.get().setDimensions(3);//退出直播间,将分别率设置为 VD_840x480 @@ -334,7 +334,7 @@ public class SocketSwClient { // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); } - } else if (action3 == 5) { + } else if (action3 == 5) {//结束PK // endDRGif(); LiveRoomViewHolder.d_pk_view.setVisibility(View.GONE); if (LiveSwAnchorActivity.mLiveAnchorViewHolder != null) { @@ -353,20 +353,20 @@ public class SocketSwClient { /* if (LiveAudienceActivity.getmLivePlayViewHolder() != null) { LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); }*/ - if(livePushSwViewHolder==null){ - if("4".equals(map.getString("msgtype"))){ + isDRPK = 1; + if (livePushSwViewHolder == null) { + if ("4".equals(map.getString("msgtype"))) { return; } UserBean u = new UserBean(); // u.setUserNiceName(map.getString("uname")); u.setId(map.getString("uid")); - if(StringUtil.isEmpty(u.getId())){ + if (StringUtil.isEmpty(u.getId())) { return; } - L.eSw("通知用户 action3 == 3:"+u.getId()); + L.eSw("通知用户 action3 == 3:" + u.getId()); mListener.onLinkDRMicPKToUser(u); Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); - isDRPK = 1; } } else if (action3 == 10) { //显示pk分数 @@ -374,6 +374,13 @@ public class SocketSwClient { // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); } + } else if (action3 == 7) { + L.eSw("主播退出直播間:"+map.getString("uid")); + mListener.onLinkDRMicPkQuit(map.getString("uid")); + //清除已邀请人数 + if(LiveSwAnchorActivity.mLiveAnchorViewHolder!=null){ + LiveSwAnchorActivity.mLiveAnchorViewHolder.removeYaoqing(map.getString("uid")); + } } break; @@ -1282,10 +1289,13 @@ public class SocketSwClient { u.setUserNiceName(map.getString("uname")); u.setAvatar(map.getString("uhead")); u.setRandomPk("11".equals(map.getString("msgtype"))); - mListener.onLinkMicPkApply(u, map.getString("stream"), "11".equals(map.getString("msgtype"))?2:1); + mListener.onLinkMicPkApply(u, map.getString("stream"), "11".equals(map.getString("msgtype")) ? 2 : 1); break; case 2://收到对方主播PK回调 L.eSw("收到对方主播PK回调"); + /*if("1".equals(map.getString("random_pk"))){ + + }*/ RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); mListener.onLinkMicToPk(map.getString("uid"), map.getString("uhead"), map.getString("uhead")); mListener.onLinkMicPkStart(map.getString("uid"), map.getString("uhead"), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); @@ -1340,15 +1350,13 @@ public class SocketSwClient { } break; case 10://系统发起PK回调 - if(livePushSwViewHolder!=null){ - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 2) - .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) - .param("pkuid", CommonAppConfig.getInstance().getUid()) - .param("msgtype", 2) - .param("uid", CommonAppConfig.getInstance().getUid()) + if (livePushSwViewHolder != null) { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK).param("action", 2) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()) + .param("msgtype", 2).param("uid", CommonAppConfig.getInstance().getUid()) .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("random_pk", "1") + .param("is_auto ", "1") .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); @@ -1376,65 +1384,25 @@ public class SocketSwClient { RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); LiveNetManager.get(mContext).getLiveInfo(map.getString("uid"), new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveInfoModel data) { - mListener.onLinkMicToPk(map.getString("uid"), data.getAvatar(), map.getString("uhead")); - mListener.onLinkMicPkStart(map.getString("uid"), data.getAvatar(), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); - if (livePushSwViewHolder != null) { - UserBean userBean = new UserBean(); - userBean.setId(map.getString("uid")); - userBean.setAvatar(data.getAvatar()); - userBean.setUserNiceName(map.getString("uname")); - livePushSwViewHolder.setAnPkRtc(userBean); - } - } - - @Override - public void onError(String error) { - - } + @Override + public void onSuccess(LiveInfoModel data) { + mListener.onLinkMicToPk(map.getString("uid"), data.getAvatar(), map.getString("uhead")); + mListener.onLinkMicPkStart(map.getString("uid"), data.getAvatar(), map.getString("uname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); + if (livePushSwViewHolder != null) { + UserBean userBean = new UserBean(); + userBean.setId(map.getString("uid")); + userBean.setAvatar(data.getAvatar()); + userBean.setUserNiceName(map.getString("uname")); + livePushSwViewHolder.setAnPkRtc(userBean); } - ); + } + + @Override + public void onError(String error) { + + } + }); } - /*JSONObject msg1 = new JSONObject(); - msg1.put("type", "autoLivePK"); - msg1.put("uid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()); - IMRTCManager.getInstance().requestJoinOtherRoom(map.getString("uid"), true, msg1.toString(), new IRCRTCResultCallback() { - @Override - public void onSuccess() { - if (WordUtil.isNewZh()) { - ToastUtil.show("邀请 " + map.getString("uid") + " 发送成功"); - } else { - ToastUtil.show("invite " + map.getString("uid") + " successful"); - } - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - runOnUiThread(new Runnable() { - @Override - public void run() { - dismiss(); - } - }); - //todo 安卓端状态码说明文档:https://docs.rongcloud.cn/v4/views/rtc/call/code/android.html - Log.e("ry", rtcErrorCode + "aaaaaa" + CommonAppConfig.getInstance().getUid() + "VDSSSS" + map.getString("uid")); - if (WordUtil.isNewZh()) { - ToastUtil.show("邀请 " + map.getString("uid") + " 发送失败 :" + rtcErrorCode); - } else { - ToastUtil.show("invite " + map.getString("uid") + " lose :" + rtcErrorCode); - } - } - });*/ break; } } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java index 24614a852..6480eb369 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java @@ -278,6 +278,11 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder { } + @Override + public void removeLiveUid(String uid) { + + } + @Override public void removeDetailView() { diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 52ba0d341..196b6ebc7 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -425,6 +425,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } + @Override + public void removeLiveUid(String uid) { + + } + @Override public void release() { mEnd = true; diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java index 26dac4602..844383315 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -1,6 +1,5 @@ package com.yunbao.live.views; -import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; import android.Manifest; import android.app.Activity; @@ -9,8 +8,6 @@ import android.content.Context; import android.graphics.Color; import android.media.AudioManager; import android.os.Build; -import android.os.Handler; -import android.os.Looper; import android.text.TextUtils; import android.util.Log; import android.view.Gravity; @@ -24,16 +21,12 @@ import android.widget.RelativeLayout; import android.widget.TextView; import com.alibaba.fastjson.JSONObject; -import com.google.android.exoplayer2.PlaybackException; -import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.ui.StyledPlayerView; -import com.google.android.exoplayer2.video.VideoSize; import com.google.gson.Gson; import com.lxj.xpopup.XPopup; import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; -import com.lzy.okserver.OkDownload; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.bean.BaseModel; @@ -70,31 +63,10 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import java.util.Locale; -import cn.rongcloud.rtc.api.RCRTCEngine; -import cn.rongcloud.rtc.api.RCRTCRemoteUser; -import cn.rongcloud.rtc.api.RCRTCRoom; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener; -import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleDataCallback; -import cn.rongcloud.rtc.api.callback.IRCRTCVideoInputFrameListener; import cn.rongcloud.rtc.api.stream.RCRTCInputStream; -import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo; -import cn.rongcloud.rtc.api.stream.RCRTCOutputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoInputStream; -import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig; -import cn.rongcloud.rtc.api.stream.RCRTCVideoView; -import cn.rongcloud.rtc.base.RCRTCMediaType; -import cn.rongcloud.rtc.base.RCRTCParamsType; -import cn.rongcloud.rtc.base.RCRTCRemoteVideoFrame; -import cn.rongcloud.rtc.base.RCRTCStreamType; -import cn.rongcloud.rtc.base.RTCErrorCode; -import cn.rongcloud.rtc.core.RendererCommon; import io.agora.beautyapi.faceunity.agora.SWAuManager; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.functions.Consumer; @@ -116,9 +88,6 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { private ViewGroup mPkContainer; public StyledPlayerView mVideoView; - private FrameLayout playFrameLayout; - private FrameLayout playFrameLayout1; - private View mLoading, mLoading2; private ImageView mCover; private boolean mPaused;//是否切后台了 @@ -142,7 +111,6 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { private boolean userJoinLinkMic = false;//用户是否已加入房间 //0未申请1申请中2连麦中 - RCRTCRoom rcrtcRoom; String purl, srcUrl; SWAuManager swAuManager; String liveUid; @@ -184,8 +152,6 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { EventBus.getDefault().register(this); Bus.getOn(this); mRoot = (ViewGroup) findViewById(R.id.root); - playFrameLayout = (FrameLayout) findViewById(R.id.playView); - playFrameLayout1 = (FrameLayout) findViewById(R.id.playView1); mSmallContainer = (ViewGroup) findViewById(R.id.small_container); mLeftContainer = (ViewGroup) findViewById(R.id.left_container); mRightContainer = (ViewGroup) findViewById(R.id.right_container); @@ -275,6 +241,25 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,liveUid, SWAuManager.getChannelName(liveUid)); } + @Override + public void removeLiveUid(String uid) { + //先结束PK + if(drMicUserList!=null){ + List tempList = new ArrayList<>(); + int index = -1; + for (int i = 0; i () { - - - @Override - public void onSuccess(RCRTCRoom data) { - userJoinLinkMic = true; - rcrtcRoom = data; - subscribeMic(data); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", LiveActivity.mLiveUid + errorCode + ""); - if (errorCode.getValue() == 50007) {//userJoinLinkMic可能失效,直接leaveRoom - userJoinLinkMic = false; - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - UsertoRY(); - } - }); - } else { - ToastUtil.show("房间失败" + errorCode); - } - - } - });*/ - - - } - - private void subscribeMic(RCRTCRoom data) { - runOnUiThread(new Runnable() { - @Override - public void run() { - RCRTCEngine.getInstance().enableSpeaker(true); - //遍历远端用户发布的资源列表 - Log.i(TAG, "软件资源数量:" + data.getLiveStreams().size()); - for (RCRTCInputStream stream : data.getLiveStreams()) { - Log.i(TAG, "资源流 type: " + stream.getMediaType()); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - //暂停播放 - - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT); - ry_view.addView(remoteView); - Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + data.getLiveStreams().size()); - } - userinputStreamList.add(stream); - } - rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList, new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", userinputStreamList.size() + LiveActivity.mLiveUid + "订阅失败" + errorCode.toString()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - - @Override - public void onSuccess() { - Log.e("ry", "订阅资源成功"); -// new Handler().postDelayed(new Runnable() { -// @Override -// public void run() { - toMic(); -// } -// }, 3000); - - } - }); - } - }); - } - - /** - * 主房间事件监听 - * 详细说明请参考文档:https://www.rongcloud.cn/docs/api/android/rtclib_v4/cn/rongcloud/rtc/api/callback/IRCRTCRoomEventsListener.html - */ - public IRCRTCRoomEventsListener roomEventsListener = new IRCRTCRoomEventsListener() { - @Override - public void onRemoteUserPublishResource(RCRTCRemoteUser rcrtcRemoteUser, List list) { - Log.e("ry", "远端来了" + list.size()); - //TODO 按需在此订阅远端用户发布的资源 - rcrtcRoom.getLocalUser().subscribeStreams(list, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "远端成功" + list.size()); - - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "远端失败" + list.size()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - - @Override - public void onRemoteUserMuteAudio(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - - } - - @Override - public void onRemoteUserMuteVideo(RCRTCRemoteUser remoteUser, RCRTCInputStream stream, boolean mute) { - - } - - @Override - public void onRemoteUserUnpublishResource(RCRTCRemoteUser remoteUser, List streams) { - - } - - @Override - public void onUserJoined(RCRTCRemoteUser remoteUser) { - - } - - @Override - public void onUserLeft(RCRTCRemoteUser remoteUser) { - - } - - @Override - public void onUserOffline(RCRTCRemoteUser remoteUser) { - - } - - @Override - public void onPublishLiveStreams(List streams) { - - } - - @Override - public void onUnpublishLiveStreams(List streams) { - - } - }; - - - public List userinputStreamList1 = new ArrayList<>(); - public List userinputStreamList2 = new ArrayList<>(); - - public void toMic() { - RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC, RCRTCParamsType.AudioScenario.MUSIC_CLASSROOM); - userinputStreamList1.clear(); - userinputStreamList2.clear(); - RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - int minRate = 200; - int maxRate = 900; - switch (IMLoginManager.get(mContext).getSelectClarity()) { - case 0: - rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - minRate = landscape == 1 ? 900 : 200; - maxRate = landscape == 1 ? 700 : 900; - break; - case 1: - rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; - minRate = landscape == 1 ? 900 : 250; - maxRate = landscape == 1 ? 700 : 2200; - break; - case 2: - rcrtcVideoResolution = landscape == 1 ? RCRTCParamsType.RCRTCVideoResolution.parseVideoResolution(960, 720) : RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; - minRate = landscape == 1 ? 900 : 400; - maxRate = landscape == 1 ? 700 : 4000; - break; - } - // 示例代码使用480x640分辨率演示 - RCRTCVideoStreamConfig config = RCRTCVideoStreamConfig.Builder.create() - //设置分辨率 - .setVideoResolution(rcrtcVideoResolution) - //设置帧率 - .setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_24) - //设置最小码率,480P下推荐200 - .setMinRate(minRate) - //设置最大码率,480P下推荐900 - .setMaxRate(maxRate).build(); - RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config); -// 创建视图渲染视图 -// RCRTCVideoView videoView = new RCRTCVideoView(contexts); -// RCRTCEngine.getInstance().getDefaultVideoStream().setVideoView(videoView); -//TODO 示例代码使用获取本地默认视频流、音频流演示 - ArrayList streams = new ArrayList<>(); -// streams.add(RCRTCEngine.getInstance().getDefaultVideoStream()); - streams.add(RCRTCEngine.getInstance().getDefaultAudioStream()); - if (landscape == 1) { - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - setLiveBeanLandscape(1); - } - }); - - } -// 开启摄像头 -// RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(null); -// 开始切换为主播身份 - RCRTCEngine.getInstance().getRoom().getLocalUser().switchToBroadcaster(streams, new IRCRTCSwitchRoleDataCallback() { - /** - * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 - * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 - */ - @Override - public void onKicked() { - Log.e("ry", "切换onKicked"); - - } - - @Override - public void onSuccess(RCRTCLiveInfo data) { - rcrtcRoom.registerRoomListener(roomEventsListener); - //该用户切换为主播成功,可以以主播身份进行音视频 - Log.e("ry", "切换成功"); - new Handler(Looper.getMainLooper()).post(new Runnable() { - public void run() { - if (onMicCallback != null) { - onMicCallback.onMikUpdate(); - } - //遍历远端用户列表 - for (int i = 0; i < rcrtcRoom.getRemoteUsers().size(); i++) { - Log.e("ry", rcrtcRoom.getRemoteUsers().get(i).getUserId() + "收到rcrtcOtherRoom" + rcrtcRoom.getRemoteUsers().size()); - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : rcrtcRoom.getRemoteUsers().get(i).getStreams()) { - Log.e("ry", i + "收到" + stream.getMediaType() + "实打实打算" + rcrtcRoom.getRemoteUsers().get(i).getUserId()); - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - if (userinputStreamList1.size() == 0) { - - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setStreamType(RCRTCStreamType.NORMAL); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - ((RCRTCVideoInputStream) stream).setVideoFrameListener(new IRCRTCVideoInputFrameListener() { - @Override - public void onFrame(RCRTCRemoteVideoFrame videoFrame) { - String debugText = " 2、安卓主播开播, 安卓用户申请连麦后 ,安卓用户这边底部画面不全 :" + videoFrame.getFrameType().name() + "\n" + "rotation:" + videoFrame.getRotation() + "\n" + "timestampNs:" + videoFrame.getTimestampNs() + "\n" + "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n"; - //Log.d("ry", "onFrame: " + debugText); - new Handler(Looper.getMainLooper()).post(() -> { - debugView.setText(debugText); - - }); - } - }); - //todo 本demo只演示添加1个远端用户的视图 - ry_view.removeAllViews(); - remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL); - ry_view.addView(remoteView); - } - userinputStreamList1.add(stream); - } - userinputStreamList2.add(stream); - } - } - //开始订阅资源 - rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList2, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "订阅资源成功"); - MicStatusManager.getInstance().setMicData(MicStatusManager.MIC_TYPE_OPEN, LiveActivity.mLiveUid); - AudioManager audioManager = (AudioManager) contexts.getSystemService(Context.AUDIO_SERVICE); - RCRTCEngine.getInstance().enableSpeaker(true); - audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); - audioManager.setSpeakerphoneOn(true); - - HttpClient.getInstance().get("live.joinDrLm", "live.joinDrLm").params("roomid", LiveActivity.mLiveUid).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.e("ry", code + "热热热"); - } - }); - } - - @Override - public void onFailed(RTCErrorCode rtcErrorCode) { - Log.e("ry", "订阅资源失败: " + rtcErrorCode.getReason()); - ToastUtil.show(mContext.getString(R.string.live_pk_link_error)); - } - }); - } - }); - - - } - - /** - * 当切换失败且不影响当前角色继续音视频时回调 - * @param errorCode 失败错误码 - */ - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", errorCode + "切换失败"); - - } - }); } @Override public void setLoadViewListener(LoadingListener listener) { super.setLoadViewListener(listener); } - - private void showLoadingDialog() { - if (PLAY_MODEL == PLAY_MODEL_480) return; - - new DialogUitl.Builder(mContext).setTitle("網絡提示").setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。").setView(R.layout.dialog_simple_tip).setClickCallback(new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - dialog.dismiss(); - } - }).build().show(); - PLAY_MODEL = PLAY_MODEL_480; - String url = srcUrl; - if (videoLandscape == VIDEO_VERTICAL) { - url = url.replace(".flv", videoRatioVertical[PLAY_MODEL_480] + videoFps[0] + ".flv"); - } else if (videoLandscape == VIDEO_HORIZONTAL) { - url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); - } - } - - private class ExoPlayerListener implements Player.Listener { - String TAG = "播放流"; - - @Override - public void onPlayerError(PlaybackException error) { - Player.Listener.super.onPlayerError(error); - debugView.setText("播放出错code=" + error.errorCode + " msg=" + error.getErrorCodeName()); - } - - @Override - public void onVideoSizeChanged(VideoSize videoSize) { - Player.Listener.super.onVideoSizeChanged(videoSize); - Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height); - //ToastUtil.show("分辨率: 宽 = " + videoSize.width + " 高 = " + videoSize.height); - if (videoSize.height > videoSize.width) { - videoLandscape = VIDEO_VERTICAL; - } else { - videoLandscape = VIDEO_HORIZONTAL; - } - } - - @Override - public void onPlaybackStateChanged(int playbackState) { - Player.Listener.super.onPlaybackStateChanged(playbackState); - if (playbackState == Player.STATE_BUFFERING) { - //showLoadingDialog(); - mLoading.setVisibility(View.VISIBLE); - OkDownload.getInstance().pauseAll(); - Log.i(TAG, "onPlaybackStateChanged: 缓存中"); - } else { - mLoading.setVisibility(View.INVISIBLE); - Log.i(TAG, "onPlaybackStateChanged: 播放中"); - } - } - - @Override - public void onIsPlayingChanged(boolean isPlaying) { - Player.Listener.super.onIsPlayingChanged(isPlaying); - if (isPlaying) { - hideCover(); - mLoading.setVisibility(View.INVISIBLE); - Log.i(TAG, "onIsPlayingChanged: 开始播放 | waitNextUrl = " + waitNextUrl); - OkDownload.getInstance().startAll(); - if (loadingListener != null) { - loadingListener.onPlayer(); - } - if (waitNextUrl != null) { - waitNextUrl = null; - } - } - } - } - - private int mPkTimeCount = 0; - - - public interface PlayViewLayoutInterface { - void playViewLayout(int width, int height); - } - - private PlayViewLayoutInterface layoutInterface; - - public void setLayoutInterface(PlayViewLayoutInterface layoutInterface) { - mVideoView.post(new Runnable() { - @Override - public void run() { - int width = mVideoView.getMeasuredWidth(); - int height = mVideoView.getMeasuredHeight(); - if (layoutInterface != null) { - layoutInterface.playViewLayout(width, height); - } - } - }); - } - - } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java index 73bb5b84f..5de3bf44a 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java @@ -94,6 +94,11 @@ public class LivePlayTxViewHolder extends LiveRoomPlayViewHolder implements ITXL } + @Override + public void removeLiveUid(String uid) { + + } + @Override public void removeDetailView() { diff --git a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java index 712888d0a..a1d826ecd 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -26,6 +26,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; import com.tencent.rtmp.ITXLivePushListener; import com.tencent.rtmp.TXLiveConstants; import com.yunbao.common.CommonAppConfig; @@ -103,7 +104,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX private boolean isPk = false; private boolean isNeedOpenCamera = false; private SWManager swManager; - private String pkUid1; + private String pkUid1; //单人PK 对方主播 uid //修改上面主播的头像 @Subscribe(threadMode = ThreadMode.MAIN) @@ -252,9 +253,9 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX }); } - public void exitChannelDrPk(List drPkbeanList){ - for (int i = 0; i drPkbeanList) { + for (int i = 0; i < drPkbeanList.size(); i++) { + if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeanList.get(i).getId()))) { SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), String.valueOf(drPkbeanList.get(i).getId())); } } @@ -275,8 +276,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX swManager.updateMyChannelView((FrameLayout) mLeftContainer); //清除 mBigContainer 中的渲染 mBigContainer.removeAllViews(); - - btn_close.setVisibility(View.VISIBLE); + showButtonGone(); //设置对方主播的渲染视图 设置到 rightContainer swManager.setPkContainer(mRightContainer); swManager.joinChannelEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, u.getId(), SWAuManager.getChannelName(u.getId())); @@ -288,57 +288,57 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX .params("type", "1") .params("sign", "1") .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msgs, String[] info) { - if (code == 0) { - HttpClient.getInstance().get("Livepk.setPK", "Livepk.setPK") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("pkuid", u.getId()) - .params("type", "1") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msgs, String[] info) { - if (code == 0) { - L.eSw("555555555555555555555555555555555555"); - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", Constants.SOCKET_LINK_MIC_PK) - .param("action", 4) - .param("pkname", u.getUserNiceName()) - .param("pkuid", u.getId()) - .param("pkhead", u.getAvatar()) - .param("uname", u.getUserNiceName()) - .param("uhead", u.getAvatar()) - .param("uid", CommonAppConfig.getInstance().getUid()); - msg1.create(); + @Override + public void onSuccess(int code, String msgs, String[] info) { + if (code == 0) { + HttpClient.getInstance().get("Livepk.setPK", "Livepk.setPK") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("pkuid", u.getId()) + .params("type", "1") + .params("sign", "1") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msgs, String[] info) { + if (code == 0) { + L.eSw("555555555555555555555555555555555555"); + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", Constants.SOCKET_LINK_MIC_PK) + .param("action", 4) + .param("pkname", u.getUserNiceName()) + .param("pkuid", u.getId()) + .param("pkhead", u.getAvatar()) + .param("uname", u.getUserNiceName()) + .param("uhead", u.getAvatar()) + .param("uid", CommonAppConfig.getInstance().getUid()); + msg1.create(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - Message message1 = Message.obtain("g" + CommonAppConfig.getInstance().getUid(), conversationType, messageContent); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + Message message1 = Message.obtain("g" + CommonAppConfig.getInstance().getUid(), conversationType, messageContent); - RongIMClient.getInstance().sendMessage(message1, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(Message message) { + RongIMClient.getInstance().sendMessage(message1, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(Message message) { - } + } - @Override - public void onSuccess(Message message) { - Log.i("tx", "发送成功"); - } + @Override + public void onSuccess(Message message) { + Log.i("tx", "发送成功"); + } - @Override - public void onError(Message message, RongIMClient.ErrorCode errorCode) { + @Override + public void onError(Message message, RongIMClient.ErrorCode errorCode) { - } - }); - } + } + }); + } - } - }); - } - } - }); + } + }); + } + } + }); mLiveSwLinkMicPkPresenter.setPkUserInfoView(u); } @@ -346,22 +346,23 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX private int currentPosition = 0; private String drpkUid3 = ""; + public int setAnDrPkRtc(String uid, int position) { - L.eSw("setAnDrPkRtc uid:"+uid+" position"+position); - int temp= -1; + L.eSw("setAnDrPkRtc uid:" + uid + " position" + position); + int temp = -1; if (swManager != null && !StringUtil.isEmpty(uid)) { L.eSw("设置对方主播的视图 setAnDrPkRtc" + uid + "position:" + position); - if(currentPosition==0){ + if (currentPosition == 0) { position = 2; } - if(position==-1){ - temp = currentPosition+1; - }else{ + if (position == -1) { + temp = currentPosition + 1; + } else { temp = position; } switch (temp) { case 2: - swManager.joinChannelDrEx(dr2_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); + swManager.joinChannelDrEx(dr2_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); swManager.updateMyChannelView(dr1_preview); mBigContainer.removeAllViews(); @@ -370,17 +371,17 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX break; case 3: drpkUid3 = uid; - swManager.joinChannelDrEx(dr4_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); + swManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); dr3_preview.setVisibility(View.GONE); dr4_preview.setVisibility(View.VISIBLE); break; case 4: dr3_preview.setVisibility(View.VISIBLE); //先退出这个主播的直播间,在进入该直播间,(视图问题暂时這樣處理) - swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),drpkUid3); - swManager.joinChannelDrEx(dr3_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3)); + swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drpkUid3); + swManager.joinChannelDrEx(dr3_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3)); - swManager.joinChannelDrEx(dr4_preview,CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); + swManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); break; } dr_pk_view.setVisibility(View.VISIBLE); @@ -389,7 +390,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX return currentPosition; } - public void anchorClose(){ + public void anchorClose() { swManager.updateMyChannelView((FrameLayout) mBigContainer); //用户主动断开连麦再退出画面 } @@ -399,7 +400,6 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX } - public void onLinkDRMicPkApply(UserBean userBean) { if (mLiveSwLinkMicPkPresenter != null) { mLiveSwLinkMicPkPresenter.onLinkDRMicPkApply(userBean); @@ -439,6 +439,10 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX btn_close.setVisibility(View.GONE); } + public void showButtonGone() { + btn_close.setVisibility(View.VISIBLE); + } + @Override public void toggleCamera() { if (mCameraFront) { @@ -471,86 +475,6 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX if (swManager != null) { swManager.createChannel(CommonAppConfig.SWToken, CommonAppConfig.getChannelName()); } - if (rcrtcLiveInfo != null) { - rcrtcLiveInfo.addPublishStreamUrl(pushUrl, new IRCRTCResultDataCallback() { - @Override - public void onSuccess(String[] data) { - //强制设置开播后cdn的尺寸竖屏,因为有时候PK异常退出,cdn没有还原竖屏。 - if (rtcRoom != null) { - RCRTCMixConfig config = new RCRTCMixConfig(); - RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig(); - config.setMediaConfig(mediaConfig); - //视频输出配置 - RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig(); - mediaConfig.setVideoConfig(videoConfig); - //大流视频的输出参数 - RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout(); - - //推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置 - //如不设置宽高值则服务端将使用默认宽高 360 * 640 - //例:发布的视频分辨率为720 * 1280,如果不设置则观众端看到的视频分辨率为 360 * 640, - //所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中 - //設置開播分辨率 - //設置開播分辨率 - RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - int minRate = 200; - int maxRate = 900; - switch (IMLoginManager.get(mContext).getSelectClarity()) { - case 0: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; - break; - case 1: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280; - break; - case 2: - rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920; - break; - } - int width = rcrtcVideoResolution.getWidth(); - int height = rcrtcVideoResolution.getHeight(); - normal.setWidth(width); //视频宽 - normal.setHeight(height); //视频高 - normal.setFps(15); //视频帧率 - videoConfig.setVideoLayout(normal); - //2. 合流画布设置 - //(请参照画布和声音配置示例代码) - //3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高 - ArrayList list = new ArrayList<>(); - config.setCustomLayouts(list); - //user1的视频流 - RCRTCMixConfig.CustomLayoutList.CustomLayout videoLayout1 = new RCRTCMixConfig.CustomLayoutList.CustomLayout(); - list.add(videoLayout1); - videoLayout1.setVideoStream(RCRTCEngine.getInstance().getDefaultVideoStream()); // RCRTCStream#MediaType 必须是Video - videoLayout1.setX(0); //X 坐标 - videoLayout1.setY(0); //Y 坐标 - videoLayout1.setWidth(720); // 视频窗口的宽 - videoLayout1.setHeight(1280); // 视频窗口的高 - //2. 合流画布设置 - rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "混成功12"); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "混失败" + errorCode); - - } - }); - } - - - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - } - }); - startCountDown(); - } else { - ToastUtil.show("请稍后,准备中...."); - } } public boolean isPking() { @@ -563,7 +487,6 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX @Override public void onPause() { mPaused = true; - } @Override diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index 7fb4954ca..a06dc20a3 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -122,6 +122,8 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public abstract void initSwEngine(String liveUid); + public abstract void removeLiveUid(String uid); + public abstract void removeDetailView(); public abstract void setPkView(String liveUid); diff --git a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java index 02e100b65..bf024bd45 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -25,6 +25,7 @@ import androidx.core.content.ContextCompat; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.GsonUtils; +import com.google.gson.Gson; import com.ms.banner.Banner; import com.ms.banner.BannerConfig; import com.ms.banner.listener.OnBannerClickListener; @@ -40,6 +41,7 @@ import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; @@ -87,6 +89,25 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { private TextView mLiveTimeTextView;//主播的直播时长 private long mAnchorLiveTime;//主播直播时间 private LiveRoomHandler mLiveRoomHandler; + private static LinearLayout btn_end_pk_dr; + private String drpkRoomId; //多人 PK 房主 roomUid + public void setDrpkRoomId(String drpkRoomId) { + this.drpkRoomId = drpkRoomId; + } + + public void showEndPkBt(){ + if(btn_end_pk_dr!=null){ + if(btn_start_dr_pk_view.getVisibility()==View.GONE){ + btn_end_pk_dr.setVisibility(View.VISIBLE); + } + } + } + + public void closeEndPkBt(){ + if(btn_end_pk_dr!=null){ + btn_end_pk_dr.setVisibility(View.GONE); + } + } public LiveRyAnchorViewHolder(Context context, ViewGroup parentView) { super(context, parentView); @@ -108,6 +129,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { Bus.getOn(this); mDrawable0 = ContextCompat.getDrawable(mContext, R.mipmap.icon_live_func_0); mDrawable1 = ContextCompat.getDrawable(mContext, R.mipmap.icon_live_func_1); + btn_end_pk_dr = (LinearLayout) findViewById(R.id.btn_end_pk_dr); mBtnFunction = (ImageView) findViewById(R.id.btn_function); btn_dr = (TextView) findViewById(R.id.btn_dr); mBanner = (Banner) findViewById(R.id.banner); @@ -171,6 +193,22 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { yaoqing.clear(); } }); + btn_end_pk_dr.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + closeEndPkBt(); + HttpClient.getInstance().post("live.leaveDRPKroom", "live.leaveDRPKroom") + .params("roomid", drpkRoomId) + .params("uid", CommonAppConfig.getInstance().getUid()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + L.eSw("live.leaveDRPKroom:code:" + code + " info" + new Gson().toJson(info)); + + } + }); + } + }); btn_dr.setOnClickListener(new View.OnClickListener() { @Override @@ -204,6 +242,10 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { yaoqing.put(numinda, numinda); } + public void removeYaoqing(String numinda){ + yaoqing.remove(numinda); + } + @Override public void onClick(View v) { if (!canClick()) { diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 12e1183bc..dcc465b40 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -389,7 +389,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe liveHandler.removeCallbacks(loadTimeoutRunnableGone); if (mLivePlayViewHolder == null) { if (isSw) { - mLivePlayViewHolder = new LivePlaySwViewHolder(mContext, playContainer, 1); + mLivePlayViewHolder = new LivePlaySwViewHolder(mContext, playContainer, mLiveBean.getLandscape()); } else { mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); } @@ -419,7 +419,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveAudienceViewHolder.subscribeActivityLifeCycle(); } else { mLivePlayViewHolder.initSwEngine(liveID); - mLivePlayViewHolder.setLiveBeanLandscape(1); + mLivePlayViewHolder.setLiveBeanLandscape(mLiveBean.getLandscape()); mLiveLinkMicPresenter.setLiveSdk(mLiveSDK); mLiveLinkMicAnchorPresenter.setLiveSdk(mLiveSDK); } @@ -983,6 +983,11 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter.release(); mLiveRyLinkMicPkPresenter = null; } + if(mLiveSwLinkMicPkPresenter!=null){ + mLiveSwLinkMicPkPresenter.clearData(); + mLiveSwLinkMicPkPresenter.release(); + mLiveSwLinkMicPkPresenter = null; + } if(mLivePlayViewHolder!=null){ mLivePlayViewHolder.stopPlay2(); } @@ -1705,6 +1710,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //mLivePlayViewHolder.setDrMicInfo(u); } + @Override + public void onLinkDRMicPkQuit(String uid) { + L.eSw("onLinkDRMicPkQuit:"+uid); + mLivePlayViewHolder.removeLiveUid(uid); + } + /** * 主播与主播PK 所有人收到PK开始的回调 */ diff --git a/live/src/main/res/layout/view_live_push_sw.xml b/live/src/main/res/layout/view_live_push_sw.xml index 4cd13440a..bbe8f0a50 100644 --- a/live/src/main/res/layout/view_live_push_sw.xml +++ b/live/src/main/res/layout/view_live_push_sw.xml @@ -44,7 +44,7 @@ android:layout_height="270dp" android:layout_marginTop="130dp" android:orientation="horizontal" - android:visibility="visible"> + android:visibility="gone"> + + + + + + Date: Thu, 30 May 2024 13:20:40 +0800 Subject: [PATCH 30/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beautyapi/faceunity/agora/SWManager.java | 26 +++++++++++++++---- .../live/activity/LiveAudienceActivity.java | 3 +++ .../presenter/LiveSwLinkMicPkPresenter.java | 4 +-- .../live/views/LivePlaySwViewHolder.java | 3 ++- .../live/views/LivePushSwViewHolder.java | 22 +++++++++++++--- .../live/views/PortraitLiveManager.java | 2 +- 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 2b7934d3b..775696051 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -57,6 +57,12 @@ public class SWManager extends BaseCacheManager { private onRtcEngineListener onRtcEngineListener; private List drPkUserInfo = new ArrayList<>(); + private onDrPkJoinSuccessListener onDrPkJoinSuccessListener; + + public void setOnDrPkJoinSuccessListener(SWManager.onDrPkJoinSuccessListener onDrPkJoinSuccessListener) { + this.onDrPkJoinSuccessListener = onDrPkJoinSuccessListener; + } + public void setOnRtcEngineListener(SWManager.onRtcEngineListener onRtcEngineListener) { this.onRtcEngineListener = onRtcEngineListener; } @@ -322,7 +328,7 @@ public class SWManager extends BaseCacheManager { * @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 position) { int tempUid; if (StringUtil.isEmpty(strUid)) { tempUid = 0; @@ -342,6 +348,12 @@ public class SWManager extends BaseCacheManager { RtcConnection rtcConnection = new RtcConnection(); rtcConnection.channelId = channelName; //對方主播的頻道 rtcConnection.localUid = tempUid;//自己的ID + + SurfaceView surfaceView = new SurfaceView(mContext); + surfaceView.setZOrderMediaOverlay(true); + frameLayout.addView(surfaceView); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, Integer.parseInt(toUid)); + L.eSw("strUid:" + tempUid + "_token:" + token + "_channelName:" + channelName); // 用内部通知,刷新多人PK的用户信息 mRtcEngine.joinChannelEx(token, rtcConnection, options, new IRtcEngineEventHandler() { @@ -352,10 +364,6 @@ public class SWManager extends BaseCacheManager { 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_HIDDEN, Integer.parseInt(toUid)); mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); } }); @@ -493,4 +501,12 @@ public class SWManager extends BaseCacheManager { return CommonAppConfig.SWChannelPrefix + liveUid; } } + + public interface onDrPkJoinSuccessListener{ + void joinSuccess1(); + void joinSuccess2(); + void joinSuccess3(); + void joinSuccess4(); + + } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 7493e4e30..0e67649f4 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -350,13 +350,16 @@ public class LiveAudienceActivity extends LiveActivity { if (itemModelList.size() == 0) { return; } + Log.e("直播间接口调用排查", "transformPage 11"); ViewGroup viewGroup = (ViewGroup) page; Log.e(TAG, "position:" + mCurrentItem); if ((position < 0 && viewGroup.getId() != mCurrentItem)) { + Log.e("直播间接口调用排查", "transformPage 22"); // room_container 为视频播放的根布局 id View rootView = viewGroup.findViewById(R.id.drawer_layout); if (rootView != null && rootView.getParent() != null && rootView.getParent() instanceof ViewGroup) { ((ViewGroup) (rootView.getParent())).removeView(rootView); + Log.e("直播间接口调用排查", "transformPage 33"); manager.onRemove(false); } } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index acba3a23a..f30d6121c 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -611,7 +611,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UN_LEAVELIVE)); LiveSwAnchorActivity.isDRPK = 1; LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); - SocketSwLinkMicPkUtil.linkMicPkAccept(mSocketSwClient, mApplyUid, mApplyUrl, mApplyNmae); + //SocketSwLinkMicPkUtil.linkMicPkAccept(mSocketSwClient, mApplyUid, mApplyUrl, mApplyNmae); EventBus.getDefault().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.UP_PK_TWO).setObject(mApplyUid)); onLinkMicPkStart(mApplyUid, 2); } @@ -1256,7 +1256,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } } - }, 2000); + }, 1000); L.eSw("dRjoinOtherRoom:size:" + drPkbeanList.size() + " json " + new Gson().toJson(drPkbeanList)); } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java index 844383315..c8211ff9b 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -638,13 +638,14 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { mCover.setVisibility(View.VISIBLE); } } - swAuManager.exitChannelAll(); stopPlay2(); } @Override public void stopPlay2() { + swAuManager.exitChannelAll(); drMicUserList = new ArrayList<>(); + } @Override diff --git a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java index a1d826ecd..08a8dde82 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -122,6 +122,11 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX } } + public onDrPkJoinSuccessListener onDrPkJoinSuccessListener; + + public void setOnDrPkJoinSuccessListener(LivePushSwViewHolder.onDrPkJoinSuccessListener onDrPkJoinSuccessListener) { + this.onDrPkJoinSuccessListener = onDrPkJoinSuccessListener; + } public LivePushSwViewHolder(Context context, ViewGroup parentView) { super(context, parentView); @@ -362,7 +367,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX } switch (temp) { case 2: - swManager.joinChannelDrEx(dr2_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); + swManager.joinChannelDrEx(dr2_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid),temp); swManager.updateMyChannelView(dr1_preview); mBigContainer.removeAllViews(); @@ -371,7 +376,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX break; case 3: drpkUid3 = uid; - swManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); + swManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid),temp); dr3_preview.setVisibility(View.GONE); dr4_preview.setVisibility(View.VISIBLE); break; @@ -379,9 +384,9 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX dr3_preview.setVisibility(View.VISIBLE); //先退出这个主播的直播间,在进入该直播间,(视图问题暂时這樣處理) swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drpkUid3); - swManager.joinChannelDrEx(dr3_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3)); + swManager.joinChannelDrEx(dr3_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3),temp); - swManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid)); + swManager.joinChannelDrEx(dr4_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid),temp); break; } dr_pk_view.setVisibility(View.VISIBLE); @@ -654,4 +659,13 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX swManager.exitChannelAll(); } } + + public interface onDrPkJoinSuccessListener{ + void joinSuccess1(); + void joinSuccess2(); + void joinSuccess3(); + void joinSuccess4(); + + } + } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index dcc465b40..b8344bcca 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -344,9 +344,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } }; - @Override public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk, boolean isSw) { + Log.e("直播间接口调用排查", "onAdd onAdd onAdd onAdd"); isEnterRoom = false; MobclickAgent.onEvent(mContext, "live_room_chat_list", "滑动直播间聊天列表"); openParametersModel = new OpenParametersModel(); From 5f3ebb4235e8a32bb3c25cea5489c92cbacf62a5 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 30 May 2024 15:52:34 +0800 Subject: [PATCH 31/64] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E9=97=B4=20=E7=94=A8=E6=88=B7=E7=AD=89=E7=BA=A7+=E8=B6=85?= =?UTF-8?q?=E7=9A=87+=E7=B2=89=E4=B8=9D=E7=89=8C+=E5=9B=BE=E6=A0=87+?= =?UTF-8?q?=E5=90=8D=E5=AD=97=EF=BC=8810=E5=AD=97=EF=BC=89=E4=BC=9A?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1=E5=90=8D=E5=AD=97=E5=89=8D=E9=9D=A2=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.gradle | 2 +- .../com/yunbao/live/utils/LiveTextRender.java | 87 ++++++++++++++----- live/src/main/res/layout/item_live_chat.xml | 2 +- 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/config.gradle b/config.gradle index fd33bfeaf..882f01bd3 100644 --- a/config.gradle +++ b/config.gradle @@ -4,7 +4,7 @@ ext { buildToolsVersion: "29.0.2", minSdkVersion : 21, targetSdkVersion : 33, - versionCode : 473, + versionCode : 474, versionName : "6.6.8" ] manifestPlaceholders = [ diff --git a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java index b220d8f07..f9f67b5ba 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -21,6 +21,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.MeasureSpec; +import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; @@ -263,7 +264,7 @@ public class LiveTextRender { } public interface CreatePrefixCallback { - void onPrefixCallback(SpannableStringBuilder builder); + void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth); } /** @@ -353,19 +354,20 @@ public class LiveTextRender { index = builder.length(); } } - createPrefixCallback.onPrefixCallback(builder); + createPrefixCallback.onPrefixCallback(builder, 0); } @Override public void onLoadFailed() { SpannableStringBuilder builder = new SpannableStringBuilder(); int index = 0; - + int prefixWidth = 0; if (levelDrawable != null) { builder.append(" "); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += levelDrawable.getBounds().width(); } if (gzDrawablesMap.containsKey(bean)) {//贵族 @@ -373,6 +375,7 @@ public class LiveTextRender { gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += gzDrawablesMap.get(bean).getBounds().width(); } if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 @@ -380,6 +383,7 @@ public class LiveTextRender { ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += ryxzDrawablesMap.get(bean).getBounds().width(); } if (nhDrawablesMap.containsKey(bean)) {//靓号 @@ -387,6 +391,7 @@ public class LiveTextRender { nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += nhDrawablesMap.get(bean).getBounds().width(); } //在这里添加粉丝徽章的图片 if (!TextUtils.isEmpty(bean.getMedalNmae()) && !TextUtils.isEmpty(bean.getMedalLevelImageUrl()) @@ -397,6 +402,7 @@ public class LiveTextRender { drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += drawable.getBounds().width(); } } @@ -421,7 +427,7 @@ public class LiveTextRender { index = builder.length(); } } - createPrefixCallback.onPrefixCallback(builder); + createPrefixCallback.onPrefixCallback(builder, prefixWidth); } }); @@ -515,9 +521,9 @@ public class LiveTextRender { } public void getGuardImage(Context mContext, int guardType, ImgLoader.DrawableCallback callback) { - if (guardType==0){ + if (guardType == 0) { callback.onLoadFailed(); - }else { + } else { if (mContext instanceof Activity) { if (((Activity) mContext).isDestroyed()) { mContext = CommonAppContext.getTopActivity(); @@ -684,7 +690,7 @@ public class LiveTextRender { createPrefix(drawable, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int color = Color.parseColor("#68F1F4"); if (bean.isAnchor()) { color = Color.parseColor("#FBEABF"); @@ -696,20 +702,20 @@ public class LiveTextRender { builder = renderGift(color, builder, bean); break; default: - builder = renderChat(color, builder, bean); + builder = renderChat(textView, color, builder, bean, prefixWidth); break; } textView.setText(builder); } }); - } + }// 123123123123123123123123 @Override public void onLoadFailed() { createPrefix(null, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int color = 0; if (bean.isAnchor()) { color = 0xffffdd00; @@ -721,7 +727,7 @@ public class LiveTextRender { builder = renderGift(color, builder, bean); break; default: - builder = renderChat(color, builder, bean); + builder = renderChat(textView, color, builder, bean, prefixWidth); break; } textView.setText(builder); @@ -808,12 +814,31 @@ public class LiveTextRender { /** * 渲染普通聊天消息 */ - private SpannableStringBuilder renderChat(int color, SpannableStringBuilder builder, LiveChatBean bean) { + private SpannableStringBuilder renderChat(TextView textView, int color, SpannableStringBuilder builder, LiveChatBean bean, int prefixWidth) { int length = builder.length(); String name = bean.getUserNiceName(); if (bean.getType() != LiveChatBean.ENTER_ROOM) {//产品规定,进场消息不允许加冒号 name += ":"; } + SpannableStringBuilder sb = new SpannableStringBuilder(); + sb.append(builder).append(name).append(" "); + float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + int width = ((ViewGroup) textView.getParent()).getWidth(); + //检测渲染后图标+名字是否超过父布局宽度,超过了就做换行处理 + if (measuredText > width) { + sb.clear(); + sb.append(builder); + for (int i = 0; i < name.length(); i++) { + sb.append(name.charAt(i)).append(" "); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + if (measuredText + 1 > width) { + name = name.substring(0, i+1) + "\n" + name.substring(i+1); + break; + } + } + sb.clear(); + } + // name=name.substring(0,7)+"\n"+name.substring(7); builder.append(name); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) { @@ -823,6 +848,24 @@ public class LiveTextRender { builder.setSpan(new ForegroundColorSpan(color), length, length + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } int lengthContent = builder.length(); + //这一段先别删,万一后面要改内容换行呢 + /* sb.clear(); + sb.append(builder).append(bean.getContent()); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + if (measuredText > width) { + sb.clear(); + sb.append(builder); + for (int i = 0; i < bean.getContent().length(); i++) { + sb.append(bean.getContent().charAt(i)); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + if (measuredText + 3 > width) { + bean.setContent(bean.getContent().substring(0, i) + "\n"+ bean.getContent().substring(i)); + bean.setContent(""); + break; + } + } + } +*/ builder.append(bean.getContent()); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getContentColor())) { @@ -889,7 +932,7 @@ public class LiveTextRender { if (textView != null) { createPrefix(drawable, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int start = builder.length(); String name = bean.getUserNiceName() + " "; builder.append(name); @@ -904,15 +947,15 @@ public class LiveTextRender { @Override public void onLoadFailed() { if (textView != null) { - createPrefix(null, bean, new CreatePrefixCallback() { - @Override - public void onPrefixCallback(SpannableStringBuilder builder) { - int start = builder.length(); - String name = bean.getUserNiceName() + " "; - builder.append(name); - textView.setText(builder); - } - }); + createPrefix(null, bean, new CreatePrefixCallback() { + @Override + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { + int start = builder.length(); + String name = bean.getUserNiceName() + " "; + builder.append(name); + textView.setText(builder); + } + }); } } diff --git a/live/src/main/res/layout/item_live_chat.xml b/live/src/main/res/layout/item_live_chat.xml index c4d360d8c..da2996682 100644 --- a/live/src/main/res/layout/item_live_chat.xml +++ b/live/src/main/res/layout/item_live_chat.xml @@ -10,7 +10,7 @@ Date: Thu, 30 May 2024 18:25:01 +0800 Subject: [PATCH 32/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beautyapi/faceunity/agora/SWManager.java | 30 +++++ .../live/activity/LiveSwAnchorActivity.java | 2 + .../live/presenter/LiveGiftAnimPresenter.java | 59 ++++----- .../presenter/LiveSwLinkMicPkPresenter.java | 3 + .../yunbao/live/socket/SocketSwClient.java | 1 - .../live/views/LivePlayKsyViewHolder.java | 5 + .../live/views/LivePlayRyViewHolder.java | 5 + .../live/views/LivePlaySwViewHolder.java | 64 +++++---- .../live/views/LivePlayTxViewHolder.java | 5 + .../live/views/LiveRoomPlayViewHolder.java | 2 + .../yunbao/live/views/LiveRoomViewHolder.java | 7 + .../live/views/PortraitLiveManager.java | 121 +++++++++++------- .../main/res/layout/item_anchor_mic_info.xml | 12 +- 13 files changed, 205 insertions(+), 111 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 775696051..1c1fdea91 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -184,6 +184,36 @@ public class SWManager extends BaseCacheManager { } } + + public void setDrPkNumClarity(int selectClarity) { + if (cfg != null && mRtcEngine != null) { + VideoEncoderConfiguration.VideoDimensions videoDimensions = new VideoEncoderConfiguration.VideoDimensions(); + switch (selectClarity) { + case 1: + videoDimensions.width = 720; + videoDimensions.height = 1280; + cfg.dimensions = videoDimensions; + break; + case 2: + case 3: + videoDimensions.width = 360; + videoDimensions.height = 640; + cfg.dimensions = videoDimensions; + break; + case 4: + videoDimensions.width = 360; + videoDimensions.height = 320; + cfg.dimensions = videoDimensions; + break; + } + mRtcEngine.setVideoEncoderConfiguration(cfg); + } + } + + + + + /** * 设置镜像模式 */ diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index 01e860dd1..b958b1432 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -123,6 +123,7 @@ import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.base.RCRTCRect; import cn.rongcloud.rtc.base.RTCErrorCode; +import io.agora.beautyapi.faceunity.agora.SWManager; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; @@ -1656,6 +1657,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl mLiveRoomViewHolder.endDRGif(); } } + SWManager.get().setDrPkNumClarity(1); // if (mLiveRoomViewHolder != null) { // mLiveRoomViewHolder.hotAddVisibility(false); // } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java index 6909894a4..1c167b617 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java @@ -374,18 +374,13 @@ public class LiveGiftAnimPresenter { new Handler().postDelayed(new Runnable() { @Override public void run() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) - .setmLiveUid(mLiveUid) - .setmStream(mStream) - .setmWishGiftId(blindBox.getEvent().getBlindBoxId() + "") - .setIsContactGift(true)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP).setmLiveUid(mLiveUid).setmStream(mStream).setmWishGiftId(blindBox.getEvent().getBlindBoxId() + "").setIsContactGift(true)); } }, 1000); } else { - if (mIvLook.getTag()!=null&&mIvLook.getTag()instanceof LiveReceiveGiftBean){ + if (mIvLook.getTag() != null && mIvLook.getTag() instanceof LiveReceiveGiftBean) { changeLiveRoom((LiveReceiveGiftBean) mIvLook.getTag()); - }else { + } else { changeLiveRoom(); } @@ -436,6 +431,7 @@ public class LiveGiftAnimPresenter { } }); } + private void changeLiveRoom(LiveReceiveGiftBean mTempGifGiftBean) { if (mTempGifGiftBean != null) { String uid = mTempGifGiftBean.getUid(); @@ -459,7 +455,7 @@ public class LiveGiftAnimPresenter { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw) { if (liveBean == null) { return; } @@ -503,7 +499,7 @@ public class LiveGiftAnimPresenter { LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw) { if (liveBean == null) { return; } @@ -657,6 +653,16 @@ public class LiveGiftAnimPresenter { }); } + + /** + * 釋放全局通知 + */ + public void releaseServiceNotice() { + L.eSw("releaseServiceNotice 釋放全局通知"); + mHandler.sendEmptyMessageDelayed(full_service_notice_new_1, 100); + full_service_notice_new.setVisibility(View.GONE); + } + private void setGitTipAnimatorBuyZuoji() { mDp500 = DpUtil.dp2px(500); mGifGiftTipShowAnimatorBuyZuoji = ObjectAnimator.ofFloat(mGifGiftTipGroupBuyZuoji, "translationX", mDp500, 0); @@ -1003,8 +1009,7 @@ public class LiveGiftAnimPresenter { } } } else { - if ((bean.getGifUrl().contains("svga") || bean.getGifUrl().contains("gif")) && - IMLoginManager.get(mContext).isGiftEffect()) { + if ((bean.getGifUrl().contains("svga") || bean.getGifUrl().contains("gif")) && IMLoginManager.get(mContext).isGiftEffect()) { //同一直播间,玩家自己送礼物,也能看到全服通知 //同一直播间,其他玩家也能看到全服通知 @@ -1159,6 +1164,7 @@ public class LiveGiftAnimPresenter { mRoomNum = event.getLiveuid(); if (mShowAllServer) { + L.eSw("mGifAll != null"); if (mGifAll != null) { LiveReceiveGiftBean bean = new LiveReceiveGiftBean(); bean.setSendtype(91); @@ -1167,6 +1173,7 @@ public class LiveGiftAnimPresenter { mGifAll.offer(bean); } } else { + L.eSw("mGifAll != nullnullnullnullnullnull"); notifyFFGGGDJANEvent = event; mShowAllServer = true; index4Guard = getFirstIndexOfValue(heightOffsetArr, 0); @@ -1264,23 +1271,17 @@ public class LiveGiftAnimPresenter { mGifGiftTipGroupBuyGuardNew.setVisibility(View.VISIBLE); switch (event.getGuardType()) { case "1": - guardAllServerNotifyBg.setBackgroundResource(WordUtil.isNewZh() ? - R.mipmap.background_all_server_notify_star_zh : - R.mipmap.background_all_server_notify_star_en); + guardAllServerNotifyBg.setBackgroundResource(WordUtil.isNewZh() ? R.mipmap.background_all_server_notify_star_zh : R.mipmap.background_all_server_notify_star_en); mGifGiftTipBuyGuardNew.setTextColor(Color.parseColor("#072A93")); mIvLookBuyGuardNew.setBackgroundResource(R.mipmap.btn_star_guard_onlookers); break; case "2": - guardAllServerNotifyBg.setBackgroundResource(WordUtil.isNewZh() ? - R.mipmap.background_all_server_notify_king_zh : - R.mipmap.background_all_server_notify_king_en); + guardAllServerNotifyBg.setBackgroundResource(WordUtil.isNewZh() ? R.mipmap.background_all_server_notify_king_zh : R.mipmap.background_all_server_notify_king_en); mGifGiftTipBuyGuardNew.setTextColor(Color.parseColor("#BF0B0A")); mIvLookBuyGuardNew.setBackgroundResource(R.mipmap.btn_king_guard_onlookers); break; case "3": - guardAllServerNotifyBg.setBackgroundResource(WordUtil.isNewZh() ? - R.mipmap.background_all_server_notify_god_zh : - R.mipmap.background_all_server_notify_sgod_en); + guardAllServerNotifyBg.setBackgroundResource(WordUtil.isNewZh() ? R.mipmap.background_all_server_notify_god_zh : R.mipmap.background_all_server_notify_sgod_en); mGifGiftTipBuyGuardNew.setTextColor(Color.parseColor("#41057E")); mIvLookBuyGuardNew.setBackgroundResource(R.mipmap.btn_god_guard_onlookers); break; @@ -1333,13 +1334,7 @@ public class LiveGiftAnimPresenter { IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); if (!TextUtils.isEmpty(notifyFFGGGDJANEvent.getLink())) { StringBuffer htmlUrl = new StringBuffer(); - htmlUrl.append(notifyFFGGGDJANEvent.getLink()) - .append(notifyFFGGGDJANEvent.getLink().contains("?") ? "&uid=" : "?uid=") - .append(userInfo.getId()) - .append("&token=") - .append(userInfo.getToken()) - .append("&isZh=") - .append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); + htmlUrl.append(notifyFFGGGDJANEvent.getLink()).append(notifyFFGGGDJANEvent.getLink().contains("?") ? "&uid=" : "?uid=").append(userInfo.getId()).append("&token=").append(userInfo.getToken()).append("&isZh=").append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); if (!TextUtils.isEmpty(notifyFFGGGDJANEvent.getH5Type())) { if (TextUtils.equals(notifyFFGGGDJANEvent.getH5Type(), "1")) { Bundle bundle = new Bundle(); @@ -1412,9 +1407,7 @@ public class LiveGiftAnimPresenter { mGifGiftTipGroupBuyZuoji.setLayoutParams(params); } - String text = mTempGifGiftBean.getUserNiceName() + " " - + mContext.getString(R.string.live_send_buy_zuoji_1) - + " " + (mTempGifGiftBean.getCarName()); + String text = mTempGifGiftBean.getUserNiceName() + " " + mContext.getString(R.string.live_send_buy_zuoji_1) + " " + (mTempGifGiftBean.getCarName()); Spanned spanned = Html.fromHtml(text, null, new HtmlTagHandler("myfont")); mGifGiftTipBuyZuoji.setText(spanned); mGifGiftTipBuyZuoji.setSelected(false); @@ -1453,9 +1446,7 @@ public class LiveGiftAnimPresenter { mGifGiftTipGroupBuyLiangName.setLayoutParams(params); } - String text = mTempGifGiftBean.getUserNiceName() + " " - + mContext.getString(R.string.live_send_buy_liang_name_1) - + " " + mTempGifGiftBean.getLiangName(); + String text = mTempGifGiftBean.getUserNiceName() + " " + mContext.getString(R.string.live_send_buy_liang_name_1) + " " + mTempGifGiftBean.getLiangName(); Spanned spanned = Html.fromHtml(text, null, new HtmlTagHandler("myfont")); mGifGiftTipBuyLiangName.setText(spanned); mGifGiftTipBuyLiangName.setSelected(false); diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index f30d6121c..4a7e8bb6b 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -474,6 +474,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { livePushSwViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); } } + SWManager.get().setDrPkNumClarity(drPkbeans.size()); if(drPkbeans.size()==1){ mLiveAnchorViewHolder.closeEndPkBt(); } @@ -518,6 +519,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { dRjoinOtherRoom(u); //展示结束连麦按钮 mLiveAnchorViewHolder.showEndPkBt(); + mLiveAnchorViewHolder.setDrpkRoomId(CommonAppConfig.getInstance().getUid()); } /** @@ -1172,6 +1174,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { if (removeIndex != -1) { drPkbeans.remove(removeIndex); } + SWManager.get().setDrPkNumClarity(drPkbeans.size()); setDrPkUserInfoView(drPkbeans); } } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index 324b8db5a..26ed804b5 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -323,7 +323,6 @@ public class SocketSwClient { L.eSw("action3 == 2:" + u.getId()); L.eSw("收到对方同意多人PK邀请"); mListener.onLinkDRMicPkApplyOk(u); - SWManager.get().setDimensions(3);//退出直播间,将分别率设置为 VD_840x480 } else if (action3 == 6) {//开始Pk if (LiveRoomViewHolder.mHandler != null) { LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java index 6480eb369..546f26826 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java @@ -298,6 +298,11 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder { } + @Override + public void endLiveMic() { + + } + @Override public ViewGroup getSmallContainer() { diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 196b6ebc7..c3cf5e695 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -610,6 +610,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } + @Override + public void endLiveMic() { + + } + @Override public ViewGroup getSmallContainer() { return mSmallContainer; diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java index c8211ff9b..0f4e2b5e8 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -415,12 +415,14 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { } }); } - - private void endLiveMic() { + @Override + public void endLiveMic() { L.eSw("endLiveMic"); - swAuManager.setMicAn(false); - userJoinLinkMic = false; - MicStatusManager.getInstance().clear(); + if(swAuManager!=null){ + swAuManager.setMicAn(false); + userJoinLinkMic = false; + MicStatusManager.getInstance().clear(); + } } @Override @@ -882,17 +884,22 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { boolean isShow = false; + boolean isShowInvitation = false; + @Subscribe(threadMode = ThreadMode.MAIN) public void onUpdata(String str) { + if ("UsertoRY".equals(str)) { //todo 新增dis监听 - if (isShow) { + if (isShow||MicStatusManager.getInstance().getMicStatus()==MicStatusManager.MIC_TYPE_OPEN) { return; } isShow = true; DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.mic_tag), new DialogUitl.SimpleCallback2() { @Override public void onCancelClick() { + MicStatusManager.getInstance().setMicData(MicStatusManager.MIC_TYPE_DEFAULT, LiveActivity.mLiveUid); + userJoinLinkMic = false; isShow = false; } @@ -904,6 +911,10 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { }); } else if ("inviteMic".equals(str)) { + if (isShowInvitation||MicStatusManager.getInstance().getMicStatus()==MicStatusManager.MIC_TYPE_OPEN) { + return; + } + isShowInvitation = true; String content = "邀請您進行語音連麥"; String confirm = "接受"; String cancel = "拒絕"; @@ -912,24 +923,28 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { confirm = "accept"; cancel = "cancel"; } - DialogUitl.Builder builder = new DialogUitl.Builder(mContext).setContent(content).setTitle(mLiveBean.getUserNiceName()).setConfirmString(confirm).setCancelString(cancel).setView(R.layout.dialog_live_mic_invite).setClickCallback(new DialogUitl.SimpleCallback() { + DialogUitl.Builder builder = new DialogUitl.Builder(mContext).setContent(content).setTitle(mLiveBean.getUserNiceName()).setConfirmString(confirm).setCancelString(cancel).setView(R.layout.dialog_live_mic_invite).setClickCallback3(new DialogUitl.SimpleCallback3() { @Override - public void onConfirmClick(Dialog dialog, String content) { - String[] permissions; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - permissions = new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.RECORD_AUDIO}; - } else { - permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}; - } - LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { - @Override - public void run() { - // UsertoRY(); - //将自己设置成给主播,和主播连麦 - L.eSw("将自己设置成给主播,和主播连麦"); - joinLiveMic(); + public void onConfirmClick(Dialog dialog) { + String[] permissions; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + permissions = new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.RECORD_AUDIO}; + } else { + permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}; } - }); + LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { + @Override + public void run() { + L.eSw("将自己设置成给主播,和主播连麦"); + joinLiveMic(); + isShowInvitation = false; + } + }); + } + + @Override + public void onCancel() { + isShowInvitation = false; } }); builder.build().show(); @@ -948,6 +963,11 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { } } + public void endLiveMicUser(){ + endLiveMic(); + } + + @Subscribe(threadMode = ThreadMode.MAIN) public void onOpenDrawer(LiveAudienceEvent event) { if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO) { diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java index 5de3bf44a..6097d1038 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java @@ -114,6 +114,11 @@ public class LivePlayTxViewHolder extends LiveRoomPlayViewHolder implements ITXL } + @Override + public void endLiveMic() { + + } + @Override protected int getLayoutId() { return R.layout.view_live_play_tx; diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index a06dc20a3..36c8f80b1 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -130,6 +130,8 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public abstract void claerDrPkInfoView(); + public abstract void endLiveMic(); + public interface OnMicCallback { void onMikUpdate(); diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index cb714ade5..cf305a878 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -4058,6 +4058,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis mLiveGiftAnimPresenter.showAllServerNotifyFFGGGD(notifyFFGGGDJANEvent,showB); } + public void cancelAllAnim(){ + if(mLiveGiftAnimPresenter!=null){ + mLiveGiftAnimPresenter.releaseServiceNotice(); + } + } + + //全服通知 购买坐骑 public void showBuyZuojiMessage(LiveReceiveGiftBean bean) { if (mLiveGiftAnimPresenter == null) { diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index b8344bcca..79725eff5 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -957,6 +957,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (mLiveAudienceViewHolder != null) { mLiveAudienceViewHolder.removeCallbacks(); } + if(mLivePlayViewHolder!=null){ + mLivePlayViewHolder.stopPlay2(); + mLiveRoomViewHolder.cancelAllAnim(); + } //断开socket if (mSocketRyClient != null) { mSocketRyClient.disConnect(); @@ -988,9 +992,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveSwLinkMicPkPresenter.release(); mLiveSwLinkMicPkPresenter = null; } - if(mLivePlayViewHolder!=null){ - mLivePlayViewHolder.stopPlay2(); - } + if (mLiveEndViewHolder != null) { removeLiveEnd(); } @@ -1168,26 +1170,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe DialogUitl.showSimpleDialog(mContext, null, "連麥中,退出將斷開語音連麥!", false, new DialogUitl.SimpleCallback3() { @Override public void onConfirmClick(Dialog dialog) { - if (RCRTCEngine.getInstance().getRoom() == null || RCRTCEngine.getInstance().getRoom().getLocalUser() == null) { - return; - } - ToastUtil.show("下麥中,稍等....."); - RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { - - /** - * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 - * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 - */ - @Override - public void onKicked() { - - } - - @Override - public void onSuccess() { - Log.e("ry", "下麦成功"); - // 该用户切换为观众成功,可以以观众身份进行音视频 - //退出多人房间 + if(isSw){ + if(mLivePlayViewHolder!=null){ + mLivePlayViewHolder.endLiveMic(); HttpClient.getInstance().get("live.leaveDrLm", "live.leaveDrLm") .params("roomid", liveID) .execute(new HttpCallback() { @@ -1197,39 +1182,77 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } }); - //退出rtc播放 - RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { - @Override - public void onSuccess() { - Log.e("ry", "退出多人房间成功"); + if (isBackPressed) { + MicStatusManager.getInstance().clear(); + ((LiveAudienceActivity) mContext).closeRoom(); + } else { + EventBus.getDefault().post(new LiveRoomChangeEvent(bean, liveType, liveTypeVal)); + } + } + }else{ + if (RCRTCEngine.getInstance().getRoom() == null || RCRTCEngine.getInstance().getRoom().getLocalUser() == null) { + return; + } + ToastUtil.show("下麥中,稍等....."); + RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { - if (isBackPressed) { - MicStatusManager.getInstance().clear(); - ((LiveAudienceActivity) mContext).closeRoom(); - } else { - EventBus.getDefault().post(new LiveRoomChangeEvent(bean, liveType, liveTypeVal)); + /** + * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 + * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 + */ + @Override + public void onKicked() { + + } + + @Override + public void onSuccess() { + Log.e("ry", "下麦成功"); + // 该用户切换为观众成功,可以以观众身份进行音视频 + //退出多人房间 + HttpClient.getInstance().get("live.leaveDrLm", "live.leaveDrLm") + .params("roomid", liveID) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.e("ry", code + "退出多人"); + + } + }); + //退出rtc播放 + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "退出多人房间成功"); + + if (isBackPressed) { + MicStatusManager.getInstance().clear(); + ((LiveAudienceActivity) mContext).closeRoom(); + } else { + EventBus.getDefault().post(new LiveRoomChangeEvent(bean, liveType, liveTypeVal)); + } } - } - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", errorCode + "退出多人房间失敗"); + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", errorCode + "退出多人房间失敗"); - } - }); + } + }); - } + } - /** - * 当切换失败且不影响当前角色继续音视频时回调 - * @param errorCode 失败错误码 - */ - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", "下麦失败" + errorCode); + /** + * 当切换失败且不影响当前角色继续音视频时回调 + * @param errorCode 失败错误码 + */ + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "下麦失败" + errorCode); - } - }); + } + }); + } } @Override diff --git a/live/src/main/res/layout/item_anchor_mic_info.xml b/live/src/main/res/layout/item_anchor_mic_info.xml index 1c254dd47..fade3f7a3 100644 --- a/live/src/main/res/layout/item_anchor_mic_info.xml +++ b/live/src/main/res/layout/item_anchor_mic_info.xml @@ -19,7 +19,6 @@ android:gravity="center_vertical" android:orientation="horizontal"> - - @@ -65,8 +64,11 @@ android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:maxLines="1" + android:ellipsize="end" android:text="用户名称" android:textColor="#F6F7FB" + tools:textColor="@color/gray1" android:textSize="14sp" /> @@ -130,7 +132,7 @@ android:id="@+id/mic_btn" android:layout_width="wrap_content" android:layout_height="28dp" - android:layout_marginEnd="36dp" + android:layout_marginEnd="10dp" android:background="@drawable/bg_anchor_mic_info_btn_ok" android:text="同意" android:textColor="#FFFFFF" From 07f97fefdbfa4d0e249d8c588c4edf64cdd84318 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 31 May 2024 18:01:22 +0800 Subject: [PATCH 33/64] =?UTF-8?q?=E9=99=8D=E4=BD=8E=E5=A3=B0=E7=BD=91SDK?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=8C=E5=A4=84=E7=90=86=E9=9B=B7=E7=94=B5?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8=E9=97=AA=E9=80=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++-- .../agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index fbf0b6204..a388b398e 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ task clean(type: Delete) { ext { IS_PUBLISH_LOCAL=true LIB_VERSION="1.0.6" -// AGORA_RTC_SDK="io.agora.rtc:agora-special-full:4.1.1.28" + AGORA_RTC_SDK= 'io.agora.rtc:agora-special-full:4.1.1.28' // AGORA_RTC_SDK= "${rootProject.rootDir.absolutePath}/sdk" - AGORA_RTC_SDK="io.agora.rtc:full-sdk:4.2.6" +// AGORA_RTC_SDK="io.agora.rtc:full-sdk:4.2.6" } diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java index e7588a7e6..ff8495f5a 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java @@ -115,9 +115,10 @@ public class GLFrameBuffer { synchronized (EglBase.lock){ if(textureType == GLES11Ext.GL_TEXTURE_EXTERNAL_OES){ - drawer.drawOes(textureId, matrix, mWidth, mHeight, 0, 0, mWidth, mHeight); + drawer.drawOes(textureId,0, matrix, mWidth, mHeight, 0, 0, mWidth, mHeight); + }else{ - drawer.drawRgb(textureId, matrix, mWidth, mHeight, 0, 0, mWidth, mHeight); + drawer.drawRgb(textureId,0, matrix, mWidth, mHeight, 0, 0, mWidth, mHeight); } } From d3de01666c15be4dcc6dd8f87a6d54197cfa64be Mon Sep 17 00:00:00 2001 From: 18142669586 <1669783059@qq.com> Date: Fri, 31 May 2024 19:01:41 +0800 Subject: [PATCH 34/64] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=BB=91=E5=8A=A8=E9=BB=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/CustomDrawerPopupAdapter.java | 6 ++- .../common/http/main/MainNetManager.java | 45 ++++++++++--------- .../common/views/CustomDrawerPopupView.java | 6 ++- .../live/activity/LiveAudienceActivity.java | 6 ++- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/adapter/CustomDrawerPopupAdapter.java b/common/src/main/java/com/yunbao/common/adapter/CustomDrawerPopupAdapter.java index 2ab378200..013a58bd3 100644 --- a/common/src/main/java/com/yunbao/common/adapter/CustomDrawerPopupAdapter.java +++ b/common/src/main/java/com/yunbao/common/adapter/CustomDrawerPopupAdapter.java @@ -40,12 +40,15 @@ public class CustomDrawerPopupAdapter extends RecyclerView.Adapter { private final int RIGHTS_INTERESTS = 4; private final int RECOMMEND = 5; private String liveId; + private boolean mIs_shengwang; + private List list = new ArrayList<>(); private List infoModels = new ArrayList<>(); - public CustomDrawerPopupAdapter(Context mContext) { + public CustomDrawerPopupAdapter(Context mContext,boolean mIs_shengwang) { this.mContext = mContext; + this.mIs_shengwang = mIs_shengwang; } @@ -114,6 +117,7 @@ public class CustomDrawerPopupAdapter extends RecyclerView.Adapter { map.put("num", "9"); map.put("live_recommend", "sidebar"); map.put("refresh", "1"); + map.put(" is_shengwang", mIs_shengwang?"1":"0"); //推荐位 MainNetManager.get((Activity) mContext) .anchorRecommend(map, new com.yunbao.common.http.base.HttpCallback() { diff --git a/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java b/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java index 38731b326..00dd5a6bc 100644 --- a/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java @@ -96,27 +96,27 @@ public class MainNetManager { }).isDisposed(); } - /** - * 猜你喜欢 - * - * @param num 请求数量 - * @return - */ - public void anchorRecommend(String num, HttpCallback httpCallback) { - API.get().pdLiveApi(mContext).anchorRecommend(num) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(anchorRecommendModelResponseModel -> { - if (httpCallback != null) { - AnchorRecommendModel model = anchorRecommendModelResponseModel.getData().getInfo(); - httpCallback.onSuccess(model); - } - }, throwable -> { - if (httpCallback != null) { - httpCallback.onError(throwable.getMessage()); - } - }).isDisposed(); - } +// /** +// * 猜你喜欢 +// * +// * @param num 请求数量 +// * @return +// */ +// public void anchorRecommend(String num, String is_shengwang,HttpCallback httpCallback) { +// API.get().pdLiveApi(mContext).anchorRecommend(num,is_shengwang) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(anchorRecommendModelResponseModel -> { +// if (httpCallback != null) { +// AnchorRecommendModel model = anchorRecommendModelResponseModel.getData().getInfo(); +// httpCallback.onSuccess(model); +// } +// }, throwable -> { +// if (httpCallback != null) { +// httpCallback.onError(throwable.getMessage()); +// } +// }).isDisposed(); +// } public void anchorRecommend(Map map, HttpCallback httpCallback) { API.get().pdLiveApi(mContext).anchorRecommend(map) @@ -140,11 +140,12 @@ public class MainNetManager { * @param num 请求数量 * @return */ - public void anchorRecommendType(String num, HttpCallback httpCallback) { + public void anchorRecommendType(String num, String is_shengwang,HttpCallback httpCallback) { Map map = new HashMap<>(); map.put("num", num); map.put("live_recommend", "slide"); map.put("type", "1"); + map.put(" is_shengwang", is_shengwang); API.get().pdLiveApi(mContext).anchorRecommend(map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) diff --git a/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java b/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java index 9ad0e8686..94c0bbb84 100644 --- a/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java +++ b/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java @@ -29,6 +29,7 @@ import java.util.List; public class CustomDrawerPopupView extends DrawerPopupView { private Context mContext; + private boolean mIs_shengwang; private RecyclerView drawerList; private CustomDrawerPopupAdapter adapter; @@ -45,9 +46,10 @@ public class CustomDrawerPopupView extends DrawerPopupView { return this; } - public CustomDrawerPopupView(@NonNull Context context) { + public CustomDrawerPopupView(@NonNull Context context, boolean is_shengwang) { super(context); mContext = context; + mIs_shengwang = is_shengwang; } @Override @@ -72,7 +74,7 @@ public class CustomDrawerPopupView extends DrawerPopupView { private void initView() { drawerList = findViewById(R.id.drawerList); - adapter = new CustomDrawerPopupAdapter(mContext); + adapter = new CustomDrawerPopupAdapter(mContext,mIs_shengwang); adapter.setList(list).setLiveId(liveId); drawerList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); drawerList.setAdapter(adapter); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 0e67649f4..432b2ec9a 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -316,7 +316,7 @@ public class LiveAudienceActivity extends LiveActivity { } }); } else { - MainNetManager.get(mContext).anchorRecommendType("30", new com.yunbao.common.http.base.HttpCallback() { + MainNetManager.get(mContext).anchorRecommendType("30",isSw?"1":"0", new com.yunbao.common.http.base.HttpCallback() { @Override public void onSuccess(AnchorRecommendModel data) { if (TextUtils.equals(data.getList().get(0).getUid(), mLiveBean.getUid())) { @@ -898,7 +898,7 @@ public class LiveAudienceActivity extends LiveActivity { if (userIndex != -1) { list.remove(userIndex); } - CustomDrawerPopupView customDrawerPopupView = new CustomDrawerPopupView(mContext).setList(list).setLiveId(mLiveBean.getUid()); + CustomDrawerPopupView customDrawerPopupView = new CustomDrawerPopupView(mContext,isSw).setList(list).setLiveId(mLiveBean.getUid()); customDrawerPopupView.setCallBack(new CustomDrawerPopupView.CustomDrawerPopupCallBack() { @Override @@ -1577,6 +1577,8 @@ public class LiveAudienceActivity extends LiveActivity { Map map = new HashMap<>(); map.put("num", "9"); map.put("live_recommend", "sidebar"); + map.put(" is_shengwang", isSw?"1":"0"); + //推荐位 MainNetManager.get(mContext).anchorRecommend(map, new com.yunbao.common.http.base.HttpCallback() { @Override From 6496440e5d6430f253420fa6594ec9dca73e45d0 Mon Sep 17 00:00:00 2001 From: 18142669586 <1669783059@qq.com> Date: Fri, 31 May 2024 20:00:04 +0800 Subject: [PATCH 35/64] =?UTF-8?q?=E4=BF=AE=E6=94=B99=E5=8F=91=E4=B8=A4?= =?UTF-8?q?=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presenter/LiveSwLinkMicPkPresenter.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 4a7e8bb6b..c0de23c10 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -352,25 +352,24 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { public void onSuccess(int code, String msg, String[] info) { if (code == 0) { JSONObject datas = JSONObject.parseObject(info[0]); - - SocketSendBean seed_msg = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); - seed_msg.create(); - String pkUid = datas.getString("pkuid"); - Log.i("seed", seed_msg.mResult.toString()); +// SocketSendBean seed_msg = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); +// seed_msg.create(); +// String pkUid = datas.getString("pkuid"); +// Log.i("seed", seed_msg.mResult.toString()); Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid")); - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - - } - }); - } - }); +// HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { +// @Override +// public void onSuccess(int code, String msg, String[] info) { +// HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { +// @Override +// public void onSuccess(int code, String msg, String[] info) { +// +// } +// }); +// } +// }); } } From efa698ebfa755bea5050d18e008f3e98d33bc1c6 Mon Sep 17 00:00:00 2001 From: 18142669586 <1669783059@qq.com> Date: Fri, 31 May 2024 20:55:09 +0800 Subject: [PATCH 36/64] 1 --- .../presenter/LiveSwLinkMicPkPresenter.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index c0de23c10..5a95abddb 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -352,25 +352,27 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { public void onSuccess(int code, String msg, String[] info) { if (code == 0) { JSONObject datas = JSONObject.parseObject(info[0]); -// SocketSendBean seed_msg = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); -// seed_msg.create(); -// String pkUid = datas.getString("pkuid"); -// Log.i("seed", seed_msg.mResult.toString()); + if (!datas.getString("pkuid").equals("0")) { + SocketSendBean seed_msg = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); + seed_msg.create(); + String pkUid = datas.getString("pkuid"); + Log.i("seed", seed_msg.mResult.toString()); - Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid")); + Log.e("ry1", datas.getString("win_uid") + "VVVVVV" + datas.getString("pkuid")); -// HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { -// @Override -// public void onSuccess(int code, String msg, String[] info) { -// HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { -// @Override -// public void onSuccess(int code, String msg, String[] info) { -// -// } -// }); -// } -// }); + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + pkUid).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + HttpClient.getInstance().post("Tx.sendmsgzs2", "Tx.sendmsgzs2").params("GroupId", "g" + CommonAppConfig.getInstance().getUid()).params("jsonstr", seed_msg.mResult.toString()).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + } + }); + } + }); + + } } } }); @@ -474,7 +476,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } SWManager.get().setDrPkNumClarity(drPkbeans.size()); - if(drPkbeans.size()==1){ + if (drPkbeans.size() == 1) { mLiveAnchorViewHolder.closeEndPkBt(); } } From c4d378daba20879354cc8e8e9cbd7051e1479106 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Fri, 31 May 2024 20:59:16 +0800 Subject: [PATCH 37/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/manager/RandomPkManager.java | 2 +- .../live/activity/LiveSwAnchorActivity.java | 5 +- .../presenter/LiveSwLinkMicPkPresenter.java | 162 +- .../yunbao/live/socket/SocketSwClient.java | 9 +- .../live/views/LivePlaySwViewHolder.java | 48 +- .../live/views/LivePushSwViewHolder.java | 2 +- .../yunbao/live/views/LiveRoomViewHolder.java | 1662 ++++++++--------- .../live/views/PortraitLiveManager.java | 53 +- .../src/main/res/layout/view_live_play_sw.xml | 4 +- 9 files changed, 1002 insertions(+), 945 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java b/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java index ebb586b0a..e0bd21378 100644 --- a/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java +++ b/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java @@ -343,7 +343,7 @@ public class RandomPkManager { @Override public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh()?"抱歉!出錯了!":"i \\'m sorry! An error occurred"); + //ToastUtil.show(WordUtil.isNewZh()?"抱歉!出錯了!":"i \\'m sorry! An error occurred"); } }); } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index b958b1432..b9e1fe394 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -165,6 +165,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl private boolean mPaused; String mBeautySdkType; public static int isDRPK = 0; + public static int DRPKing = 0; // 0 多人PK前 1 多人PK中 2多人PK后 public static boolean PKing = false; public static int pk_nub; public static int backIndex = 0;//0=未判断,1=已判断 @@ -405,6 +406,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl LiveSwLinkMicPkPresenter.mApplyUid = CommonAppConfig.getInstance().getUid(); btn_start_dr_pk.setVisibility(View.VISIBLE); // dr_pk_view.setVisibility(View.VISIBLE); + L.eSw("ac2222222222222222222"); final SocketSendBean msg1 = new SocketSendBean() .param("_method_", SOCKET_LIVE_DRPK) .param("action", 9) @@ -872,6 +874,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl MicUserManager.get().removeAllMicUserList(); PKing = false; isDRPK = 0; + DRPKing = 0; endLive(); RandomPkManager.getInstance().release(); } @@ -1345,7 +1348,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl @Override public void onError(Message message, RongIMClient.ErrorCode errorCode) { Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); + //ToastUtil.show(errorCode.code + ":" + errorCode.msg); } }); } else { diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 5a95abddb..427d5384e 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -3,6 +3,7 @@ package com.yunbao.live.presenter; import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; +import static com.yunbao.live.activity.LiveSwAnchorActivity.DRPKing; import static com.yunbao.live.activity.LiveSwAnchorActivity.PKing; import static com.yunbao.live.activity.LiveSwAnchorActivity.isDRPK; import static com.yunbao.live.activity.LiveSwAnchorActivity.mLiveAnchorViewHolder; @@ -158,6 +159,8 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { private List drPkbeans = new ArrayList<>(); + private JSONArray pkScores; //PK分数 + public LiveSwLinkMicPkPresenter setDRInitiator(boolean DRInitiator) { this.DRInitiator = DRInitiator; return this; @@ -475,6 +478,98 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { livePushSwViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); } } + if (DRPKing == 1) { + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + setMyDrPkDetailsView(); + for (int j = 0; j < drPkbeans.size(); j++) { + if (j == 0) { + L.eSw("j == 0:" + j); + //设置多人PK数据 + if (detailsView2 != null) { + livePushSwViewHolder.dr2_preview.removeView(detailsView2); + } + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(String.valueOf(drPkbeans.get(0).getId())); + textPkName2.setText(drPkbeans.get(0).getUser_nicename()); + livePushSwViewHolder.dr2_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.GONE); + linearGrade2.setVisibility(View.GONE); + } else if (j == 1) { + L.eSw("j == 1:" + j); + if (detailsView4 != null) { + livePushSwViewHolder.dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(String.valueOf(drPkbeans.get(1).getId())); + textPkName4.setText(drPkbeans.get(1).getUser_nicename()); + livePushSwViewHolder.dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + } else if (j == 2) { + L.eSw("j == 2:" + j); + + if (detailsView4 != null) { + livePushSwViewHolder.dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(String.valueOf(drPkbeans.get(2).getId())); + textPkName4.setText(drPkbeans.get(2).getUser_nicename()); + livePushSwViewHolder.dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + + if (detailsView3 != null) { + livePushSwViewHolder.dr3_preview.removeView(detailsView3); + } + detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); + linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); + textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); + imageGrade3 = detailsView3.findViewById(R.id.image_grade3); + textGrade3 = detailsView3.findViewById(R.id.text_grade3); + imageGrade3.setTag(String.valueOf(drPkbeans.get(1).getId())); + textPkName3.setText(drPkbeans.get(1).getUser_nicename()); + livePushSwViewHolder.dr3_preview.addView(detailsView3); + detailsLinearLayout3.setVisibility(View.GONE); + linearGrade3.setVisibility(View.GONE); + + + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); + } + } + int removeUid = 0; + for (int k = 0; k < pkScores.size(); k++) { + JSONObject score = pkScores.getJSONObject(k); + String userID = score.getString("id"); + if(userID.equals(uid)){ + removeUid = k; + } + } + pkScores.remove(removeUid); + upDataPkScore(pkScores,"-1",0); + } + }, 1000); + } + + + SWManager.get().setDrPkNumClarity(drPkbeans.size()); if (drPkbeans.size() == 1) { mLiveAnchorViewHolder.closeEndPkBt(); @@ -520,7 +615,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { dRjoinOtherRoom(u); //展示结束连麦按钮 mLiveAnchorViewHolder.showEndPkBt(); - mLiveAnchorViewHolder.setDrpkRoomId(CommonAppConfig.getInstance().getUid()); } /** @@ -578,6 +672,9 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { /*---------------------------------------------------------------- */ final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 2) //回复PK申请 2 .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", bean.getId()).param("uid", CommonAppConfig.getInstance().getUid()).param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + if (bean.isRandomPk()) { + msg1.param("random_pk", "1"); + } if (RandomPkManager.getInstance().isRankModel()) { L.eSw("排位赛"); msg1.param("is_ladders", "https://downs.yaoulive.com/rank_top_box.png"); @@ -711,6 +808,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); Log.e("ry", "退出多人OKKK" + inputStreamList.size()); isDRPK = 0; + DRPKing = 1; runOnUiThread(new Runnable() { @Override public void run() { @@ -1159,6 +1257,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { //多人PK接受申请画 加入副房间 public void dRjoinOtherRoom(UserBean u) { + L.eSw("dRjoinOtherRoom UserBeanUserBeanUserBeanUserBeanUserBeanUserBeanUserBeanUserBean "); setMyDrPkDetailsView(); HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { @Override @@ -1601,11 +1700,13 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { * 更新Pk分数 */ public void upDataPkScore(JSONArray pkScores, String uid, int time) { + this.pkScores = pkScores; + L.eSw("更新Pk分数 upDataPkScore time:" + time + " " + pkScores); String userID1 = (String) imageGrade1.getTag(); String userID2 = (String) imageGrade2.getTag(); String userID4 = (String) imageGrade4.getTag(); - if (livePushSwViewHolder.timeTitle.getVisibility() == View.GONE) { + if (livePushSwViewHolder.timeTitle.getVisibility() == View.GONE &&!"-1".equals(uid)) { mHandler.removeMessages(WHAT_PK_TIME2); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) livePushSwViewHolder.timeTitle.getLayoutParams(); layoutParams.topMargin = DpUtil.dp2px(123); @@ -1699,7 +1800,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } } - } else { + } else if(pkScoreSize == 4){ String userID3 = (String) imageGrade3.getTag(); detailsLinearLayout1.setVisibility(View.VISIBLE); @@ -1803,6 +1904,61 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } + }else{ + detailsLinearLayout1.setVisibility(View.VISIBLE); + detailsLinearLayout2.setVisibility(View.VISIBLE); + + linearGrade1.setVisibility(View.VISIBLE); + linearGrade2.setVisibility(View.VISIBLE); + //拿到原始数据 + for (int i = 0; i < pkScores.size(); i++) { + JSONObject score = pkScores.getJSONObject(i); + String userID = score.getString("id"); + long userScore = score.getLong("score"); + if (TextUtils.equals(userID, userID1)) { + textGrade1.setText(String.valueOf(userScore)); + if (!score.containsKey("paiming")) { + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + } else { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + break; + case 2: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade1); + break; + case 3: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade1); + break; + case 4: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade1); + break; + } + } + } else if (TextUtils.equals(userID, userID2)) { + textGrade2.setText(String.valueOf(userScore)); + if (!score.containsKey("paiming")) { + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + } else { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + break; + case 2: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade2); + break; + case 3: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade2); + break; + case 4: + ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade2); + break; + } + } + } + } } } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index 26ed804b5..c1512f98d 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -3,6 +3,7 @@ package com.yunbao.live.socket; import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; import static com.yunbao.common.Constants.SOCKET_LIVE_MSG_TO_USER; import static com.yunbao.live.activity.LiveSwAnchorActivity.isDRPK; +import static com.yunbao.live.activity.LiveSwAnchorActivity.DRPKing; import static com.yunbao.live.views.LiveRoomViewHolder.getIsHot; import android.app.Activity; @@ -314,14 +315,12 @@ public class SocketSwClient { mListener.onLinkDRMicPkApply(u); } else if (action3 == 2) { //收到对方同意多人PK邀请 - if ("0".equals(map.getString("msgtype"))) { - return; - } UserBean u = new UserBean(); // u.setUserNiceName(map.getString("uname")); u.setId(map.getString("pkuid")); L.eSw("action3 == 2:" + u.getId()); L.eSw("收到对方同意多人PK邀请"); + DRPKing = 0; mListener.onLinkDRMicPkApplyOk(u); } else if (action3 == 6) {//开始Pk if (LiveRoomViewHolder.mHandler != null) { @@ -333,6 +332,7 @@ public class SocketSwClient { // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW)); } + DRPKing = 1; } else if (action3 == 5) {//结束PK // endDRGif(); LiveRoomViewHolder.d_pk_view.setVisibility(View.GONE); @@ -353,6 +353,7 @@ public class SocketSwClient { LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); }*/ isDRPK = 1; + DRPKing = 0; if (livePushSwViewHolder == null) { if ("4".equals(map.getString("msgtype"))) { return; @@ -1355,7 +1356,7 @@ public class SocketSwClient { .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()) .param("msgtype", 2).param("uid", CommonAppConfig.getInstance().getUid()) .param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) - .param("is_auto ", "1") + .param("is_auto", "1") .param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()) .param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); diff --git a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java index 0f4e2b5e8..8ce62f8a6 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlaySwViewHolder.java @@ -8,9 +8,11 @@ import android.content.Context; import android.graphics.Color; import android.media.AudioManager; import android.os.Build; +import android.os.Handler; import android.text.TextUtils; import android.util.Log; import android.view.Gravity; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; @@ -224,7 +226,7 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { IMCenter.getInstance().deleteRemoteMessages(Conversation.ConversationType.PRIVATE, message.getTargetId(), new Message[]{message}, null); IMCenter.getInstance().clearMessagesUnreadStatus(Conversation.ConversationType.PRIVATE, message.getTargetId(), null); - MicedUserManager.get().removeMiscUser(CommonAppConfig.getInstance().getUid()); + MicedUserManager.get().removeMiscUser(CommonAppConfig.getInstance().getUid()); } @Override @@ -238,17 +240,17 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { } }); //进入主播房间 - swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken,liveUid, SWAuManager.getChannelName(liveUid)); + swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, liveUid, SWAuManager.getChannelName(liveUid)); } @Override public void removeLiveUid(String uid) { //先结束PK - if(drMicUserList!=null){ + if (drMicUserList != null) { List tempList = new ArrayList<>(); int index = -1; - for (int i = 0; i = Build.VERSION_CODES.TIRAMISU) { - permissions = new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.RECORD_AUDIO}; - } else { - permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}; + String[] permissions; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + permissions = new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.RECORD_AUDIO}; + } else { + permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}; + } + LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { + @Override + public void run() { + L.eSw("将自己设置成给主播,和主播连麦"); + joinLiveMic(); + isShowInvitation = false; } - LiveAudienceActivity.mProcessResultUtil.requestPermissions(permissions, new Runnable() { - @Override - public void run() { - L.eSw("将自己设置成给主播,和主播连麦"); - joinLiveMic(); - isShowInvitation = false; - } - }); + }); } @Override @@ -963,7 +967,7 @@ public class LivePlaySwViewHolder extends LiveRoomPlayViewHolder { } } - public void endLiveMicUser(){ + public void endLiveMicUser() { endLiveMic(); } diff --git a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java index 08a8dde82..03924503e 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -197,7 +197,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX btn_close.setVisibility(View.GONE);//隐藏连麦按钮 EventBus.getDefault().post(new AnchorInfoEvent(true, "", "", "")); closeButtonGone(); - + L.eSw("ac333333333333333333333"); SocketSendBean seed_msg = new SocketSendBean().param("_method_", Constants.SOCKET_LINK_MIC_PK).param("action", 9).param("msgtype", 10).param("win_uid", datas.getString("win_uid")).param("uid", CommonAppConfig.getInstance().getUid()); seed_msg.create(); Log.i("seed", seed_msg.mResult.toString()); diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index cf305a878..77b177e03 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -441,14 +441,12 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if ("svga_new_user_gif".equals(str)) { if (fastMsgRecyclerView == null) return; - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) - fastMsgRecyclerView.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) fastMsgRecyclerView.getLayoutParams(); params1.rightMargin = DeviceUtils.getScreenWidth((Activity) mContext) / 3; fastMsgRecyclerView.setLayoutParams(params1); } else if ("stop_svga_new_user_gif".equals(str)) { if (fastMsgRecyclerView == null) return; - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) - fastMsgRecyclerView.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) fastMsgRecyclerView.getLayoutParams(); params1.rightMargin = 0; fastMsgRecyclerView.setLayoutParams(params1); } else if ("showBanner".equals(str)) { @@ -548,9 +546,9 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } - public LiveRoomViewHolder(boolean isRys, int forActivity, Context context, ViewGroup parentView, GifImageView gifImageView, SVGAImageView svgaImageView, ViewGroup liveGiftPrizePoolContainer, WindowManager windowManager,boolean isSw) { + public LiveRoomViewHolder(boolean isRys, int forActivity, Context context, ViewGroup parentView, GifImageView gifImageView, SVGAImageView svgaImageView, ViewGroup liveGiftPrizePoolContainer, WindowManager windowManager, boolean isSw) { super(context, parentView); - this.isSw =isSw; + this.isSw = isSw; Contexts = context; this.forAct = forActivity; // this.isRy = isRys; @@ -661,8 +659,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis bean.setContent(model.getMsg()); bean.setUserNiceName(model.getUserName()); - bean.setAtUserName(model.getXydgiftname()) - .setLevel(model.getLevel()); + bean.setAtUserName(model.getXydgiftname()).setLevel(model.getLevel()); bean.setType(LiveChatBean.XYD_COMPLETE); mLiveChatAdapter.insertItem(bean); xydCompleteModels.add(model); @@ -692,9 +689,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public void setSudName(String sudName, SudGameDateModel sudGameDateModel) { sud_text_name = (TextView) findViewById(R.id.sud_text_name); sud_layout_name = (LinearLayout) findViewById(R.id.sud_layout_name); - sud_text_name.setText(WordUtil.isNewZh() ? - String.format("主播创建了【%s】房间,快来与主播同玩~", sudName) : - String.format("The anchor has created a 【%s】 room. Come and play with the anchor~", sudName)); + sud_text_name.setText(WordUtil.isNewZh() ? String.format("主播创建了【%s】房间,快来与主播同玩~", sudName) : String.format("The anchor has created a 【%s】 room. Come and play with the anchor~", sudName)); sud_layout_name.setVisibility(View.VISIBLE); ViewClicksAntiShake.clicksAntiShake(sud_layout_name, new ViewClicksAntiShake.ViewClicksCallBack() { @Override @@ -875,10 +870,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis dr_pk_end_gif.setVisibility(View.VISIBLE); visibility = false; RequestOptions options = new RequestOptions().skipMemoryCache(true);//配置 - Glide.with(mContext).asGif() - .apply(options)//应用配置 - .load(WordUtil.isNewZh() ? R.mipmap.drpkend : R.mipmap.drpkend_en) - .listener(new RequestListener() { + Glide.with(mContext).asGif().apply(options)//应用配置 + .load(WordUtil.isNewZh() ? R.mipmap.drpkend : R.mipmap.drpkend_en).listener(new RequestListener() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { return false; @@ -890,12 +883,10 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis resource.setLoopCount(1);//只播放一次 } //发送延时消息,通知动画结束 - mHandler.sendEmptyMessageDelayed(1, - 3000); + mHandler.sendEmptyMessageDelayed(1, 3000); return false; } - }) - .into(dr_pk_end_gif); + }).into(dr_pk_end_gif); } @@ -1310,8 +1301,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis chat_view = (RelativeLayout) findViewById(R.id.chat_view); int topMargin = mScreenWdith * 720 / 960 + 210; - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) - chat_view.getLayoutParams(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) chat_view.getLayoutParams(); params.topMargin = topMargin; chat_view.setLayoutParams(params); @@ -1321,8 +1311,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis msgLayout.setLayoutParams(msgLayoutLayoutParams); voteManager.setMarginPosition(topMargin + DpUtil.dp2px(50)); - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) - mChatRecyclerView.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) mChatRecyclerView.getLayoutParams(); params1.topMargin = DpUtil.dp2px(65); mChatRecyclerView.setLayoutParams(params1); @@ -1350,8 +1339,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ((LiveActivity) mContext).sendChatMessage("Hi~", null, null); } else if (bean.getType() == -5) { String url = CommonAppConfig.HOST + "/index.php?g=Appapi&m=Turntable&a=tricky"; - url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" - + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); Log.i("tag", url); Bundle bundle1 = new Bundle(); bundle1.putString("url", url); @@ -1470,18 +1458,17 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis liveAudienceActivity.pausePlay(); if (code == 1008) {//余额不足 liveAudienceActivity.setCoinNotEnough(true); - DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.live_coin_not_enough), false, - new DialogUitl.SimpleCallback2() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - RouteUtil.forwardMyCoin(mContext); - } + DialogUitl.showSimpleDialog(mContext, mContext.getString(R.string.live_coin_not_enough), false, new DialogUitl.SimpleCallback2() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + RouteUtil.forwardMyCoin(mContext); + } - @Override - public void onCancelClick() { - liveAudienceActivity.exitLiveRoom(); - } - }); + @Override + public void onCancelClick() { + liveAudienceActivity.exitLiveRoom(); + } + }); } } } @@ -1513,11 +1500,9 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis // ft_hot_add = (FrameLayout) findViewById(R.id.ft_hot_add); // img_hot_gif = (ImageView) findViewById(R.id.img_hot_gif); findViewById(R.id.ft_hot_add).setOnClickListener(this); - ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.open_sidebar), () -> Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.SIDEBAR))); + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.open_sidebar), () -> Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SIDEBAR))); //点击心愿单 - ViewClicksAntiShake.clicksAntiShake(wishListLayout, () -> Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.WISH_LIST))); + ViewClicksAntiShake.clicksAntiShake(wishListLayout, () -> Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.WISH_LIST))); mBanner1.setOutlineProvider(new ViewOutlineProvider() { @Override @@ -1644,7 +1629,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis private Runnable timeRunnable = new Runnable() { @Override public void run() { - Log.i("红包", "run: 红包倒计时 "+redTimeCountdown); + Log.i("红包", "run: 红包倒计时 " + redTimeCountdown); if (redTimeCountdown > 1) { timeHandler.postDelayed(timeRunnable, 1000); redPacketCountdown.setText(String.format(mContext.getString(R.string.red_packet_countdown), TimeUtils.getTime(redTimeCountdown))); @@ -1653,9 +1638,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis redTimeCountdown = 0; timeHandler.removeCallbacks(timeRunnable); StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append(mRedPacketModel.getRedPacketRemain()) - .append("/") - .append(mRedPacketModel.getRedPacketQuantity()); + stringBuffer.append(mRedPacketModel.getRedPacketRemain()).append("/").append(mRedPacketModel.getRedPacketQuantity()); redSchedule.setText(stringBuffer.toString()); openRedPacket.setText(String.format(mContext.getString(R.string.open_red_packet), mRedPacketModel.getRedPacketCount() + "")); redPacketCountdown.setVisibility(View.GONE); @@ -1670,24 +1653,23 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis private Runnable anchorTimeRunnable = new Runnable() { @Override public void run() { - Log.i("红包", "anchorTimeRunnable run: "+mCountdown); + Log.i("红包", "anchorTimeRunnable run: " + mCountdown); if (mCountdown > 0) { mCountdown = mCountdown - 1; anchorTimeHandler.postDelayed(anchorTimeRunnable, 1000); Log.e("主播倒计时", String.format(mContext.getString(R.string.red_packet_countdown), TimeUtils.getTime(mCountdown))); if (mCountdown == 180) { - LiveNetManager.get(mContext). - startRedPacketRobot(mLiveUid, mStream, mRedPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(String data) { + LiveNetManager.get(mContext).startRedPacketRobot(mLiveUid, mStream, mRedPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(String data) { - } + } - @Override - public void onError(String error) { - ToastUtil.show(error); - } - }); + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); } } else { redPacket.setVisibility(View.GONE); @@ -1695,24 +1677,24 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) dragonImmediateParticipation.getLayoutParams(); layoutParams.topMargin = DpUtil.dp2px(110); dragonImmediateParticipation.setLayoutParams(layoutParams); - } if (dragonImmediateParticipationTime.getVisibility() == View.VISIBLE) { + } + if (dragonImmediateParticipationTime.getVisibility() == View.VISIBLE) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) dragonImmediateParticipation.getLayoutParams(); layoutParams.topMargin = DpUtil.dp2px(110); dragonImmediateParticipationTime.setLayoutParams(layoutParams); } anchorTimeHandler.removeCallbacks(anchorTimeRunnable); - LiveNetManager.get(mContext). - endRedPacket(mLiveUid, mRedPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(String data) { + LiveNetManager.get(mContext).endRedPacket(mLiveUid, mRedPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(String data) { - } + } - @Override - public void onError(String error) { - ToastUtil.show(error); - } - }); + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); } } }; @@ -1731,7 +1713,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis layoutParams.topMargin = DpUtil.dp2px(190); dragonImmediateParticipation.setLayoutParams(layoutParams); } - if (dragonImmediateParticipationTime.getVisibility() == View.VISIBLE&&mContext instanceof LiveRyAnchorActivity) { + if (dragonImmediateParticipationTime.getVisibility() == View.VISIBLE && mContext instanceof LiveRyAnchorActivity) { RelativeLayout.LayoutParams layoutParamsredPacket = (RelativeLayout.LayoutParams) redPacket.getLayoutParams(); layoutParamsredPacket.topMargin = DpUtil.dp2px(110); redPacket.setLayoutParams(layoutParamsredPacket); @@ -1740,7 +1722,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis layoutParams.topMargin = DpUtil.dp2px(190); dragonImmediateParticipationTime.setLayoutParams(layoutParams); } - if (dragonImmediateParticipationTime.getVisibility() == View.GONE&&mContext instanceof LiveRyAnchorActivity){ + if (dragonImmediateParticipationTime.getVisibility() == View.GONE && mContext instanceof LiveRyAnchorActivity) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) redPacket.getLayoutParams(); layoutParams.topMargin = DpUtil.dp2px(110); redPacket.setLayoutParams(layoutParams); @@ -1757,9 +1739,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis redPacketQueue.setVisibility(View.VISIBLE); redPacketCountdown.setVisibility(View.GONE); StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append(mRedPacketModel.getRedPacketRemain()) - .append("/") - .append(mRedPacketModel.getRedPacketQuantity()); + stringBuffer.append(mRedPacketModel.getRedPacketRemain()).append("/").append(mRedPacketModel.getRedPacketQuantity()); redSchedule.setText(stringBuffer.toString()); openRedPacket.setText(String.format(mContext.getString(R.string.open_red_packet), mRedPacketModel.getRedPacketCount() + "")); } @@ -1776,37 +1756,28 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public void onViewClicks() { if (!(mContext instanceof LiveSwAnchorActivity)) { - LiveNetManager.get(mContext) - .redPacketInfo(mLiveUid, redPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(RedPacketInfoModel data) { - if (TextUtils.equals(data.getReceiveStatus(), "0")) { - redTimeCountdown = redTimeCountdown - 1; - new XPopup.Builder(mContext) - .asCustom(new ReceiveRendPacketPopup(mContext, redTimeCountdown, mLiveUid, mStream, redPacketModel.getRedPacketId(), data, false, isFans)) - .show(); - } else if (TextUtils.equals(data.getReceiveStatus(), "1")) { - new XPopup.Builder(mContext) - .asCustom(new ResultRendPacketPopup(mContext, true, data.setRedPacketId(redPacketModel.getRedPacketId()), false)) - .show(); - } else { - if (data.getGiftModels().size() > 0) { - new XPopup.Builder(mContext) - .asCustom(new ResultRendPacketPopup(mContext, false, data.setRedPacketId(redPacketModel.getRedPacketId()), false)) - .show(); - } else { - new XPopup.Builder(mContext) - .asCustom(new ResultRendPacketPopup(mContext, true, data.setRedPacketId(redPacketModel.getRedPacketId()), false)) - .show(); - } - } + LiveNetManager.get(mContext).redPacketInfo(mLiveUid, redPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(RedPacketInfoModel data) { + if (TextUtils.equals(data.getReceiveStatus(), "0")) { + redTimeCountdown = redTimeCountdown - 1; + new XPopup.Builder(mContext).asCustom(new ReceiveRendPacketPopup(mContext, redTimeCountdown, mLiveUid, mStream, redPacketModel.getRedPacketId(), data, false, isFans)).show(); + } else if (TextUtils.equals(data.getReceiveStatus(), "1")) { + new XPopup.Builder(mContext).asCustom(new ResultRendPacketPopup(mContext, true, data.setRedPacketId(redPacketModel.getRedPacketId()), false)).show(); + } else { + if (data.getGiftModels().size() > 0) { + new XPopup.Builder(mContext).asCustom(new ResultRendPacketPopup(mContext, false, data.setRedPacketId(redPacketModel.getRedPacketId()), false)).show(); + } else { + new XPopup.Builder(mContext).asCustom(new ResultRendPacketPopup(mContext, true, data.setRedPacketId(redPacketModel.getRedPacketId()), false)).show(); } + } + } - @Override - public void onError(String error) { - ToastUtil.show(error); - } - }); + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); } @@ -1829,9 +1800,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } public void setRedPacketInfoModel(RedPacketInfoModel redPacket) { - new XPopup.Builder(mContext) - .asCustom(new ReceiveRendPacketPopup(mContext, 0, mLiveUid, mStream, redPacket.getRedPacketId(), redPacket, true, isFans)) - .show(); + new XPopup.Builder(mContext).asCustom(new ReceiveRendPacketPopup(mContext, 0, mLiveUid, mStream, redPacket.getRedPacketId(), redPacket, true, isFans)).show(); } /** @@ -1880,19 +1849,18 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis * 获取当前直播间星级 */ private void initStarChallengeStatus() { - LiveNetManager.get(mContext) - .getStarChallengeStatus(PortraitLiveManager.liveID, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(StarChallengeStatusModel data1) { - showStart(data1); - Log.e("PortraitLiveManager", data1.toString()); - } + LiveNetManager.get(mContext).getStarChallengeStatus(PortraitLiveManager.liveID, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(StarChallengeStatusModel data1) { + showStart(data1); + Log.e("PortraitLiveManager", data1.toString()); + } - @Override - public void onError(String error) { - Log.e("PortraitLiveManager", error); - } - }); + @Override + public void onError(String error) { + Log.e("PortraitLiveManager", error); + } + }); } @@ -2036,155 +2004,94 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (mBannerList2 != null && mBanner2 != null) { btn_event2.setVisibility(View.VISIBLE); if (mBannerList2.size() == 1) { - mBanner2.setAutoPlay(false) - .setPages(mBannerList2, new CustomViewHolder()) - .setDelayTime(3200) - .setBannerStyle(BannerConfig.NOT_INDICATOR) - .setOnBannerClickListener(new OnBannerClickListener() { - @Override - public void onBannerClick(List datas, int p) { - if (showLoadingDialog()) { + mBanner2.setAutoPlay(false).setPages(mBannerList2, new CustomViewHolder()).setDelayTime(3200).setBannerStyle(BannerConfig.NOT_INDICATOR).setOnBannerClickListener(new OnBannerClickListener() { + @Override + public void onBannerClick(List datas, int p) { + if (showLoadingDialog()) { + return; + } + if (mBannerList2 != null) { + if (p >= 0 && p < mBannerList2.size()) { + IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); + BannerBean bean = mBannerList2.get(p); + String type = ""; + if (bean.getLink().equals("BattlePass")) { + RouteUtil.forwardBattlePass(); return; } - if (mBannerList2 != null) { - if (p >= 0 && p < mBannerList2.size()) { - IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); - BannerBean bean = mBannerList2.get(p); - String type = ""; - if (bean.getLink().equals("BattlePass")) { - RouteUtil.forwardBattlePass(); - return; - } - StringBuffer htmlUrl = new StringBuffer(); - //判断是否是星级活动 - if (bean.isStart()) { + StringBuffer htmlUrl = new StringBuffer(); + //判断是否是星级活动 + if (bean.isStart()) { - type = bean.getModel().getType(); - htmlUrl.append(CommonAppConfig.HOST) - .append("/") - .append(bean.getModel().getActivityUrl()) - .append(bean.getModel().getActivityUrl().contains("?") ? "&nickname=" : "?nickname=") - .append(userInfo.getUserNicename()) - .append("&token=") - .append(userInfo.getToken()) - .append("&anchorUid=") - .append(mLiveUid) - .append("&uid=") - .append(userInfo.getId()) - .append("&k=") - .append(System.currentTimeMillis()) - .append("&isZh=") - .append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); - } else { - type = bean.getShow_type(); - htmlUrl.append(bean.getLink()) - .append("?uid=") - .append(userInfo.getId()) - .append("&token=") - .append(userInfo.getToken()) - .append("&anchorUid=") - .append(mLiveUid) - .append("&t=") - .append(System.currentTimeMillis()) - .append("&isZh=") - .append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); - } - if (htmlUrl.toString().contains("StarChallenge")) { - Map map_ekv = new HashMap(); - map_ekv.put("link", htmlUrl.toString()); - MobclickAgent.onEvent(mContext, "live_room_star", map_ekv); - } - if (TextUtils.equals(type, "1")) { - ZhuangBanActivity.forward(mContext, htmlUrl.toString(), false, 1); - } else { - Bundle bundle = new Bundle(); - bundle.putString("url", htmlUrl.toString()); - LiveHDDialogFragment fragment = new LiveHDDialogFragment(); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); - } - } + type = bean.getModel().getType(); + htmlUrl.append(CommonAppConfig.HOST).append("/").append(bean.getModel().getActivityUrl()).append(bean.getModel().getActivityUrl().contains("?") ? "&nickname=" : "?nickname=").append(userInfo.getUserNicename()).append("&token=").append(userInfo.getToken()).append("&anchorUid=").append(mLiveUid).append("&uid=").append(userInfo.getId()).append("&k=").append(System.currentTimeMillis()).append("&isZh=").append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); + } else { + type = bean.getShow_type(); + htmlUrl.append(bean.getLink()).append("?uid=").append(userInfo.getId()).append("&token=").append(userInfo.getToken()).append("&anchorUid=").append(mLiveUid).append("&t=").append(System.currentTimeMillis()).append("&isZh=").append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); + } + if (htmlUrl.toString().contains("StarChallenge")) { + Map map_ekv = new HashMap(); + map_ekv.put("link", htmlUrl.toString()); + MobclickAgent.onEvent(mContext, "live_room_star", map_ekv); + } + if (TextUtils.equals(type, "1")) { + ZhuangBanActivity.forward(mContext, htmlUrl.toString(), false, 1); + } else { + Bundle bundle = new Bundle(); + bundle.putString("url", htmlUrl.toString()); + LiveHDDialogFragment fragment = new LiveHDDialogFragment(); + fragment.setArguments(bundle); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); } } - }) - .start(); + } + } + }).start(); } else { - mBanner2.setAutoPlay(true) - .setPages(mBannerList2, new CustomViewHolder()) - .setDelayTime(3200) - .setBannerStyle(BannerConfig.NOT_INDICATOR) - .setOnBannerClickListener(new OnBannerClickListener() { - @Override - public void onBannerClick(List datas, int p) { - if (showLoadingDialog()) { + mBanner2.setAutoPlay(true).setPages(mBannerList2, new CustomViewHolder()).setDelayTime(3200).setBannerStyle(BannerConfig.NOT_INDICATOR).setOnBannerClickListener(new OnBannerClickListener() { + @Override + public void onBannerClick(List datas, int p) { + if (showLoadingDialog()) { + return; + } + if (mBannerList2 != null) { + if (p >= 0 && p < mBannerList2.size()) { + IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); + BannerBean bean = mBannerList2.get(p); + if (bean.getLink().equals("BattlePass")) { + RouteUtil.forwardBattlePass(); return; } - if (mBannerList2 != null) { - if (p >= 0 && p < mBannerList2.size()) { - IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); - BannerBean bean = mBannerList2.get(p); - if (bean.getLink().equals("BattlePass")) { - RouteUtil.forwardBattlePass(); - return; - } - String type = ""; - StringBuffer htmlUrl = new StringBuffer(); - //判断是否是星级活动 - if (bean.isStart()) { - type = bean.getModel().getType(); - htmlUrl.append(CommonAppConfig.HOST) - .append("/") - .append(bean.getModel().getActivityUrl()) - .append(bean.getModel().getActivityUrl().contains("?") ? "&nickname=" : "?nickname=") - .append(userInfo.getUserNicename()) - .append("&token=") - .append(userInfo.getToken()) - .append("&anchorUid=") - .append(mLiveUid) - .append("&uid=") - .append(userInfo.getId()) - .append("&k=") - .append(System.currentTimeMillis()) - .append("&isZh=") - .append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); + String type = ""; + StringBuffer htmlUrl = new StringBuffer(); + //判断是否是星级活动 + if (bean.isStart()) { + type = bean.getModel().getType(); + htmlUrl.append(CommonAppConfig.HOST).append("/").append(bean.getModel().getActivityUrl()).append(bean.getModel().getActivityUrl().contains("?") ? "&nickname=" : "?nickname=").append(userInfo.getUserNicename()).append("&token=").append(userInfo.getToken()).append("&anchorUid=").append(mLiveUid).append("&uid=").append(userInfo.getId()).append("&k=").append(System.currentTimeMillis()).append("&isZh=").append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); - } else { - type = bean.getShow_type(); - htmlUrl.append(bean.getLink()) - .append(bean.getLink().contains("?") ? "&uid=" : "?uid=") - .append(userInfo.getId()) - .append("&token=") - .append(userInfo.getToken()) - .append("&anchorUid=") - .append(mLiveUid) - .append("&liveUid=") - .append(mLiveUid) - .append("&t=") - .append(System.currentTimeMillis()) - .append("&g=Appapi&m=Wish&a=index") - .append("&isZh=") - .append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); - } - if (htmlUrl.toString().contains("StarChallenge")) { - Map map_ekv = new HashMap(); - map_ekv.put("link", htmlUrl.toString()); - MobclickAgent.onEvent(mContext, "live_room_star", map_ekv); - } - if (TextUtils.equals(type, "1")) { - ZhuangBanActivity.forward(mContext, htmlUrl.toString(), false, 1); - } else { - Bundle bundle = new Bundle(); - bundle.putString("url", htmlUrl.toString()); - LiveHDDialogFragment fragment = new LiveHDDialogFragment(); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); - } - } + } else { + type = bean.getShow_type(); + htmlUrl.append(bean.getLink()).append(bean.getLink().contains("?") ? "&uid=" : "?uid=").append(userInfo.getId()).append("&token=").append(userInfo.getToken()).append("&anchorUid=").append(mLiveUid).append("&liveUid=").append(mLiveUid).append("&t=").append(System.currentTimeMillis()).append("&g=Appapi&m=Wish&a=index").append("&isZh=").append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); + } + if (htmlUrl.toString().contains("StarChallenge")) { + Map map_ekv = new HashMap(); + map_ekv.put("link", htmlUrl.toString()); + MobclickAgent.onEvent(mContext, "live_room_star", map_ekv); + } + if (TextUtils.equals(type, "1")) { + ZhuangBanActivity.forward(mContext, htmlUrl.toString(), false, 1); + } else { + Bundle bundle = new Bundle(); + bundle.putString("url", htmlUrl.toString()); + LiveHDDialogFragment fragment = new LiveHDDialogFragment(); + fragment.setArguments(bundle); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); } } - }) - .start(); + } + } + }).start(); } } @@ -2276,73 +2183,67 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } public void showLiveRoomActivityBanner() { - LiveNetManager.get(mContext) - .getLiveRoomActivityBanner(new com.yunbao.common.http.base.HttpCallback>() { - @Override - public void onSuccess(List data) { - mBannerList4.clear(); - for (LiveRoomActivityBanner datum : data) { - if (datum.getHidden() == 1) { - continue; - } - BannerBean bean = new BannerBean(); - bean.setActivityId(datum.getActiveId()); - bean.setName(datum.getName()); - bean.setLink(datum.getLink()); - bean.setImageUrl(datum.getImg()); - bean.setShow_type(datum.getType()); - mBannerList4.add(bean); - } - showBanner4(); + LiveNetManager.get(mContext).getLiveRoomActivityBanner(new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List data) { + mBannerList4.clear(); + for (LiveRoomActivityBanner datum : data) { + if (datum.getHidden() == 1) { + continue; } + BannerBean bean = new BannerBean(); + bean.setActivityId(datum.getActiveId()); + bean.setName(datum.getName()); + bean.setLink(datum.getLink()); + bean.setImageUrl(datum.getImg()); + bean.setShow_type(datum.getType()); + mBannerList4.add(bean); + } + showBanner4(); + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); } private void showBanner() { if (mBannerList1 == null || mBannerList1.size() == 0 || mBanner1 == null) { return; } - mBanner1.setAutoPlay(true) - .setPages(mBannerList1, new CustomViewHolder()) - .setDelayTime(3000) - .setBannerStyle(BannerConfig.NOT_INDICATOR) - .setOnBannerClickListener(new OnBannerClickListener() { - @Override - public void onBannerClick(List datas, int p) { - if (mBannerList1 != null) { - if (p >= 0 && p < mBannerList1.size()) { - BannerBean bean = mBannerList1.get(p); - if (bean != null) { - String link = bean.getLink(); - if (link.equals("BattlePass")) { - RouteUtil.forwardBattlePass(); - return; - } - if (link.equals("sc")) { - String url; - if (!"".equals(bean.getmIntoUrl()) && bean.getmIntoUrl() != null) { - url = CommonAppConfig.HOST + bean.getmIntoUrl() + "?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); - } else { - url = CommonAppConfig.HOST + "/h5/activity/firstTopUp/newUp.html?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); - } - ZhuangBanActivity.forward(mContext, url, false, 1); - } else if (link.equals("zxb")) { - String url = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); - ZhuangBanActivity.forward(mContext, url, false, 1); - } else if (link.equals("xyd")) { - openWishListWindow(); - } + mBanner1.setAutoPlay(true).setPages(mBannerList1, new CustomViewHolder()).setDelayTime(3000).setBannerStyle(BannerConfig.NOT_INDICATOR).setOnBannerClickListener(new OnBannerClickListener() { + @Override + public void onBannerClick(List datas, int p) { + if (mBannerList1 != null) { + if (p >= 0 && p < mBannerList1.size()) { + BannerBean bean = mBannerList1.get(p); + if (bean != null) { + String link = bean.getLink(); + if (link.equals("BattlePass")) { + RouteUtil.forwardBattlePass(); + return; + } + if (link.equals("sc")) { + String url; + if (!"".equals(bean.getmIntoUrl()) && bean.getmIntoUrl() != null) { + url = CommonAppConfig.HOST + bean.getmIntoUrl() + "?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + } else { + url = CommonAppConfig.HOST + "/h5/activity/firstTopUp/newUp.html?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); } + ZhuangBanActivity.forward(mContext, url, false, 1); + } else if (link.equals("zxb")) { + String url = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + ZhuangBanActivity.forward(mContext, url, false, 1); + } else if (link.equals("xyd")) { + openWishListWindow(); } } } - }) - .start(); + } + } + }).start(); } /** @@ -2426,8 +2327,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis path = "/" + path; } String url = CommonAppConfig.HOST + path; - url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" - + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid; + url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid; bundle.putString("url", url); bundle.putInt("height", DpUtil.dp2px(500)); bundle.putInt("show_type", 0); @@ -2450,51 +2350,47 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); textParams.leftMargin = DpUtil.dp2px(5); params.leftMargin = DpUtil.dp2px(5); - API.get().pdLiveApi(mContext).getHourChartRank(mLiveUid) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(listResponseModel -> { - List info = listResponseModel.getData().getInfo(); - if (!info.isEmpty()) { - View hotView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null); - View hourView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null); - ImageView hotPic = hotView.findViewById(R.id.wish_pic); - ImageView hourPic = hourView.findViewById(R.id.wish_pic); - mHotText = hotView.findViewById(R.id.wish_index); - mHourRank = hourView.findViewById(R.id.wish_index); - mHotText.setText("0"); - mHotText.setLayoutParams(textParams); - mHourRank.setLayoutParams(textParams); - mHotText.setGravity(Gravity.CENTER); - mHourRank.setGravity(Gravity.CENTER); - setHourRankData(info.get(0).getRank()); - hotPic.setImageResource(R.drawable.icon_time_new); - hourPic.setImageResource(R.drawable.icon_heat_new); - hotPic.setLayoutParams(params); - hourPic.setLayoutParams(params); - flipper.addView(hotView); - flipper.addView(hourView); - flipper.startFlipping(); + API.get().pdLiveApi(mContext).getHourChartRank(mLiveUid).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(listResponseModel -> { + List info = listResponseModel.getData().getInfo(); + if (!info.isEmpty()) { + View hotView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null); + View hourView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null); + ImageView hotPic = hotView.findViewById(R.id.wish_pic); + ImageView hourPic = hourView.findViewById(R.id.wish_pic); + mHotText = hotView.findViewById(R.id.wish_index); + mHourRank = hourView.findViewById(R.id.wish_index); + mHotText.setText("0"); + mHotText.setLayoutParams(textParams); + mHourRank.setLayoutParams(textParams); + mHotText.setGravity(Gravity.CENTER); + mHourRank.setGravity(Gravity.CENTER); + setHourRankData(info.get(0).getRank()); + hotPic.setImageResource(R.drawable.icon_time_new); + hourPic.setImageResource(R.drawable.icon_heat_new); + hotPic.setLayoutParams(params); + hourPic.setLayoutParams(params); + flipper.addView(hotView); + flipper.addView(hourView); + flipper.startFlipping(); // flipper.setOnClickListener(view -> { // // }); - ViewClicksAntiShake.clicksAntiShake(hotView, new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - showUrlHDDialog(info.get(0).getUrl()); - } - }); - ViewClicksAntiShake.clicksAntiShake(hourView, new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - showUrlHDDialog(info.get(0).getUrl()); - } - }); - - + ViewClicksAntiShake.clicksAntiShake(hotView, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + showUrlHDDialog(info.get(0).getUrl()); } - }, Throwable::printStackTrace) - .isDisposed(); + }); + ViewClicksAntiShake.clicksAntiShake(hourView, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + showUrlHDDialog(info.get(0).getUrl()); + } + }); + + + } + }, Throwable::printStackTrace).isDisposed(); new LoadDian9TuUtil().loadDian9TuAssets2(mContext, hourRankLayout, "rectangle_new.png", 1); } @@ -2504,9 +2400,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis path = "/" + path; } String url = CommonAppConfig.HOST + path; - url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" - + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid - + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"); + url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"); bundle.putString("url", url); bundle.putInt("height", DpUtil.dp2px(500)); bundle.putInt("show_type", 0); @@ -2596,84 +2490,82 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } public void initRankPKInfo(String mLiveUid, String pkUid) { - LiveNetManager.get(mContext) - .getRandomPk(mLiveUid, pkUid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(PkRankBean bean) { - if (bean != null) { - initPkRankView(bean); - if (!StringUtil.isEmpty(bean.getClickUrl())) { + LiveNetManager.get(mContext).getRandomPk(mLiveUid, pkUid, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(PkRankBean bean) { + if (bean != null) { + initPkRankView(bean); + if (!StringUtil.isEmpty(bean.getClickUrl())) { - pkRankVf.setOnClickListener(v -> { - MobclickAgent.onEvent(mContext, "live_room_sky", "天梯赛按钮"); - Bundle bundle = new Bundle(); - String path = bean.getClickUrl(); - if (!path.startsWith("/") && !path.startsWith("http")) { - path = "/" + path; - } - String url = null; - if (path.startsWith("http") || path.startsWith("/http")) { - url = path; - } else { - url = CommonAppConfig.HOST + path; - } - if (!url.contains("?")) { - url += "?"; - } else { - url += "&"; - } - url += "uid=" + CommonAppConfig.getInstance().getUid() + "&token=" - + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); - bundle.putString("url", url); - bundle.putInt("height", DpUtil.dp2px(500)); - bundle.putInt("show_type", 0); - bundle.putString("roomId", mLiveUid); - LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment(); - liveHDDialogFragment.setArguments(bundle); - liveHDDialogFragment.show(((AbsActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); - }); + pkRankVf.setOnClickListener(v -> { + MobclickAgent.onEvent(mContext, "live_room_sky", "天梯赛按钮"); + Bundle bundle = new Bundle(); + String path = bean.getClickUrl(); + if (!path.startsWith("/") && !path.startsWith("http")) { + path = "/" + path; } - pkRankLayout.setVisibility(View.VISIBLE); - - liveRankPk2.setVisibility(View.VISIBLE); - mPkRankText.setText(bean.getName()); - ImgLoader.display(mContext, bean.getImg(), mPkRankIcon); - pkUidTmp = ""; - if (StringUtil.isEmpty(bean.getPkTopImgUrl())) { - return; + String url = null; + if (path.startsWith("http") || path.startsWith("/http")) { + url = path; + } else { + url = CommonAppConfig.HOST + path; } - if (!StringUtil.isEmpty(isLadders)) { - bean.setPkTopImgUrl(isLadders); + if (!url.contains("?")) { + url += "?"; + } else { + url += "&"; } - if (Integer.parseInt(bean.getRedVal()) > 2) { - mRedVal.setVisibility(View.VISIBLE); - mRedVal.setText(bean.getRedVal() + (WordUtil.isNewZh() ? "連勝" : "Win")); - } - if (Integer.parseInt(bean.getBlueVal()) > 2) { - mBlueVal.setVisibility(View.VISIBLE); - mBlueVal.setText(bean.getBlueVal() + (WordUtil.isNewZh() ? "連勝" : "Win")); - } - mPkRankTopIcon.setVisibility(View.VISIBLE); - ImgLoader.display(mContext, bean.getPkTopImgUrl(), mPkRankTopIcon); - } - if (mRedVal.getVisibility() == View.VISIBLE) { - RelativeLayout.LayoutParams redValLayoutParams = (RelativeLayout.LayoutParams) mRedVal.getLayoutParams(); - redValLayoutParams.bottomMargin = DpUtil.dp2px(10); - mRedVal.setLayoutParams(redValLayoutParams); - } - if (mBlueVal.getVisibility() == View.VISIBLE) { - RelativeLayout.LayoutParams blueValLayoutParams = (RelativeLayout.LayoutParams) mBlueVal.getLayoutParams(); - blueValLayoutParams.bottomMargin = DpUtil.dp2px(10); - mBlueVal.setLayoutParams(blueValLayoutParams); - } + url += "uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid + "&isZh=" + (WordUtil.isNewZh() ? "1" : 0); + bundle.putString("url", url); + bundle.putInt("height", DpUtil.dp2px(500)); + bundle.putInt("show_type", 0); + bundle.putString("roomId", mLiveUid); + LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment(); + liveHDDialogFragment.setArguments(bundle); + liveHDDialogFragment.show(((AbsActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + }); } + pkRankLayout.setVisibility(View.VISIBLE); - @Override - public void onError(String error) { - ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); - pkUidTmp = ""; + liveRankPk2.setVisibility(View.VISIBLE); + mPkRankText.setText(bean.getName()); + ImgLoader.display(mContext, bean.getImg(), mPkRankIcon); + pkUidTmp = ""; + if (StringUtil.isEmpty(bean.getPkTopImgUrl())) { + return; } - }); + if (!StringUtil.isEmpty(isLadders)) { + bean.setPkTopImgUrl(isLadders); + } + if (Integer.parseInt(bean.getRedVal()) > 2) { + mRedVal.setVisibility(View.VISIBLE); + mRedVal.setText(bean.getRedVal() + (WordUtil.isNewZh() ? "連勝" : "Win")); + } + if (Integer.parseInt(bean.getBlueVal()) > 2) { + mBlueVal.setVisibility(View.VISIBLE); + mBlueVal.setText(bean.getBlueVal() + (WordUtil.isNewZh() ? "連勝" : "Win")); + } + mPkRankTopIcon.setVisibility(View.VISIBLE); + ImgLoader.display(mContext, bean.getPkTopImgUrl(), mPkRankTopIcon); + } + if (mRedVal.getVisibility() == View.VISIBLE) { + RelativeLayout.LayoutParams redValLayoutParams = (RelativeLayout.LayoutParams) mRedVal.getLayoutParams(); + redValLayoutParams.bottomMargin = DpUtil.dp2px(10); + mRedVal.setLayoutParams(redValLayoutParams); + } + if (mBlueVal.getVisibility() == View.VISIBLE) { + RelativeLayout.LayoutParams blueValLayoutParams = (RelativeLayout.LayoutParams) mBlueVal.getLayoutParams(); + blueValLayoutParams.bottomMargin = DpUtil.dp2px(10); + mBlueVal.setLayoutParams(blueValLayoutParams); + } + } + + @Override + public void onError(String error) { + ToastUtil.show(WordUtil.isNewZh() ? "抱歉!出錯了!" : "i \\'m sorry! An error occurred"); + pkUidTmp = ""; + } + }); } /** @@ -3067,8 +2959,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public boolean pkHandler = true; @Subscribe(threadMode = ThreadMode.MAIN) - public void setOtherInfo(LivePKRightUserInfoEvent livePKRightUserInfoEvent){ - setOtherInfo(livePKRightUserInfoEvent.getUid(),livePKRightUserInfoEvent.getuHead(),livePKRightUserInfoEvent.getuName()); + public void setOtherInfo(LivePKRightUserInfoEvent livePKRightUserInfoEvent) { + setOtherInfo(livePKRightUserInfoEvent.getUid(), livePKRightUserInfoEvent.getuHead(), livePKRightUserInfoEvent.getuName()); } //左上角显示对方主播头像及昵称 @@ -3288,19 +3180,17 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis participation_time.postDelayed(sendMoneyRunnable, 1000); } else { participation_time.removeCallbacks(sendMoneyRunnable); - LiveNetManager.get(mContext) - .endSendMoneyLong(mLiveUid, mSendMoneyLongModel.getSendMoneyLongKey(), - new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(SendMoneyLongModel data) { + LiveNetManager.get(mContext).endSendMoneyLong(mLiveUid, mSendMoneyLongModel.getSendMoneyLongKey(), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(SendMoneyLongModel data) { - } + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); } } }; @@ -3340,10 +3230,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis weekViewPic.setLayoutParams(params); if (!TextUtils.isEmpty(giftWallLightenNumber) && !TextUtils.isEmpty(giftWallLightenTotal)) { StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append(mContext.getString(R.string.gift_wall)) - .append(giftWallLightenNumber) - .append("/") - .append(giftWallLightenTotal); + stringBuffer.append(mContext.getString(R.string.gift_wall)).append(giftWallLightenNumber).append("/").append(giftWallLightenTotal); View giftWall = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null); ImageView giftWallPic = giftWall.findViewById(R.id.wish_pic); TextView giftText = giftWall.findViewById(R.id.wish_index); @@ -3356,12 +3243,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ViewClicksAntiShake.clicksAntiShake(giftWall, new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GIFT_WALL) - .setUid(mLiveUid) - .setVoicePress(true) - .setAvatar(mAvatarUrl) - .setUname(mAnchorName)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GIFT_WALL).setUid(mLiveUid).setVoicePress(true).setAvatar(mAvatarUrl).setUname(mAnchorName)); } }); } @@ -3370,8 +3252,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void onViewClicks() { MobclickAgent.onEvent(mContext, "live_room_week", "周星榜按钮"); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LIVE_WKS)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIVE_WKS)); } }); wksAndGiftWall.addView(weekView); @@ -3654,12 +3535,10 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void callback(Integer isAttention) { if (isAttention == 1) { - if(isSw){ - LiveActivity.sendSystemMessageSw( - CommonAppConfig.getInstance().getUserBean().getUserNiceName() + Contexts.getString(R.string.live_follow_anchor)); - }else{ - LiveActivity.sendSystemMessageRy( - CommonAppConfig.getInstance().getUserBean().getUserNiceName() + Contexts.getString(R.string.live_follow_anchor)); + if (isSw) { + LiveActivity.sendSystemMessageSw(CommonAppConfig.getInstance().getUserBean().getUserNiceName() + Contexts.getString(R.string.live_follow_anchor)); + } else { + LiveActivity.sendSystemMessageRy(CommonAppConfig.getInstance().getUserBean().getUserNiceName() + Contexts.getString(R.string.live_follow_anchor)); } } } @@ -3739,7 +3618,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis LiveSwAnchorActivity.backIndex = 1; ((LiveSwAnchorActivity) mContext).onBackPressed(); } - }else if(mContext instanceof LiveRyAnchorActivity){ + } else if (mContext instanceof LiveRyAnchorActivity) { if (forAct == 1) { //是否关注0==没关注 if (isAttention == 0) { @@ -4013,8 +3892,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis setHotData(formatBigNum.formatBigNum(bean.getHot_num())); mTvMedalRank.setText(bean.getMedalRankNum()); //开通粉丝勋章成功弹窗 - if (!isAncher && bean.getMedalFirstGet() != null && bean.getMedalFirstGet().equals("1") - && bean.getUid().equals(CommonAppConfig.getInstance().getUid())) { + if (!isAncher && bean.getMedalFirstGet() != null && bean.getMedalFirstGet().equals("1") && bean.getUid().equals(CommonAppConfig.getInstance().getUid())) { ((LiveAudienceActivity) mContext).openFansMedalOkWindow(); } @@ -4026,7 +3904,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (mLiveGiftAnimPresenter == null) { mLiveGiftAnimPresenter = new LiveGiftAnimPresenter(mContext, mContentView, mGifImageView, mSVGAImageView, mLiveGiftPrizePoolContainer, windowManager); } - mLiveGiftAnimPresenter.setLiveUidStream(mLiveUid,mStream); + mLiveGiftAnimPresenter.setLiveUidStream(mLiveUid, mStream); mLiveGiftAnimPresenter.showGiftAnim(bean, isAncher); } @@ -4050,16 +3928,16 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } - public void showAllServerNotifyFFGGGD(AllServerNotifyFFGGGDJANEvent notifyFFGGGDJANEvent,boolean showB) { + public void showAllServerNotifyFFGGGD(AllServerNotifyFFGGGDJANEvent notifyFFGGGDJANEvent, boolean showB) { if (mLiveGiftAnimPresenter == null) { mLiveGiftAnimPresenter = new LiveGiftAnimPresenter(mContext, mContentView, mGifImageView, mSVGAImageView, mLiveGiftPrizePoolContainer, windowManager); } mLiveGiftAnimPresenter.setLiveUidStream(mLiveUid, mStream); - mLiveGiftAnimPresenter.showAllServerNotifyFFGGGD(notifyFFGGGDJANEvent,showB); + mLiveGiftAnimPresenter.showAllServerNotifyFFGGGD(notifyFFGGGDJANEvent, showB); } - public void cancelAllAnim(){ - if(mLiveGiftAnimPresenter!=null){ + public void cancelAllAnim() { + if (mLiveGiftAnimPresenter != null) { mLiveGiftAnimPresenter.releaseServiceNotice(); } } @@ -4090,60 +3968,25 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis switch (bean.getNobilityid()) { case "1": - noble.setRootView(bean.getUhead(), - bean.getUname(), - bean.getAncherName(), - bean.getRoomnum()) - .setRoleType(NobleNoticeView.RoleType.BARON) - .setCallBack(() -> gotoLive(bean.getRoomnum())); + noble.setRootView(bean.getUhead(), bean.getUname(), bean.getAncherName(), bean.getRoomnum()).setRoleType(NobleNoticeView.RoleType.BARON).setCallBack(() -> gotoLive(bean.getRoomnum())); break; case "2": - noble.setRootView(bean.getUhead(), - bean.getUname(), - bean.getAncherName(), - bean.getRoomnum()) - .setRoleType(NobleNoticeView.RoleType.VISCOUNT) - .setCallBack(() -> gotoLive(bean.getRoomnum())); + noble.setRootView(bean.getUhead(), bean.getUname(), bean.getAncherName(), bean.getRoomnum()).setRoleType(NobleNoticeView.RoleType.VISCOUNT).setCallBack(() -> gotoLive(bean.getRoomnum())); break; case "3": - noble.setRootView(bean.getUhead(), - bean.getUname(), - bean.getAncherName(), - bean.getRoomnum()) - .setRoleType(NobleNoticeView.RoleType.MARQUIS) - .setCallBack(() -> gotoLive(bean.getRoomnum())); + noble.setRootView(bean.getUhead(), bean.getUname(), bean.getAncherName(), bean.getRoomnum()).setRoleType(NobleNoticeView.RoleType.MARQUIS).setCallBack(() -> gotoLive(bean.getRoomnum())); break; case "4": - noble.setRootView(bean.getUhead(), - bean.getUname(), - bean.getAncherName(), - bean.getRoomnum()) - .setRoleType(NobleNoticeView.RoleType.DUKE) - .setCallBack(() -> gotoLive(bean.getRoomnum())); + noble.setRootView(bean.getUhead(), bean.getUname(), bean.getAncherName(), bean.getRoomnum()).setRoleType(NobleNoticeView.RoleType.DUKE).setCallBack(() -> gotoLive(bean.getRoomnum())); break; case "5": - noble.setRootView(bean.getUhead(), - bean.getUname(), - bean.getAncherName(), - bean.getRoomnum()) - .setRoleType(NobleNoticeView.RoleType.KING) - .setCallBack(() -> gotoLive(bean.getRoomnum())); + noble.setRootView(bean.getUhead(), bean.getUname(), bean.getAncherName(), bean.getRoomnum()).setRoleType(NobleNoticeView.RoleType.KING).setCallBack(() -> gotoLive(bean.getRoomnum())); break; case "6": - noble.setRootView(bean.getUhead(), - bean.getUname(), - bean.getAncherName(), - bean.getRoomnum()) - .setRoleType(NobleNoticeView.RoleType.EMPEROR) - .setCallBack(() -> gotoLive(bean.getRoomnum())); + noble.setRootView(bean.getUhead(), bean.getUname(), bean.getAncherName(), bean.getRoomnum()).setRoleType(NobleNoticeView.RoleType.EMPEROR).setCallBack(() -> gotoLive(bean.getRoomnum())); break; case "7": - noble.setRootView(bean.getUhead(), - bean.getUname(), - bean.getAncherName(), - bean.getRoomnum()) - .setRoleType(NobleNoticeView.RoleType.BETTER_EMPEROR) - .setCallBack(() -> gotoLive(bean.getRoomnum())); + noble.setRootView(bean.getUhead(), bean.getUname(), bean.getAncherName(), bean.getRoomnum()).setRoleType(NobleNoticeView.RoleType.BETTER_EMPEROR).setCallBack(() -> gotoLive(bean.getRoomnum())); break; } } @@ -4454,8 +4297,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public void setFastMessage(List greetings) { fastMsgRecyclerView.setVisibility(View.VISIBLE); fastMessageRecyclerViewAdapter.setMessage(greetings); - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) - mChatRecyclerView.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) mChatRecyclerView.getLayoutParams(); if (greetings.size() > 0) { params1.bottomMargin = 100; } else { @@ -4515,14 +4357,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } public void openGiftDialog(String giftId) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) - .setmLiveUid(mLiveUid) - .setmStream(mStream) - .setPk(false) - .setLiveGuardInfo(null) - .setmWishGiftId(giftId) - .setUname("0"));//setUname==by + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP).setmLiveUid(mLiveUid).setmStream(mStream).setPk(false).setLiveGuardInfo(null).setmWishGiftId(giftId).setUname("0"));//setUname==by } public void setFansGroup(String isFans) { @@ -4640,32 +4475,27 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis return; } - mBanner3.setAutoPlay(true) - .setPages(mBannerList3, new Banner3CustomViewHolder()) - .setDelayTime(3000) - .setBannerStyle(BannerConfig.NOT_INDICATOR) - .setOnBannerClickListener(new OnBannerClickListener() { - @Override - public void onBannerClick(List datas, int p) { - if (mBannerList3 != null) { - if (mBannerList3.get(p).getLink().equals("BattlePass")) { - RouteUtil.forwardBattlePass(); - return; - } - if (mBannerList3.get(p).getLink().equals("0")) { - if (p == 0) { - ((LiveAudienceActivity) mContext).openGiftWindow("" + bean1.getId(), "1"); - EventBus.getDefault().post("svga_new_user_gif"); - } else if (p == 1) { - EventBus.getDefault().post("svga_new_user_follow"); - } else if (p == 2) { - EventBus.getDefault().post("svga_new_user_double"); - } - } + mBanner3.setAutoPlay(true).setPages(mBannerList3, new Banner3CustomViewHolder()).setDelayTime(3000).setBannerStyle(BannerConfig.NOT_INDICATOR).setOnBannerClickListener(new OnBannerClickListener() { + @Override + public void onBannerClick(List datas, int p) { + if (mBannerList3 != null) { + if (mBannerList3.get(p).getLink().equals("BattlePass")) { + RouteUtil.forwardBattlePass(); + return; + } + if (mBannerList3.get(p).getLink().equals("0")) { + if (p == 0) { + ((LiveAudienceActivity) mContext).openGiftWindow("" + bean1.getId(), "1"); + EventBus.getDefault().post("svga_new_user_gif"); + } else if (p == 1) { + EventBus.getDefault().post("svga_new_user_follow"); + } else if (p == 2) { + EventBus.getDefault().post("svga_new_user_double"); } } - }) - .start(); + } + } + }).start(); } /** @@ -4679,69 +4509,61 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis for (BannerBean bean : mBannerList4) { Log.i("debug", "showBanner4: " + bean.toString()); } - mBanner4.setAutoPlay(true) - .setPages(mBannerList4, new Banner4CustomViewHolder()) - .setDelayTime(2800) - .setBannerStyle(BannerConfig.NOT_INDICATOR) - .setOnBannerClickListener(new OnBannerClickListener() { + mBanner4.setAutoPlay(true).setPages(mBannerList4, new Banner4CustomViewHolder()).setDelayTime(2800).setBannerStyle(BannerConfig.NOT_INDICATOR).setOnBannerClickListener(new OnBannerClickListener() { - @Override - public void onBannerClick(List datas, int p) { - if (mBannerList4.get(p).getLink().equals("BattlePass") || mBannerList4.get(p).getType() == 888) { - RouteUtil.forwardBattlePass(); - return; - } - if (TextUtils.equals("特惠首冲", mBannerList4.get(p).getName())) { + @Override + public void onBannerClick(List datas, int p) { + if (mBannerList4.get(p).getLink().equals("BattlePass") || mBannerList4.get(p).getType() == 888) { + RouteUtil.forwardBattlePass(); + return; + } + if (TextUtils.equals("特惠首冲", mBannerList4.get(p).getName())) { - Map map_ekv = new HashMap(); - map_ekv.put("link", mBannerList4.get(p).getLink()); - MobclickAgent.onEvent(mContext, "live_room_first_charge", map_ekv); - } - Log.i("debug", "onBannerClick: " + mBannerList4.get(p).toString()); - BannerBean bean = mBannerList4.get(p); - if (showLoadingDialog()) { - return; - } - if (bean.getActivityId() == -1) {//-1写死跳活动弹窗 - Bus.get().post(new LiveAudienceEvent() - .setActivity(true) - .setType(LiveAudienceEvent.LiveAudienceType.BOTTOM_COLLECTION)); - } else if (bean.getActivityId() == 0) { - openWebDialog(bean.getLink()); - } else { - LiveGameDialogFragment fragment = new LiveGameDialogFragment("1".equals(bean.getShow_type())); - fragment.setActivityId(bean.getActivityId()); - fragment.setRoomId(mLiveUid); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGameDialogFragment"); - } + Map map_ekv = new HashMap(); + map_ekv.put("link", mBannerList4.get(p).getLink()); + MobclickAgent.onEvent(mContext, "live_room_first_charge", map_ekv); + } + Log.i("debug", "onBannerClick: " + mBannerList4.get(p).toString()); + BannerBean bean = mBannerList4.get(p); + if (showLoadingDialog()) { + return; + } + if (bean.getActivityId() == -1) {//-1写死跳活动弹窗 + Bus.get().post(new LiveAudienceEvent().setActivity(true).setType(LiveAudienceEvent.LiveAudienceType.BOTTOM_COLLECTION)); + } else if (bean.getActivityId() == 0) { + openWebDialog(bean.getLink()); + } else { + LiveGameDialogFragment fragment = new LiveGameDialogFragment("1".equals(bean.getShow_type())); + fragment.setActivityId(bean.getActivityId()); + fragment.setRoomId(mLiveUid); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGameDialogFragment"); + } + } + + + private void openWebDialog(String url) { + if (!url.startsWith("http")) { + if (url.startsWith("/")) { + url = CommonAppConfig.HOST + url; + } else { + url = CommonAppConfig.HOST + "/" + url; } + } + if (url.contains("?")) { + url += "&"; + } else { + url += "?"; + } + url += "uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid; + Log.i("tag", url); + Bundle bundle1 = new Bundle(); + bundle1.putString("url", url); + LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment(); + liveHDDialogFragment.setArguments(bundle1); + liveHDDialogFragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); - - private void openWebDialog(String url) { - if (!url.startsWith("http")) { - if (url.startsWith("/")) { - url = CommonAppConfig.HOST + url; - } else { - url = CommonAppConfig.HOST + "/" + url; - } - } - if (url.contains("?")) { - url += "&"; - } else { - url += "?"; - } - url += "uid=" + CommonAppConfig.getInstance().getUid() + "&token=" - + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid; - Log.i("tag", url); - Bundle bundle1 = new Bundle(); - bundle1.putString("url", url); - LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment(); - liveHDDialogFragment.setArguments(bundle1); - liveHDDialogFragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); - - } - }) - .start(); + } + }).start(); } private int nowTime = 0; @@ -4944,9 +4766,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis * @param msgModel */ public void showFullScreen(MsgModel msgModel) { - fullScreen.setUserNameAndUserText(msgModel.getUserName(), msgModel.getTrumpetMsg()) - .setType(msgModel.getRoleType()) - .setCallBack(() -> gotoLive(msgModel.getAnchorId())); + fullScreen.setUserNameAndUserText(msgModel.getUserName(), msgModel.getTrumpetMsg()).setType(msgModel.getRoleType()).setCallBack(() -> gotoLive(msgModel.getAnchorId())); } /** @@ -4961,20 +4781,14 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class); new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override - public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) { + public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk, boolean isSw) { if (liveBean == null) { return; } if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI) - .setMicIng(1) - .setBean(liveBean).setLiveType(liveType).setLiveTypeVal(Integer.parseInt(liveTypeVal))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI).setMicIng(1).setBean(liveBean).setLiveType(liveType).setLiveTypeVal(Integer.parseInt(liveTypeVal))); } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI) - .setMicIng(2) - .setBean(liveBean).setLiveType(liveType).setLiveTypeVal(Integer.parseInt(liveTypeVal))); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.LIAN_MAI).setMicIng(2).setBean(liveBean).setLiveType(liveType).setLiveTypeVal(Integer.parseInt(liveTypeVal))); } else { if (MicStatusManager.getInstance().isMic(liveUid)) { MicStatusManager.getInstance().showDownMicDialog(mContext); @@ -5208,12 +5022,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void run() { BannerBean bannerBean = new BannerBean(); - bannerBean.setWishlistIcon(model.getWishlistIcon()) - .setWishlistName(model.getWishlistName()) - .setWishlistNum(model.getWishlistNum()) - .setWishlistProgress(model.getWishlistProgress()) - .setmLink(CommonAppConfig.HOST + "/index.php") - .setType(1); + bannerBean.setWishlistIcon(model.getWishlistIcon()).setWishlistName(model.getWishlistName()).setWishlistNum(model.getWishlistNum()).setWishlistProgress(model.getWishlistProgress()).setmLink(CommonAppConfig.HOST + "/index.php").setType(1); bannerBean.setShow_type("2"); mTopBannerList.add(bannerBean); LiveChatBean bean = new LiveChatBean(); @@ -5342,8 +5151,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (mPkTimeCount2 == 0) { timeTitle.setVisibility(View.GONE); timeTitle.removeCallbacks(countdownRunnable); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); + Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.PK_TIME_COUNT)); } else { timeTitle.setVisibility(View.VISIBLE); Log.e("多人Pk", "countdownRunnable mPkTimeCount:" + mPkTimeCount2); @@ -5356,51 +5164,53 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } }; + public void upDataPkScore(JSONArray pkScores, int time) { - L.eSw("upDataPkScore(JSONArray pkScores, int time) {"+new Gson().toJson(pkScores)); + L.eSw("upDataPkScore(JSONArray pkScores, int time) {" + new Gson().toJson(pkScores)); isShowGif = true; - if (detailsView == null) { - L.eSw("upDataPkScore(JSONArray pkScores, int time) {detailsView=null"); - detailsView = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - timeTitle = detailsView.findViewById(R.id.time_title); - textTime = detailsView.findViewById(R.id.text_time); - linearGrade1 = detailsView.findViewById(R.id.lin_pk1); - linearGrade2 = detailsView.findViewById(R.id.lin_pk2); - linearGrade3 = detailsView.findViewById(R.id.lin_pk3); - linearGrade4 = detailsView.findViewById(R.id.lin_pk4); - textPkName1 = detailsView.findViewById(R.id.text_pk_name1); - textPkName2 = detailsView.findViewById(R.id.text_pk_name2); - textPkName3 = detailsView.findViewById(R.id.text_pk_name3); - textPkName4 = detailsView.findViewById(R.id.text_pk_name4); - textGrade1 = detailsView.findViewById(R.id.text_grade1); - textGrade2 = detailsView.findViewById(R.id.text_grade2); - textGrade3 = detailsView.findViewById(R.id.text_grade3); - textGrade4 = detailsView.findViewById(R.id.text_grade4); - imageGrade1 = detailsView.findViewById(R.id.image_grade1); - imageGrade2 = detailsView.findViewById(R.id.image_grade2); - imageGrade3 = detailsView.findViewById(R.id.image_grade3); - imageGrade4 = detailsView.findViewById(R.id.image_grade4); - //暂时关闭 - linearGrade1.setVisibility(View.GONE); - linearGrade2.setVisibility(View.GONE); - linearGrade3.setVisibility(View.GONE); - linearGrade4.setVisibility(View.GONE); + if (detailsView != null) { mRoot.removeView(detailsView); - mRoot.addView(detailsView); - mRoot.post(new Runnable() { - @Override - public void run() { - int mScreenWdith = ScreenDimenUtil.getInstance().getScreenWdith(); - int vHeight = mScreenWdith * 720 / 960; - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) detailsView.getLayoutParams(); - params.height = vHeight; - params.width = mScreenWdith; - params.topMargin = DpUtil.dp2px(105); - params.addRule(RelativeLayout.ALIGN_TOP); - detailsView.setLayoutParams(params); - } - }); } + L.eSw("upDataPkScore(JSONArray pkScores, int time) {detailsView=null"); + detailsView = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + timeTitle = detailsView.findViewById(R.id.time_title); + textTime = detailsView.findViewById(R.id.text_time); + linearGrade1 = detailsView.findViewById(R.id.lin_pk1); + linearGrade2 = detailsView.findViewById(R.id.lin_pk2); + linearGrade3 = detailsView.findViewById(R.id.lin_pk3); + linearGrade4 = detailsView.findViewById(R.id.lin_pk4); + textPkName1 = detailsView.findViewById(R.id.text_pk_name1); + textPkName2 = detailsView.findViewById(R.id.text_pk_name2); + textPkName3 = detailsView.findViewById(R.id.text_pk_name3); + textPkName4 = detailsView.findViewById(R.id.text_pk_name4); + textGrade1 = detailsView.findViewById(R.id.text_grade1); + textGrade2 = detailsView.findViewById(R.id.text_grade2); + textGrade3 = detailsView.findViewById(R.id.text_grade3); + textGrade4 = detailsView.findViewById(R.id.text_grade4); + imageGrade1 = detailsView.findViewById(R.id.image_grade1); + imageGrade2 = detailsView.findViewById(R.id.image_grade2); + imageGrade3 = detailsView.findViewById(R.id.image_grade3); + imageGrade4 = detailsView.findViewById(R.id.image_grade4); + //暂时关闭 + linearGrade1.setVisibility(View.GONE); + linearGrade2.setVisibility(View.GONE); + linearGrade3.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + + mRoot.addView(detailsView); + mRoot.post(new Runnable() { + @Override + public void run() { + int mScreenWdith = ScreenDimenUtil.getInstance().getScreenWdith(); + int vHeight = mScreenWdith * 720 / 960; + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) detailsView.getLayoutParams(); + params.height = vHeight; + params.width = mScreenWdith; + params.topMargin = DpUtil.dp2px(105); + params.addRule(RelativeLayout.ALIGN_TOP); + detailsView.setLayoutParams(params); + } + }); if (time > 0) { mPkTimeCount2 = time; drPKtIME = time; @@ -5490,7 +5300,142 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis showUserDialog(userId3); } }); + } + public void upDataPkScore(JSONArray pkScores) { + L.eSw("upDataPkScore(JSONArray pkScores, int time) {" + new Gson().toJson(pkScores)); + isShowGif = true; + if (detailsView == null) { + L.eSw("upDataPkScore(JSONArray pkScores, int time) {detailsView=null"); + detailsView = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + timeTitle = detailsView.findViewById(R.id.time_title); + textTime = detailsView.findViewById(R.id.text_time); + linearGrade1 = detailsView.findViewById(R.id.lin_pk1); + linearGrade2 = detailsView.findViewById(R.id.lin_pk2); + linearGrade3 = detailsView.findViewById(R.id.lin_pk3); + linearGrade4 = detailsView.findViewById(R.id.lin_pk4); + textPkName1 = detailsView.findViewById(R.id.text_pk_name1); + textPkName2 = detailsView.findViewById(R.id.text_pk_name2); + textPkName3 = detailsView.findViewById(R.id.text_pk_name3); + textPkName4 = detailsView.findViewById(R.id.text_pk_name4); + textGrade1 = detailsView.findViewById(R.id.text_grade1); + textGrade2 = detailsView.findViewById(R.id.text_grade2); + textGrade3 = detailsView.findViewById(R.id.text_grade3); + textGrade4 = detailsView.findViewById(R.id.text_grade4); + imageGrade1 = detailsView.findViewById(R.id.image_grade1); + imageGrade2 = detailsView.findViewById(R.id.image_grade2); + imageGrade3 = detailsView.findViewById(R.id.image_grade3); + imageGrade4 = detailsView.findViewById(R.id.image_grade4); + //暂时关闭 + linearGrade1.setVisibility(View.GONE); + linearGrade2.setVisibility(View.GONE); + linearGrade3.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + mRoot.removeView(detailsView); + mRoot.addView(detailsView); + mRoot.post(new Runnable() { + @Override + public void run() { + int mScreenWdith = ScreenDimenUtil.getInstance().getScreenWdith(); + int vHeight = mScreenWdith * 720 / 960; + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) detailsView.getLayoutParams(); + params.height = vHeight; + params.width = mScreenWdith; + params.topMargin = DpUtil.dp2px(105); + params.addRule(RelativeLayout.ALIGN_TOP); + detailsView.setLayoutParams(params); + } + }); + } + Log.e("多人Pk", "upDataPkScore mPkTimeCount:" + mPkTimeCount); + if (pkScores.size() == 2) { + linearGrade3.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + } else if(pkScores.size()==3){ + linearGrade4.setVisibility(View.GONE); + } + for (int i = 0; i < pkScores.size(); i++) { + JSONObject score = pkScores.getJSONObject(i); + String userNiceName = score.getString("user_nicename"); + long userScore = score.getLong("score"); + String userId = score.getString("id"); + int resScore = R.mipmap.icon_livepk_no1; + if (userScore == 0 && !score.containsKey("paiming")) { + resScore = R.mipmap.icon_livepk_no1; + } else { + if (score.containsKey("paiming")) { + int ranking = score.getIntValue("paiming"); + switch (ranking) { + case 1: + resScore = R.mipmap.icon_livepk_no1; + break; + case 2: + resScore = R.mipmap.icon_livepk_no2; + break; + case 3: + resScore = R.mipmap.icon_livepk_no3; + break; + case 4: + resScore = R.mipmap.icon_livepk_no4; + break; + } + } + } + if (i == 0) { + linearGrade1.setVisibility(View.VISIBLE); + textPkName1.setText(userNiceName); + ImgLoader.display(mContext, resScore, imageGrade1); + textGrade1.setText(String.valueOf(userScore)); + + } else if (i == 1) { + linearGrade2.setVisibility(View.VISIBLE); + textPkName2.setText(userNiceName); + ImgLoader.display(mContext, resScore, imageGrade2); + textGrade2.setText(String.valueOf(userScore)); + userId2 = userId; + } else if (i == 2) { + if (pkScores.size() == 3) { + linearGrade4.setVisibility(View.VISIBLE); + textPkName4.setText(userNiceName); + ImgLoader.display(mContext, resScore, imageGrade4); + textGrade4.setText(String.valueOf(userScore)); + userId4 = userId; + } else { + linearGrade3.setVisibility(View.VISIBLE); + textPkName3.setText(userNiceName); + ImgLoader.display(mContext, resScore, imageGrade3); + textGrade3.setText(String.valueOf(userScore)); + userId3 = userId; + } + + } else if (i == 3) { + linearGrade4.setVisibility(View.VISIBLE); + textPkName4.setText(userNiceName); + ImgLoader.display(mContext, resScore, imageGrade4); + textGrade4.setText(String.valueOf(userScore)); + userId4 = userId; + } + } + + + textPkName2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showUserDialog(userId2); + } + }); + textPkName4.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showUserDialog(userId4); + } + }); + textPkName3.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showUserDialog(userId3); + } + }); } @@ -5519,8 +5464,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis * @param landscape */ public void changeMessageLandscape(int landscape) { - RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) - mChatRecyclerView.getLayoutParams(); + RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) mChatRecyclerView.getLayoutParams(); RelativeLayout.LayoutParams enterRoomParams = (RelativeLayout.LayoutParams) enterRoomLeave.getLayoutParams(); if (landscape == 2) { params1.height = DpUtil.dp2px(200); @@ -5613,10 +5557,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis TextView userName = fans_enter_room_leave.findViewById(R.id.user_name); ImageView bg = fans_enter_room_leave.findViewById(R.id.bg); - userName.setText(Html.fromHtml(String.format("@%s %s", - model.getUserNiceName(), - mContext.getString(R.string.live_fans_group_enter_room) - ))); + userName.setText(Html.fromHtml(String.format("@%s %s", model.getUserNiceName(), mContext.getString(R.string.live_fans_group_enter_room)))); ImgLoader.display(mContext, model.getFansEnterRoomUrl(), bg); fans_enter_room_leave.setVisibility(View.VISIBLE); TranslateAnimation animationTranslate = new TranslateAnimation(DeviceUtils.getScreenWidth((Activity) mContext), 0, 0, 0); @@ -5705,47 +5646,46 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis LiveAnchorSayModel sayModel; public void initAnchorSayData() { - LiveNetManager.get(mContext) - .getLivePreviewInfo(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveAnchorSayModel data) { - Log.i("女神说", "onSuccess: " + data); - sayModel = data; - LiveAnchorSayModel.LivePreview preview = data.getLivePreview(); - if (preview != null) { - mAnchorSayText.setText(getText(data.getLivePreview().getContent())); - ImgLoader.display(mContext, preview.getStyleImage(), mAnchorSayImage); - if (preview.getIsShow() == 1) { - mAnchorSay.setVisibility(View.VISIBLE); - } else { - mAnchorSay.setVisibility(View.INVISIBLE); - } - } else { - mAnchorSay.setVisibility(View.INVISIBLE); - } - + LiveNetManager.get(mContext).getLivePreviewInfo(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveAnchorSayModel data) { + Log.i("女神说", "onSuccess: " + data); + sayModel = data; + LiveAnchorSayModel.LivePreview preview = data.getLivePreview(); + if (preview != null) { + mAnchorSayText.setText(getText(data.getLivePreview().getContent())); + ImgLoader.display(mContext, preview.getStyleImage(), mAnchorSayImage); + if (preview.getIsShow() == 1) { + mAnchorSay.setVisibility(View.VISIBLE); + } else { + mAnchorSay.setVisibility(View.INVISIBLE); } + } else { + mAnchorSay.setVisibility(View.INVISIBLE); + } - @Override - public void onError(String error) { + } + @Override + public void onError(String error) { + + } + + public String getText(String content) { + int t = 4; + float len = (float) content.length() / t; + StringBuilder sb = new StringBuilder(); + sb.append("\n"); + for (int i = 0; i < len; i++) { + if (len - i < 1) { + sb.append(content.substring(i * t)); + } else { + sb.append(content.substring(i * t, i * t + t)).append("\n"); } - - public String getText(String content) { - int t = 4; - float len = (float) content.length() / t; - StringBuilder sb = new StringBuilder(); - sb.append("\n"); - for (int i = 0; i < len; i++) { - if (len - i < 1) { - sb.append(content.substring(i * t)); - } else { - sb.append(content.substring(i * t, i * t + t)).append("\n"); - } - } - return sb.toString(); - } - }); + } + return sb.toString(); + } + }); } public void initAnchorSay() { @@ -5769,10 +5709,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public void showAnchorSayAndCallAnchor() { isHinde = false; - if (mAnchorSay.getVisibility() != View.VISIBLE && - sayModel != null && sayModel.getLivePreview() != null && - sayModel.getLivePreview().getIsShow() == 1 - ) { + if (mAnchorSay.getVisibility() != View.VISIBLE && sayModel != null && sayModel.getLivePreview() != null && sayModel.getLivePreview().getIsShow() == 1) { Log.i("女神说", "sayModel: " + sayModel); mAnchorSay.setVisibility(View.VISIBLE); } @@ -5805,12 +5742,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } BannerBean bannerBean = new BannerBean(); - bannerBean.setWishlistIcon(wishListProgress.getWishlistIcon()) - .setWishlistName(wishListProgress.getWishlistName()) - .setWishlistNum(wishListProgress.getWishlistNum()) - .setWishlistProgress(wishListProgress.getWishlistProgress()) - .setmLink(CommonAppConfig.HOST + "/index.php") - .setType(1); + bannerBean.setWishlistIcon(wishListProgress.getWishlistIcon()).setWishlistName(wishListProgress.getWishlistName()).setWishlistNum(wishListProgress.getWishlistNum()).setWishlistProgress(wishListProgress.getWishlistProgress()).setmLink(CommonAppConfig.HOST + "/index.php").setType(1); bannerBean.setShow_type("2"); if (mTopBannerList.size() == 1 || mTopBannerList.size() == 0) { mTopBannerList.add(bannerBean); @@ -5832,197 +5764,142 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis return; } topBanner1.setVisibility(View.GONE); - topBanner1.setAutoPlay(true) - .setPages(mTopBannerList, new TopBannerCustomViewHolder()) - .setDelayTime(3000) - .setBannerStyle(BannerConfig.NOT_INDICATOR) - .setOnBannerClickListener(new OnBannerClickListener() { - @Override - public void onBannerClick(List datas, int position) { - if (datas.size() > 0 && mTopBannerList != null && mTopBannerList.size() > 0) { - if (mTopBannerList.get(position).getType() == TopBannerCustomViewHolder.TYPE_CALL_ANCHOR) { - MobclickAgent.onEvent(mContext, "live_room_contact", "联系方式按钮"); - Dialog loading = DialogUitl.loadingDialog(mContext); - loading.show(); - LiveNetManager.get(mContext) - .getContactInfo(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { + topBanner1.setAutoPlay(true).setPages(mTopBannerList, new TopBannerCustomViewHolder()).setDelayTime(3000).setBannerStyle(BannerConfig.NOT_INDICATOR).setOnBannerClickListener(new OnBannerClickListener() { + @Override + public void onBannerClick(List datas, int position) { + if (datas.size() > 0 && mTopBannerList != null && mTopBannerList.size() > 0) { + if (mTopBannerList.get(position).getType() == TopBannerCustomViewHolder.TYPE_CALL_ANCHOR) { + MobclickAgent.onEvent(mContext, "live_room_contact", "联系方式按钮"); + Dialog loading = DialogUitl.loadingDialog(mContext); + loading.show(); + LiveNetManager.get(mContext).getContactInfo(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveAnchorCallMeModel data) { - if (data.getIsGet() == 1) { - new LiveUserAnchorMailBoxWebInfoPopDialog(mContext, mAnchorName, data.getLink()) - .setOnDismissListener(dialog -> { - checkNewLetter(); - loading.dismiss(); - }) - .showDialog(); - return; - } - new LiveContactDetailsSendGiftDialog(mContext) - .setGiftId(data.getGiftId()) - .setAnchorName(mAnchorName) - .setStream(mStream) - .setLiveUid(mLiveUid) - .setOnDismissListener(dialog1 -> { - checkNewLetter(); - }) - .showDialog(); - loading.dismiss(); - } - - @Override - public void onError(String error) { - loading.dismiss(); - } - }); - - } else { - MobclickAgent.onEvent(mContext, "live_room_wish", "心愿单按钮"); - BannerBean bean = mTopBannerList.get(position); - IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); - String type = ""; - StringBuffer htmlUrl = new StringBuffer(); - htmlUrl.append(bean.getLink()) - .append(bean.getLink().contains("?") ? "&uid=" : "?uid=") - .append(userInfo.getId()) - .append("&token=") - .append(userInfo.getToken()) - .append("&anchorUid=") - .append(mLiveUid) - .append("&liveUid=") - .append(mLiveUid) - .append("&t=") - .append(System.currentTimeMillis()) - .append("&g=Appapi&m=Wish&a=index") - .append("&isZh=") - .append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); - if (TextUtils.equals(type, "1")) { - ZhuangBanActivity.forward(mContext, htmlUrl.toString(), false, 1); - } else { - Bundle bundle = new Bundle(); - bundle.putString("url", htmlUrl.toString()); - LiveHDDialogFragment fragment = new LiveHDDialogFragment(); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + @Override + public void onSuccess(LiveAnchorCallMeModel data) { + if (data.getIsGet() == 1) { + new LiveUserAnchorMailBoxWebInfoPopDialog(mContext, mAnchorName, data.getLink()).setOnDismissListener(dialog -> { + checkNewLetter(); + loading.dismiss(); + }).showDialog(); + return; } + new LiveContactDetailsSendGiftDialog(mContext).setGiftId(data.getGiftId()).setAnchorName(mAnchorName).setStream(mStream).setLiveUid(mLiveUid).setOnDismissListener(dialog1 -> { + checkNewLetter(); + }).showDialog(); + loading.dismiss(); } + + @Override + public void onError(String error) { + loading.dismiss(); + } + }); + + } else { + MobclickAgent.onEvent(mContext, "live_room_wish", "心愿单按钮"); + BannerBean bean = mTopBannerList.get(position); + IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); + String type = ""; + StringBuffer htmlUrl = new StringBuffer(); + htmlUrl.append(bean.getLink()).append(bean.getLink().contains("?") ? "&uid=" : "?uid=").append(userInfo.getId()).append("&token=").append(userInfo.getToken()).append("&anchorUid=").append(mLiveUid).append("&liveUid=").append(mLiveUid).append("&t=").append(System.currentTimeMillis()).append("&g=Appapi&m=Wish&a=index").append("&isZh=").append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); + if (TextUtils.equals(type, "1")) { + ZhuangBanActivity.forward(mContext, htmlUrl.toString(), false, 1); + } else { + Bundle bundle = new Bundle(); + bundle.putString("url", htmlUrl.toString()); + LiveHDDialogFragment fragment = new LiveHDDialogFragment(); + fragment.setArguments(bundle); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); } - } - }) - .start(); - topBanner2.setAutoPlay(true) - .setPages(mTopBannerList, new TopBannerCustomViewHolder(false)) - .setDelayTime(3000) - .setBannerStyle(BannerConfig.NOT_INDICATOR) - .setOnBannerClickListener(new OnBannerClickListener() { - @Override - public void onBannerClick(List datas, int position) { - if (datas.size() > 0) { - if (position >= mTopBannerList.size()) { - position = 0; - } - if (mTopBannerList.get(position).getType() == TopBannerCustomViewHolder.TYPE_CALL_ANCHOR) { - MobclickAgent.onEvent(mContext, "live_room_contact", "联系方式按钮"); - Dialog loading = DialogUitl.loadingDialog(mContext); - loading.show(); - LiveNetManager.get(mContext) - .getContactInfo(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { + } - @Override - public void onSuccess(LiveAnchorCallMeModel data) { - if (data.getIsGet() == 1) { - new LiveUserAnchorMailBoxWebInfoPopDialog(mContext, mAnchorName, data.getLink()) - .setOnDismissListener(dialog -> { - checkNewLetter(); - loading.dismiss(); - }) - .showDialog(); - return; - } - new LiveContactDetailsSendGiftDialog(mContext) - .setGiftId(data.getGiftId()) - .setAnchorName(mAnchorName) - .setStream(mStream) - .setLiveUid(mLiveUid) - .setOnDismissListener(dialog1 -> { - checkNewLetter(); - }) - .showDialog(); - loading.dismiss(); - } + } + }).start(); + topBanner2.setAutoPlay(true).setPages(mTopBannerList, new TopBannerCustomViewHolder(false)).setDelayTime(3000).setBannerStyle(BannerConfig.NOT_INDICATOR).setOnBannerClickListener(new OnBannerClickListener() { + @Override + public void onBannerClick(List datas, int position) { + if (datas.size() > 0) { + if (position >= mTopBannerList.size()) { + position = 0; + } + if (mTopBannerList.get(position).getType() == TopBannerCustomViewHolder.TYPE_CALL_ANCHOR) { + MobclickAgent.onEvent(mContext, "live_room_contact", "联系方式按钮"); + Dialog loading = DialogUitl.loadingDialog(mContext); + loading.show(); + LiveNetManager.get(mContext).getContactInfo(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onError(String error) { - loading.dismiss(); - } - }); - - } else { - MobclickAgent.onEvent(mContext, "live_room_wish", "心愿单按钮"); - BannerBean bean = mTopBannerList.get(position); - IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); - String type = ""; - StringBuffer htmlUrl = new StringBuffer(); - htmlUrl.append(bean.getLink()) - .append(bean.getLink().contains("?") ? "&uid=" : "?uid=") - .append(userInfo.getId()) - .append("&token=") - .append(userInfo.getToken()) - .append("&anchorUid=") - .append(mLiveUid) - .append("&liveUid=") - .append(mLiveUid) - .append("&t=") - .append(System.currentTimeMillis()) - .append("&g=Appapi&m=Wish&a=index") - .append("&isZh=") - .append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); - if (TextUtils.equals(type, "1")) { - ZhuangBanActivity.forward(mContext, htmlUrl.toString(), false, 1); - } else { - Bundle bundle = new Bundle(); - bundle.putString("url", htmlUrl.toString()); - LiveHDDialogFragment fragment = new LiveHDDialogFragment(); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + @Override + public void onSuccess(LiveAnchorCallMeModel data) { + if (data.getIsGet() == 1) { + new LiveUserAnchorMailBoxWebInfoPopDialog(mContext, mAnchorName, data.getLink()).setOnDismissListener(dialog -> { + checkNewLetter(); + loading.dismiss(); + }).showDialog(); + return; } + new LiveContactDetailsSendGiftDialog(mContext).setGiftId(data.getGiftId()).setAnchorName(mAnchorName).setStream(mStream).setLiveUid(mLiveUid).setOnDismissListener(dialog1 -> { + checkNewLetter(); + }).showDialog(); + loading.dismiss(); } - } + @Override + public void onError(String error) { + loading.dismiss(); + } + }); + + } else { + MobclickAgent.onEvent(mContext, "live_room_wish", "心愿单按钮"); + BannerBean bean = mTopBannerList.get(position); + IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); + String type = ""; + StringBuffer htmlUrl = new StringBuffer(); + htmlUrl.append(bean.getLink()).append(bean.getLink().contains("?") ? "&uid=" : "?uid=").append(userInfo.getId()).append("&token=").append(userInfo.getToken()).append("&anchorUid=").append(mLiveUid).append("&liveUid=").append(mLiveUid).append("&t=").append(System.currentTimeMillis()).append("&g=Appapi&m=Wish&a=index").append("&isZh=").append(((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0")); + if (TextUtils.equals(type, "1")) { + ZhuangBanActivity.forward(mContext, htmlUrl.toString(), false, 1); + } else { + Bundle bundle = new Bundle(); + bundle.putString("url", htmlUrl.toString()); + LiveHDDialogFragment fragment = new LiveHDDialogFragment(); + fragment.setArguments(bundle); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + } } - }) - .start(); + } + + } + }).start(); updateCallMe(); } private void updateCallMe() { - LiveNetManager.get(mContext) - .getContactInfo(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(LiveAnchorCallMeModel data) { - System.out.println(">>>>> 获取联系方式:" + data); - if (data.getIsShow() == 1) { - if (!isHinde) { - topBanner1.setVisibility(View.VISIBLE); - } - BannerBean call = new BannerBean(); - call.setData(data); - call.setType(TopBannerCustomViewHolder.TYPE_CALL_ANCHOR); - mTopBannerList.add(0, call); - topBanner1.update(mTopBannerList); - topBanner2.update(mTopBannerList); - } - - + LiveNetManager.get(mContext).getContactInfo(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(LiveAnchorCallMeModel data) { + System.out.println(">>>>> 获取联系方式:" + data); + if (data.getIsShow() == 1) { + if (!isHinde) { + topBanner1.setVisibility(View.VISIBLE); } + BannerBean call = new BannerBean(); + call.setData(data); + call.setType(TopBannerCustomViewHolder.TYPE_CALL_ANCHOR); + mTopBannerList.add(0, call); + topBanner1.update(mTopBannerList); + topBanner2.update(mTopBannerList); + } - @Override - public void onError(String error) { - System.out.println("!>>>>> 获取联系方式:" + error); - } - }); + + } + + @Override + public void onError(String error) { + System.out.println("!>>>>> 获取联系方式:" + error); + } + }); } @@ -6066,19 +5943,18 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public void updateFansMessageRed() { if (mContext instanceof LiveAudienceActivity) { - LiveNetManager.get(mContext) - .getCheckFansLevelUpgrade(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(FansCheckRed data) { - ((LiveAudienceActivity) mContext).setShowCrownRed(data.getStatus() == 1); + LiveNetManager.get(mContext).getCheckFansLevelUpgrade(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(FansCheckRed data) { + ((LiveAudienceActivity) mContext).setShowCrownRed(data.getStatus() == 1); - } + } - @Override - public void onError(String error) { + @Override + public void onError(String error) { - } - }); + } + }); } } } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 79725eff5..7f4226ec7 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -394,7 +394,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); } - mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager(),isSw); + mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager(), isSw); mLiveAudienceViewHolder = new LiveAudienceViewHolder(mContext, mContainer); mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, mLiveAudienceViewHolder.getContentView()); mLiveLinkMicAnchorPresenter = new LiveLinkMicAnchorPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, null); @@ -957,7 +957,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (mLiveAudienceViewHolder != null) { mLiveAudienceViewHolder.removeCallbacks(); } - if(mLivePlayViewHolder!=null){ + if (mLivePlayViewHolder != null) { mLivePlayViewHolder.stopPlay2(); mLiveRoomViewHolder.cancelAllAnim(); } @@ -987,7 +987,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRyLinkMicPkPresenter.release(); mLiveRyLinkMicPkPresenter = null; } - if(mLiveSwLinkMicPkPresenter!=null){ + if (mLiveSwLinkMicPkPresenter != null) { mLiveSwLinkMicPkPresenter.clearData(); mLiveSwLinkMicPkPresenter.release(); mLiveSwLinkMicPkPresenter = null; @@ -1031,7 +1031,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe EventBus.getDefault() .post(new LiveFloatEvent() .setmLiveBean(mLiveBean) - .setmLiveSDK(isSw?2:mLiveSDK) + .setmLiveSDK(isSw ? 2 : mLiveSDK) .setmLiveType(mLiveType) .setmLiveTypeVal(mLiveTypeVal)); } @@ -1170,8 +1170,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe DialogUitl.showSimpleDialog(mContext, null, "連麥中,退出將斷開語音連麥!", false, new DialogUitl.SimpleCallback3() { @Override public void onConfirmClick(Dialog dialog) { - if(isSw){ - if(mLivePlayViewHolder!=null){ + if (isSw) { + if (mLivePlayViewHolder != null) { mLivePlayViewHolder.endLiveMic(); HttpClient.getInstance().get("live.leaveDrLm", "live.leaveDrLm") .params("roomid", liveID) @@ -1189,7 +1189,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe EventBus.getDefault().post(new LiveRoomChangeEvent(bean, liveType, liveTypeVal)); } } - }else{ + } else { if (RCRTCEngine.getInstance().getRoom() == null || RCRTCEngine.getInstance().getRoom().getLocalUser() == null) { return; } @@ -1277,15 +1277,15 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (!mFirstConnectSocket) { mFirstConnectSocket = true; if (mLiveType == Constants.LIVE_TYPE_PAY || mLiveType == Constants.LIVE_TYPE_TIME) { - if(isSw){ + if (isSw) { SocketSwChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal, 1); - }else{ + } else { SocketRyChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal, 1); } } - if(isSw){ + if (isSw) { SocketSwChatUtil.getFakeFans(mLiveBean.getUid()); - }else{ + } else { SocketRyChatUtil.getFakeFans(mLiveBean.getUid()); } } @@ -1735,8 +1735,18 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onLinkDRMicPkQuit(String uid) { - L.eSw("onLinkDRMicPkQuit:"+uid); + L.eSw("onLinkDRMicPkQuit:" + uid); mLivePlayViewHolder.removeLiveUid(uid); + int removeUid = 0; + for (int k = 0; k < pkScores.size(); k++) { + JSONObject score = pkScores.getJSONObject(k); + String userID = score.getString("id"); + if (userID.equals(uid)) { + removeUid = k; + } + } + pkScores.remove(removeUid); + upDataPkScore(pkScores, -1); } /** @@ -2166,9 +2176,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe MobclickAgent.onEvent(mContext, "live_room_light", "直播间点亮"); mLighted = true; int guardType = mLiveGuardInfo != null ? mLiveGuardInfo.getMyGuardType() : Constants.GUARD_TYPE_NONE; - if(isSw){ + if (isSw) { SocketSwChatUtil.sendLightMessage(mLiveBean.getUid(), 1 + RandomUtil.nextInt(6), guardType); - }else{ + } else { SocketRyChatUtil.sendLightMessage(mLiveBean.getUid(), 1 + RandomUtil.nextInt(6), guardType); } } @@ -2228,9 +2238,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe * 更新主播映票数 */ public void sendUpdateVotesMessage() { - if(isSw){ + if (isSw) { SocketSwChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal); - }else{ + } else { SocketRyChatUtil.sendUpdateVotesMessage(mLiveBean.getUid(), mLiveTypeVal); } } @@ -2354,6 +2364,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mViewPager.setCanScroll(enableScroll); } + public JSONArray pkScores; + /** * 用户端多人Pk * @@ -2362,6 +2374,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe */ public void upDataPkScore(JSONArray pkScores, int time) { L.eSw("upDataPkScore" + time); + this.pkScores = pkScores; if (mLiveRoomViewHolder != null) { String liveId = mLiveBean.getUid(); JSONObject liveModel = null; @@ -2376,8 +2389,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } pkScores.remove(index); pkScores.add(0, liveModel); - mLiveRoomViewHolder.upDataPkScore(pkScores, time); - mLivePlayViewHolder.claerDrPkInfoView(); + if (time == -1) { + mLiveRoomViewHolder.upDataPkScore(pkScores); + } else { + mLiveRoomViewHolder.upDataPkScore(pkScores, time); + mLivePlayViewHolder.claerDrPkInfoView(); + } setPkStatus(true); } //通知心愿单位置换地方 diff --git a/live/src/main/res/layout/view_live_play_sw.xml b/live/src/main/res/layout/view_live_play_sw.xml index cdcd20495..64cb1c25f 100644 --- a/live/src/main/res/layout/view_live_play_sw.xml +++ b/live/src/main/res/layout/view_live_play_sw.xml @@ -49,7 +49,7 @@ From 11c9a530282f1d924940a3d1fca1e621eb52c664 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 1 Jun 2024 10:16:31 +0800 Subject: [PATCH 38/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/live/activity/LiveSwAnchorActivity.java | 2 +- .../live/presenter/LiveSwLinkMicPkPresenter.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index b9e1fe394..78c9dbf64 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -1668,7 +1668,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl case LEAVE_PK_SCORE: if (mLiveSwLinkMicPkPresenter != null) { mLiveSwLinkMicPkPresenter.closeButtonGone(); - mLiveSwLinkMicPkPresenter.upDataPkScore(event.getPkScores(), event.getUid(), event.getTime()); + mLiveSwLinkMicPkPresenter.upDataPkScore(event.getPkScores(), event.getUid(), event.getTime(),true); } if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.seisShowGif(true); diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 427d5384e..10b4c19fe 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -79,8 +79,10 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Timer; import java.util.TimerTask; @@ -563,7 +565,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } pkScores.remove(removeUid); - upDataPkScore(pkScores,"-1",0); + upDataPkScore(pkScores,"-1",0,false); } }, 1000); } @@ -588,7 +590,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { if (livePushSwViewHolder != null) { livePushSwViewHolder.setAnDrPkRtc(String.valueOf(u.getId()), -1); } - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("type", 3).param("uid", u.getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("msgtype", 3).param("uid", u.getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.create(); String targetId = "g" + CommonAppConfig.getInstance().getUid(); @@ -1063,7 +1065,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("msgtype", 3).param("uid", drPkbeans.get(i).getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("msgtype", 3).param("uid", drPkbeans.get(i).getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName() );; msg1.create(); L.eSw("發送給自己直播間" + drPkbeans.get(i).getId()); String targetId = "g" + CommonAppConfig.getInstance().getUid(); @@ -1699,14 +1701,14 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { /** * 更新Pk分数 */ - public void upDataPkScore(JSONArray pkScores, String uid, int time) { + public void upDataPkScore(JSONArray pkScores, String uid, int time,boolean isShowTimeTitle) { this.pkScores = pkScores; L.eSw("更新Pk分数 upDataPkScore time:" + time + " " + pkScores); String userID1 = (String) imageGrade1.getTag(); String userID2 = (String) imageGrade2.getTag(); String userID4 = (String) imageGrade4.getTag(); - if (livePushSwViewHolder.timeTitle.getVisibility() == View.GONE &&!"-1".equals(uid)) { + if (livePushSwViewHolder.timeTitle.getVisibility() == View.GONE &&isShowTimeTitle) { mHandler.removeMessages(WHAT_PK_TIME2); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) livePushSwViewHolder.timeTitle.getLayoutParams(); layoutParams.topMargin = DpUtil.dp2px(123); From 39cf76439f6c03f52b7727194d394591f1695273 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 1 Jun 2024 10:32:32 +0800 Subject: [PATCH 39/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?APPID=20=E6=9B=B4=E6=8D=A2=E5=AD=98=E5=82=A8=E4=BD=8D=E7=BD=AE]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/common/CommonAppConfig.java | 2 ++ .../beautyapi/faceunity/agora/SWAuManager.java | 16 +++++++++++----- .../beautyapi/faceunity/agora/SWManager.java | 5 +---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index 3ec41c897..5b98684f4 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -79,6 +79,8 @@ public class CommonAppConfig { public static String SWToken = ""; //声网Token public static final String SWChannelPrefix = "g"; + public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; + /** * 获取通道 diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index 63ca6e76a..b3f9742d7 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -10,6 +10,7 @@ import android.widget.FrameLayout; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.LiveBean; import com.yunbao.common.bean.UserBean; import com.yunbao.common.http.API; import com.yunbao.common.http.ResponseModel; @@ -21,6 +22,8 @@ import com.yunbao.common.utils.L; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; +import java.util.List; + import io.agora.rtc2.ChannelMediaOptions; import io.agora.rtc2.Constants; import io.agora.rtc2.IRtcEngineEventHandler; @@ -43,9 +46,6 @@ import io.rong.message.TextMessage; */ public class SWAuManager extends BaseCacheManager { - // 填写项目的 App ID,可在声网控制台中生成 - public static final String shengwang_appId = "4cf0376582d742ac8a96778b25b1079e"; - // 填写频道名 private Activity mContext; public static SWAuManager manager; private RtcEngineEx mRtcEngine; @@ -102,7 +102,7 @@ public class SWAuManager extends BaseCacheManager { // 创建 RtcEngineConfig 对象,并进行配置 RtcEngineConfig config = new RtcEngineConfig(); config.mContext = mContext; - config.mAppId = SWAuManager.shengwang_appId; + config.mAppId = CommonAppConfig.SWAPPId; config.mEventHandler = mRtcEventHandler; // 创建并初始化 RtcEngine mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); @@ -123,7 +123,7 @@ public class SWAuManager extends BaseCacheManager { // 创建 RtcEngineConfig 对象,并进行配置 RtcEngineConfig config = new RtcEngineConfig(); config.mContext = mContext; - config.mAppId = SWAuManager.shengwang_appId; + config.mAppId = CommonAppConfig.SWAPPId; config.mEventHandler = mEventHandler; // 创建并初始化 RtcEngine mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); @@ -415,4 +415,10 @@ public class SWAuManager extends BaseCacheManager { public interface SwListener { void onUserOffline(int liveUid); } + + public void preloadChannel(List uids){ + for (int i = 0; i Date: Sat, 1 Jun 2024 11:07:00 +0800 Subject: [PATCH 40/64] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A3=B0=E7=BD=91?= =?UTF-8?q?=E6=AD=A3=E5=BC=8F=E6=9C=8D=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/main/java/com/yunbao/common/CommonAppConfig.java | 5 ++++- config.gradle | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index 5b98684f4..325e26afd 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -78,8 +78,11 @@ public class CommonAppConfig { public static int alert_end_time = 1; public static String SWToken = ""; //声网Token public static final String SWChannelPrefix = "g"; - + //测试服 public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; + //正式服 +// public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; + /** diff --git a/config.gradle b/config.gradle index 76db80235..14d48a2a1 100644 --- a/config.gradle +++ b/config.gradle @@ -9,7 +9,7 @@ ext { ] manifestPlaceholders = [ //正式、 - //serverHost : "https://napi.yaoulive.com", +// serverHost : "https://napi.yaoulive.com", // 测试 serverHost : "https://ceshi.yaoulive.com", From 19c270ad22874814c762ebe3ae79311ca1506090 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 1 Jun 2024 11:16:26 +0800 Subject: [PATCH 41/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E7=A7=92=E5=BC=80]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../faceunity/agora/SWAuManager.java | 38 +++++++++++-------- .../beautyapi/faceunity/agora/SWManager.java | 17 +++++---- .../yunbao/main/activity/MainActivity.java | 3 ++ .../views/MainHomeFollLiveViewHolder.java | 12 +++++- .../main/views/MainHomeFollowViewHolder.java | 6 ++- .../main/views/MainHomeLiveViewHolder.java | 7 ++++ .../views/MainHomeRecomLiveViewHolder.java | 6 +++ 7 files changed, 63 insertions(+), 26 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index b3f9742d7..c174f1492 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -98,16 +98,18 @@ public class SWAuManager extends BaseCacheManager { */ public void initRtcEngine(Activity mContext) { this.mContext = mContext; - try { - // 创建 RtcEngineConfig 对象,并进行配置 - RtcEngineConfig config = new RtcEngineConfig(); - config.mContext = mContext; - config.mAppId = CommonAppConfig.SWAPPId; - config.mEventHandler = mRtcEventHandler; - // 创建并初始化 RtcEngine - mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); - } catch (Exception e) { - throw new RuntimeException("Check the error."); + if(mRtcEngine==null){ + try { + // 创建 RtcEngineConfig 对象,并进行配置 + RtcEngineConfig config = new RtcEngineConfig(); + config.mContext = mContext; + config.mAppId = CommonAppConfig.SWAPPId; + config.mEventHandler = mRtcEventHandler; + // 创建并初始化 RtcEngine + mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); + } catch (Exception e) { + throw new RuntimeException("Check the error."); + } } mRtcEngine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING); // 直播模式,引擎級別 // 开启本地预览 @@ -120,13 +122,15 @@ public class SWAuManager extends BaseCacheManager { public void initRtcEngineAudio(Activity mContext) { this.mContext = mContext; try { + if(mRtcEngine==null){ + RtcEngineConfig config = new RtcEngineConfig(); + config.mContext = mContext; + config.mAppId = CommonAppConfig.SWAPPId; + config.mEventHandler = mEventHandler; + // 创建并初始化 RtcEngine + mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); + } // 创建 RtcEngineConfig 对象,并进行配置 - RtcEngineConfig config = new RtcEngineConfig(); - config.mContext = mContext; - config.mAppId = CommonAppConfig.SWAPPId; - config.mEventHandler = mEventHandler; - // 创建并初始化 RtcEngine - mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); mRtcEngine.enableAudio(); mRtcEngine.enableLocalAudio(true); } catch (Exception e) { @@ -417,7 +421,9 @@ public class SWAuManager extends BaseCacheManager { } public void preloadChannel(List uids){ + L.eSw("设置秒开数据"); for (int i = 0; i { private CommonRefreshView mRefreshView; private MainHomeRemFollLiveAdapter mAdapter; @@ -56,7 +59,7 @@ public class MainHomeFollLiveViewHolder extends AbsMainHomeChildViewHolder imple mRefreshView.showRefreshBar(); mRefreshView.mRecyclerView.scrollToPosition(0); } - }else if ("blacklist".equals(str)) { + } else if ("blacklist".equals(str)) { if (mRefreshView != null) { mRefreshView.showRefreshBar(); } @@ -99,6 +102,7 @@ public class MainHomeFollLiveViewHolder extends AbsMainHomeChildViewHolder imple @Override public void onRefreshSuccess(List list, int count) { + SWAuManager.get().preloadChannel(list); EventBus.getDefault().post(new AnchorRecommendModel()); } @@ -115,6 +119,7 @@ public class MainHomeFollLiveViewHolder extends AbsMainHomeChildViewHolder imple new_data.add(loadItemList.get(j)); } } + SWAuManager.get().preloadChannel(new_data); mAdapter.insertList(new_data); } @@ -147,6 +152,9 @@ public class MainHomeFollLiveViewHolder extends AbsMainHomeChildViewHolder imple // if (mRefreshView != null) { // mRefreshView.initData(); // } + if (mAdapter != null) { + SWAuManager.get().preloadChannel(mAdapter.getList()); + } } @Override @@ -164,6 +172,6 @@ public class MainHomeFollLiveViewHolder extends AbsMainHomeChildViewHolder imple @Override public void onResume() { super.onResume(); - + L.eSw("onResume"); } } diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeFollowViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeFollowViewHolder.java index 0dfd0bc0f..88fc09831 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeFollowViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeFollowViewHolder.java @@ -23,6 +23,8 @@ import com.yunbao.main.http.MainHttpUtil; import java.util.List; +import io.agora.beautyapi.faceunity.agora.SWAuManager; + /** * Created by cxf on 2018/9/22. * 首页 关注 @@ -70,7 +72,9 @@ public class MainHomeFollowViewHolder extends AbsMainHomeChildViewHolder impleme public List processData(String[] info) { if (info.length > 0) { JSONObject obj = JSON.parseObject(info[0]); - return JSON.parseArray(obj.getString("list"), LiveBean.class); + List liveBeanList = JSON.parseArray(obj.getString("list"), LiveBean.class); + SWAuManager.get().preloadChannel(liveBeanList); + return liveBeanList; } return null; } diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index 0a8dc1a9c..2301f50be 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -74,6 +74,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import io.agora.beautyapi.faceunity.agora.SWAuManager; + /** * Created by cxf on 2018/9/22. * MainActivity 首页 直播 @@ -242,6 +244,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement if (liveModel != null) { old_data.remove(liveModel); } + SWAuManager.get().preloadChannel(old_data); new_data.addAll(old_data); } @@ -271,6 +274,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement } } if (loadItemList.size() > 0) { + SWAuManager.get().preloadChannel(new_data); mAdapter.insertList(new_data); } } @@ -533,6 +537,9 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement @Override public void loadData() { + if (mAdapter != null) { + SWAuManager.get().preloadChannel(mAdapter.getList()); + } } @Override diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeRecomLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeRecomLiveViewHolder.java index d86234c2f..ec5025544 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeRecomLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeRecomLiveViewHolder.java @@ -31,6 +31,8 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.Arrays; import java.util.List; +import io.agora.beautyapi.faceunity.agora.SWAuManager; + /** * 首页推荐 */ @@ -104,6 +106,7 @@ public class MainHomeRecomLiveViewHolder extends AbsMainHomeChildViewHolder impl @Override public void onRefreshSuccess(List list, int count) { + SWAuManager.get().preloadChannel(list); EventBus.getDefault().post(new AnchorRecommendModel()); } @@ -149,6 +152,9 @@ public class MainHomeRecomLiveViewHolder extends AbsMainHomeChildViewHolder impl // if (mRefreshView != null) { // mRefreshView.initData(); // } + if (mAdapter != null) { + SWAuManager.get().preloadChannel(mAdapter.getList()); + } } @Override From 680780145c570c191d1f02ae6312311334360874 Mon Sep 17 00:00:00 2001 From: 18142669586 <1669783059@qq.com> Date: Sat, 1 Jun 2024 12:07:36 +0800 Subject: [PATCH 42/64] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9A=E4=BA=BA?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E9=97=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presenter/LiveSwLinkMicPkPresenter.java | 90 +++++++++---------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 10b4c19fe..32f1797fa 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -1740,63 +1740,63 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { if (TextUtils.equals(userID, userID1)) { textGrade1.setText(String.valueOf(userScore)); if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no1); } else { int ranking = score.getIntValue("paiming"); switch (ranking) { case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no1); break; case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no2); break; case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no3); break; case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no4); break; } } } else if (TextUtils.equals(userID, userID2)) { textGrade2.setText(String.valueOf(userScore)); if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no1); } else { int ranking = score.getIntValue("paiming"); switch (ranking) { case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no1); break; case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no2); break; case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no3); break; case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no4); break; } } } else if (TextUtils.equals(userID, userID4)) { textGrade4.setText(String.valueOf(userScore)); if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); + imageGrade4.setImageResource(R.mipmap.icon_livepk_no1); } else { int ranking = score.getIntValue("paiming"); switch (ranking) { case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); + imageGrade4.setImageResource(R.mipmap.icon_livepk_no1); break; case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade4); + imageGrade4.setImageResource(R.mipmap.icon_livepk_no2); break; case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade4); + imageGrade4.setImageResource(R.mipmap.icon_livepk_no3); break; case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade4); + imageGrade4.setImageResource(R.mipmap.icon_livepk_no4); break; } } @@ -1822,84 +1822,84 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { if (TextUtils.equals(userID, userID1)) { textGrade1.setText(String.valueOf(userScore)); if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no1); } else { int ranking = score.getIntValue("paiming"); switch (ranking) { case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no1); break; case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no2); break; case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no3); break; case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no4); break; } } } else if (TextUtils.equals(userID, userID2)) { textGrade2.setText(String.valueOf(userScore)); if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no1); } else { int ranking = score.getIntValue("paiming"); switch (ranking) { case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no1); break; case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no2); break; case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no3); break; case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no4); break; } } } else if (TextUtils.equals(userID, userID4)) { textGrade4.setText(String.valueOf(userScore)); if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); + imageGrade4.setImageResource(R.mipmap.icon_livepk_no1); } else { int ranking = score.getIntValue("paiming"); switch (ranking) { case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade4); + imageGrade4.setImageResource(R.mipmap.icon_livepk_no1); break; case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade4); + imageGrade4.setImageResource(R.mipmap.icon_livepk_no2); break; case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade4); + imageGrade4.setImageResource(R.mipmap.icon_livepk_no3); break; case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade4); + imageGrade4.setImageResource(R.mipmap.icon_livepk_no4); break; } } } else if (TextUtils.equals(userID, userID3)) { textGrade3.setText(String.valueOf(userScore)); if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade3); + imageGrade3.setImageResource(R.mipmap.icon_livepk_no1); } else { int ranking = score.getIntValue("paiming"); switch (ranking) { case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade3); + imageGrade3.setImageResource(R.mipmap.icon_livepk_no1); break; case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade3); + imageGrade3.setImageResource(R.mipmap.icon_livepk_no2); break; case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade3); + imageGrade3.setImageResource(R.mipmap.icon_livepk_no3); break; case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade3); + imageGrade3.setImageResource(R.mipmap.icon_livepk_no4); break; } } @@ -1920,42 +1920,42 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { if (TextUtils.equals(userID, userID1)) { textGrade1.setText(String.valueOf(userScore)); if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no1); } else { int ranking = score.getIntValue("paiming"); switch (ranking) { case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no1); break; case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no2); break; case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no3); break; case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade1); + imageGrade1.setImageResource(R.mipmap.icon_livepk_no4); break; } } } else if (TextUtils.equals(userID, userID2)) { textGrade2.setText(String.valueOf(userScore)); if (!score.containsKey("paiming")) { - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no1); } else { int ranking = score.getIntValue("paiming"); switch (ranking) { case 1: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no1, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no1); break; case 2: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no2, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no2); break; case 3: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no3, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no3); break; case 4: - ImgLoader.display(mContext, R.mipmap.icon_livepk_no4, imageGrade2); + imageGrade2.setImageResource(R.mipmap.icon_livepk_no4); break; } } From a0616374929230b5b4c65baea6b1afbc8dbcc03d Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 1 Jun 2024 14:24:10 +0800 Subject: [PATCH 43/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=A4=9A=E4=BA=BAPK=EF=BC=8C=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E4=B8=BB=E6=92=AD=E4=BF=A1=E6=81=AF=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E4=BB=A3=E7=A0=81]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/yunbao/common/CommonAppConfig.java | 4 ++-- .../io/agora/beautyapi/faceunity/agora/SWAuManager.java | 5 ++--- .../yunbao/live/presenter/LiveSwLinkMicPkPresenter.java | 7 ------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index 325e26afd..2bcb30b32 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -79,9 +79,9 @@ public class CommonAppConfig { public static String SWToken = ""; //声网Token public static final String SWChannelPrefix = "g"; //测试服 - public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; + //public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; //正式服 -// public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; + public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index c174f1492..7a6c7afe8 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -421,10 +421,9 @@ public class SWAuManager extends BaseCacheManager { } public void preloadChannel(List uids){ - L.eSw("设置秒开数据"); for (int i = 0; i drPkbeanList) { L.eSw("setDrPkUserInfoView" + new Gson().toJson(drPkbeanList)); - mHandler.postDelayed(new Runnable() { - @Override - public void run() { for (int j = 0; j < drPkbeanList.size(); j++) { if (j == 0) { L.eSw("j == 0:" + j); @@ -1355,13 +1352,9 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { detailsLinearLayout3.setVisibility(View.GONE); linearGrade3.setVisibility(View.GONE); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - } - } } - }, 1000); L.eSw("dRjoinOtherRoom:size:" + drPkbeanList.size() + " json " + new Gson().toJson(drPkbeanList)); } From 6132338c6cd40883fb0da7acb50231a721307e5c Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 1 Jun 2024 14:33:27 +0800 Subject: [PATCH 44/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=BC=B9=E7=AA=97=E5=8A=9F=E8=83=BD]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 3 + .../java/com/shayu/phonelive/AppContext.java | 10 +- .../phonelive/activity/LauncherActivity.java | 9 +- .../com/yunbao/common/CommonAppConfig.java | 1 + .../com/yunbao/common/bean/OpenAdModel.java | 57 +++-- .../com/yunbao/common/dialog/DebugDialog.java | 9 +- .../dialog/OpenAdBottomDialogPopup.java | 87 +++++++- .../dialog/OpenAdCenterDialogPopup.java | 143 +++++++++++-- .../yunbao/common/manager/OpenAdManager.java | 200 ++++++++++++++++-- .../com/yunbao/common/utils/AppManager.java | 34 ++- .../common/views/APKUpdateCustomPopup.java | 15 ++ .../main/res/layout/dialog_open_bottom_ad.xml | 15 +- .../main/res/layout/dialog_open_center_ad.xml | 24 ++- config.gradle | 12 +- gradle.properties | 8 +- .../live/views/PortraitLiveManager.java | 6 + .../yunbao/main/activity/MainActivity.java | 41 +++- .../com/yunbao/main/dialog/SigninDialog.java | 17 +- .../main/views/MainHomeLiveViewHolder.java | 1 - 19 files changed, 595 insertions(+), 97 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8d8a3325c..0b83186e1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -162,6 +162,9 @@ + diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index f23dc1ea8..af4de4c66 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -30,6 +30,7 @@ import com.tencent.imsdk.v2.V2TIMGroupMemberInfo; import com.tencent.imsdk.v2.V2TIMManager; import com.tencent.imsdk.v2.V2TIMSimpleMsgListener; import com.tencent.imsdk.v2.V2TIMUserInfo; +import com.yunbao.common.manager.OpenAdManager; import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.BuildConfig; import com.yunbao.common.CommonAppConfig; @@ -37,7 +38,6 @@ import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; import com.yunbao.common.bean.AnchorStartLiveBean; import com.yunbao.common.bean.CrashSaveBean; -import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.event.SudGameSocketImEvent; import com.yunbao.common.manager.imrongcloud.InstructorSendReward; import com.yunbao.common.manager.imrongcloud.InstructorSendRewardProvider; @@ -55,6 +55,7 @@ import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.utils.LiveImDeletUtil; import com.yunbao.live.views.PortraitLiveManager; import com.yunbao.live.views.RecommendLiveRoomProvider; +import com.yunbao.main.activity.LoginActivity; import com.yunbao.main.activity.MsgSettActivity; import org.greenrobot.eventbus.EventBus; @@ -109,20 +110,25 @@ public class AppContext extends CommonAppContext { @Override public void onActivityDestroyed(@NonNull Activity activity) { + AppManager.getInstance().removeActivity(activity); for (WeakReference reference : activities) { if (reference.get() == activity) { activities.remove(reference); return; } } - AppManager.getInstance().removeActivity(activity); + } @Override public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { activities.add(new WeakReference<>(activity)); + if(activity instanceof LoginActivity){ + AppManager.getInstance().clear(); + } CrashSaveBean.getInstance().setActivitySize(activities); AppManager.getInstance().addActivity(activity); + OpenAdManager.getInstance().dismiss(); } @Override diff --git a/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java b/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java index f0619923c..7f872d4e3 100644 --- a/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java +++ b/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java @@ -113,6 +113,7 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL res.updateConfiguration(config, res.getDisplayMetrics()); return res; } + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS); @@ -144,7 +145,11 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL } }; mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000); - LogUtil.uploadErrorLog(AppContext.sInstance); + try { + LogUtil.uploadErrorLog(AppContext.sInstance); + } catch (Exception e) { + e.printStackTrace(); + } SpUtil.getInstance().setBooleanValue("NOTIFICATION", NotificationManagerCompat.from(this).areNotificationsEnabled()); } @@ -229,7 +234,7 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL } else { checkUidAndToken(); } - }else{ + } else { ToastUtil.show(getString(R.string.net_error)); } } diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index 2bcb30b32..fb294a2ef 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -37,6 +37,7 @@ public class CommonAppConfig { public static final boolean IS_UPLOAD_ERROR_LOG = getMetaDataBoolean("IS_UPLOAD_ERROR_LOG"); //是否为插件包模式 public static final boolean IS_PLUGIN_MODEL = getMetaDataBoolean("IS_PLUGIN_MODEL"); + public static final String BUILD_TIME = getMetaDataString("BUILD_TIME"); //外部sd卡 public static final String DCMI_PATH = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath(); diff --git a/common/src/main/java/com/yunbao/common/bean/OpenAdModel.java b/common/src/main/java/com/yunbao/common/bean/OpenAdModel.java index 8260ee377..638334d48 100644 --- a/common/src/main/java/com/yunbao/common/bean/OpenAdModel.java +++ b/common/src/main/java/com/yunbao/common/bean/OpenAdModel.java @@ -2,7 +2,6 @@ package com.yunbao.common.bean; import com.google.gson.annotations.SerializedName; import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.StringUtil; import java.text.ParseException; @@ -22,6 +21,8 @@ public class OpenAdModel extends BaseModel { public static final int SHOW_ONE = 3;//3. 仅弹出一次; @SerializedName("id") private int id; + @SerializedName("popup_name") + private String name; @SerializedName("popup_location") private int type = TYPE_HOME; @SerializedName("activity_url") @@ -35,24 +36,27 @@ public class OpenAdModel extends BaseModel { @SerializedName("popup_model") private int model = MODEL_SQUARE; @SerializedName("start_show_time") - private String startTime;//活动开始时间 + private String startTime;//活动开始时间 1 @SerializedName("end_show_time") - private String endTime;//活动结束时间 + private String endTime;//活动结束时间 5 @SerializedName("popup_permission") private int permission; @SerializedName("popup_frequency") private int showModel = SHOW_DEF;//显示模式,1:杀死程序后弹出 2:指定时间内(本机时间) 3:1. 仅弹出一次 @SerializedName("popup_frequency_time") - private String section = "0";// SHOW_DEF = 2 - + private String section = "0";// SHOW_DEF = 2 1 + @SerializedName("popup_sort") + private int popupSort = 1;//弹框类型 1.图片 2.H5 + @SerializedName("sort") + private int sort = 0; public OpenAdModel() { } public static OpenAdModel createTestData() { OpenAdModel model = new OpenAdModel(); - model.id=3; - model.type=1; + model.id = 3; + model.type = 1; model.url = "/h5/GuildTournament/20230821/rank.html"; model.imageUrl = "https://ceshi.yaoulive.com/data/upload/20230913/1694589490.png"; model.showTime = 10; @@ -66,6 +70,30 @@ public class OpenAdModel extends BaseModel { return model; } + public int getPopupSort() { + return popupSort; + } + + public int getSort() { + return sort; + } + + public void setSort(int sort) { + this.sort = sort; + } + + public void setPopupSort(int popupSort) { + this.popupSort = popupSort; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public int getShowModel() { return showModel; } @@ -91,12 +119,13 @@ public class OpenAdModel extends BaseModel { } public String getUrl() { - if (!url.startsWith("http://") || !url.startsWith("https://")) { - url = CommonAppConfig.HOST + url; + if (!url.startsWith("http://") && !url.startsWith("https://")) { + url = CommonAppConfig.HOST + (url.startsWith("/") ? url : "/" + url); } - return url + "?t=" + System.currentTimeMillis() / 1000; + return url; } - public String getOriginalUrl(){ + + public String getOriginalUrl() { return url; } @@ -198,6 +227,7 @@ public class OpenAdModel extends BaseModel { public String toString() { return "OpenAdModel{" + "id=" + id + + ", name='" + name + '\'' + ", type=" + type + ", url='" + url + '\'' + ", imageUrl='" + imageUrl + '\'' + @@ -206,7 +236,10 @@ public class OpenAdModel extends BaseModel { ", model=" + model + ", startTime='" + startTime + '\'' + ", endTime='" + endTime + '\'' + - ", permission='" + permission + '\'' + + ", permission=" + permission + + ", showModel=" + showModel + + ", section='" + section + '\'' + + ", sort=" + popupSort + '}'; } } diff --git a/common/src/main/java/com/yunbao/common/dialog/DebugDialog.java b/common/src/main/java/com/yunbao/common/dialog/DebugDialog.java index 48131bfbf..199516ba6 100644 --- a/common/src/main/java/com/yunbao/common/dialog/DebugDialog.java +++ b/common/src/main/java/com/yunbao/common/dialog/DebugDialog.java @@ -15,18 +15,20 @@ import com.lzf.easyfloat.EasyFloat; import com.lzf.easyfloat.enums.ShowPattern; import com.lzf.easyfloat.interfaces.OnPermissionResult; import com.lzf.easyfloat.permission.PermissionUtils; +import com.yunbao.common.CommonAppConfig; import com.yunbao.common.adapter.DebugDialogAdapter; import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.ToastUtil; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Timer; import java.util.TimerTask; public class DebugDialog { RecyclerView recyclerView; - HashMap params; + LinkedHashMap params; DebugDialogAdapter adapter; private static DebugDialog debugDialog; Context mContext; @@ -69,7 +71,7 @@ public class DebugDialog { this.runnable = runnable; if (params == null) { Log.i("debug弹窗", "DebugDialog: 初始化参数"); - params = new HashMap<>(); + params = new LinkedHashMap<>(); } init(); } @@ -102,6 +104,7 @@ public class DebugDialog { } public void show() { + if (recyclerView != null) return; if (showPattern == ShowPattern.CURRENT_ACTIVITY) { createView(); return; @@ -136,7 +139,7 @@ public class DebugDialog { EasyFloat.updateFloat("debug"); } }); - params.put("debug弹窗", textView); + params.put("发包时间:" + CommonAppConfig.BUILD_TIME, textView); adapter.setParamMap(params); EasyFloat.with(mContext) diff --git a/common/src/main/java/com/yunbao/common/dialog/OpenAdBottomDialogPopup.java b/common/src/main/java/com/yunbao/common/dialog/OpenAdBottomDialogPopup.java index 072ab97a8..e878da2d2 100644 --- a/common/src/main/java/com/yunbao/common/dialog/OpenAdBottomDialogPopup.java +++ b/common/src/main/java/com/yunbao/common/dialog/OpenAdBottomDialogPopup.java @@ -1,7 +1,11 @@ package com.yunbao.common.dialog; +import android.app.Activity; import android.content.Context; +import android.webkit.WebView; +import android.webkit.WebViewClient; import android.widget.ImageView; +import android.widget.LinearLayout; import androidx.annotation.NonNull; @@ -9,12 +13,21 @@ import com.lxj.xpopup.XPopup; import com.yunbao.common.R; import com.yunbao.common.activity.WebViewActivity; import com.yunbao.common.bean.OpenAdModel; +import com.yunbao.common.event.JavascriptInterfaceEvent; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.JavascriptInterfaceUtils; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.ScreenDimenUtil; + +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; public class OpenAdBottomDialogPopup extends AbsDialogPopupWindow { - private ImageView mImageView; private ImageView mClose; + private LinearLayout contentLayout; private OpenAdModel model; private OnItemClickListener mListener; @@ -27,6 +40,11 @@ public class OpenAdBottomDialogPopup extends AbsDialogPopupWindow { @Override public void buildDialog(XPopup.Builder builder) { builder.animationDuration(0); + builder.hasShadowBg(true); + if(model.getPopupSort()==2){ + builder.dismissOnTouchOutside(false); + builder.dismissOnBackPressed(false); + } } @Override @@ -51,8 +69,63 @@ public class OpenAdBottomDialogPopup extends AbsDialogPopupWindow { @Override protected void onCreate() { super.onCreate(); - mImageView = findViewById(R.id.img); + contentLayout = findViewById(R.id.content_layout); mClose = findViewById(R.id.close); + if (model.getPopupSort() == 1) { + setImage(); + } else { + setWeb(); + } + + mClose.setOnClickListener(v -> dismiss()); + if (model.getShowTime() > 0) { + mClose.postDelayed(this::dismiss, model.getShowTime()); + } + } + + private void setWeb() { + WebView mWebView = new WebView(mContext); + mWebView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); + mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext((Activity) mContext, mWebView).setPageClose(true).setLiveZhuangBana(false), "androidObject"); + mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口 + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.getSettings().setDomStorageEnabled(true); + String appCachePath = mContext.getCacheDir().getAbsolutePath(); +// mWebView.getSettings().setAppCachePath(appCachePath); + mWebView.getSettings().setAllowFileAccess(true); + mWebView.getSettings().setUseWideViewPort(true); // 关键点 + mWebView.getSettings().setAllowFileAccess(true); // 允许访问文件 + mWebView.setHorizontalScrollBarEnabled(false); + mWebView.setVerticalScrollBarEnabled(false); + mWebView.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + L.e("H5-------->" + url); + view.loadUrl(url); + + return true; + } + + @Override + public void onPageFinished(WebView view, String url) { + } + }); + String url=model.getUrl(); + if(url.contains("?")){ + url+="&uid="+ IMLoginManager.get(mContext).getUserInfo().getId()+"&token="+IMLoginManager.get(mContext).getUserInfo().getToken(); + }else{ + url+="?uid="+ IMLoginManager.get(mContext).getUserInfo().getId()+"&token="+IMLoginManager.get(mContext).getUserInfo().getToken(); + } + mWebView.loadUrl(url); + contentLayout.addView(mWebView); + } + + private void setImage() { + int width = ScreenDimenUtil.getInstance().getScreenWdith(); + int height = (int) (width * 1.4); + + ImageView mImageView = new ImageView(mContext); + mImageView.setLayoutParams(new LinearLayout.LayoutParams(width, height)); mImageView.setOnClickListener(v -> { WebViewActivity.forward(mContext, model.getUrl(), model.getType() != OpenAdModel.TYPE_HOME); if (mListener != null) { @@ -61,10 +134,12 @@ public class OpenAdBottomDialogPopup extends AbsDialogPopupWindow { } dismiss(); }); - mClose.setOnClickListener(v -> dismiss()); ImgLoader.display(mContext, model.getImageUrl(), mImageView); - if (model.getShowTime() > 0) { - mClose.postDelayed(this::dismiss, model.getShowTime()); - } + contentLayout.addView(mImageView); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onJavascriptInterfaceEvent(JavascriptInterfaceEvent event) { + } } diff --git a/common/src/main/java/com/yunbao/common/dialog/OpenAdCenterDialogPopup.java b/common/src/main/java/com/yunbao/common/dialog/OpenAdCenterDialogPopup.java index d5a0de407..046494ea8 100644 --- a/common/src/main/java/com/yunbao/common/dialog/OpenAdCenterDialogPopup.java +++ b/common/src/main/java/com/yunbao/common/dialog/OpenAdCenterDialogPopup.java @@ -1,24 +1,44 @@ package com.yunbao.common.dialog; +import android.app.Activity; import android.content.Context; +import android.graphics.Color; import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.view.WindowInsets; +import android.webkit.WebResourceRequest; +import android.webkit.WebView; +import android.webkit.WebViewClient; import android.widget.ImageView; +import android.widget.LinearLayout; import androidx.annotation.NonNull; -import androidx.constraintlayout.widget.ConstraintLayout; import com.lxj.xpopup.XPopup; +import com.lzf.easyfloat.enums.ShowPattern; import com.yunbao.common.R; import com.yunbao.common.activity.WebViewActivity; import com.yunbao.common.bean.OpenAdModel; +import com.yunbao.common.event.JavascriptInterfaceEvent; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.JavascriptInterfaceUtils; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.utils.ScreenDimenUtil; +import com.yunbao.common.utils.ToastUtil; + +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; public class OpenAdCenterDialogPopup extends AbsDialogFullScreenPopupWindow { private ImageView mImageView; + private LinearLayout contentLayout; private ImageView mClose; private OpenAdModel model; private OnItemClickListener mListener; @@ -39,7 +59,8 @@ public class OpenAdCenterDialogPopup extends AbsDialogFullScreenPopupWindow { @Override public void buildDialog(XPopup.Builder builder) { - builder.hasShadowBg(false); + builder.hasShadowBg(true); + builder.shadowBgColor(Color.parseColor("#80000000")); builder.animationDuration(0); } @@ -61,12 +82,103 @@ public class OpenAdCenterDialogPopup extends AbsDialogFullScreenPopupWindow { @Override protected void onCreate() { super.onCreate(); - Log.e("-----弹窗-----", "onCreate: 创建弹窗" ); - mImageView = findViewById(R.id.img); + Log.e("-----弹窗-----", "onCreate: 创建弹窗"); + contentLayout = findViewById(R.id.content_layout); mClose = findViewById(R.id.close); - findViewById(R.id.layout).setOnClickListener(v -> dismiss()); + + + contentLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + boolean isShow = false; + + @Override + public void onGlobalLayout() { + if (isShow) + return; + isShow = true; + int width = contentLayout.getWidth() - DpUtil.dp2px(20); + int height = (int) (width * 1.5); + if (model.getModel() == OpenAdModel.MODEL_SQUARE) { + height = (int) (width * 1.2); + } + Log.i("-----弹窗-----", "高度:" + height + " 宽度:" + width + " 屏幕宽度: " + ScreenDimenUtil.getInstance().getScreenWdith()); + /*DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { + @Override + public void run(DebugDialog dialog) { + dialog.setShowPattern(ShowPattern.ALL_TIME); + dialog.show(); + int width = contentLayout.getWidth() - DpUtil.dp2px(10); + int height = (int) (width * 1.5); + if (model.getModel() == OpenAdModel.MODEL_SQUARE) { + height = (int) (width * 1.2); + } + Log.i("-----弹窗-----", "弹框debug高宽 高度:" + height + " 宽度:" + width); + dialog.setParams(model.getName() + "弹框高宽", "高度:" + height + " 宽度:" + width); + } + });*/ + if (model.getPopupSort() == 1) { + setImage(model, width, height); + findViewById(R.id.layout).setOnClickListener(v -> dismiss()); + } else { + setWeb(model, width, height); + } + mClose.setOnClickListener(v -> dismiss()); + if (model.getShowTime() > 0) { + mClose.postDelayed(OpenAdCenterDialogPopup.this::dismiss, model.getShowTime()); + } + } + }); + + } + + private void setWeb(OpenAdModel model, int width, int height) { + WebView mWebView = new WebView(mContext); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height); + params.gravity = Gravity.CENTER; + mWebView.setLayoutParams(params); + mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext((Activity) mContext, mWebView).setPageClose(true).setLiveZhuangBana(false), "androidObject"); + mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口 + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.getSettings().setDomStorageEnabled(true); + String appCachePath = mContext.getCacheDir().getAbsolutePath(); +// mWebView.getSettings().setAppCachePath(appCachePath); + mWebView.getSettings().setAllowFileAccess(true); + mWebView.getSettings().setUseWideViewPort(true); // 关键点 + mWebView.getSettings().setAllowFileAccess(true); // 允许访问文件 + mWebView.setHorizontalScrollBarEnabled(false); + mWebView.setVerticalScrollBarEnabled(false); + mWebView.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + L.e("H5-------->" + url); + view.loadUrl(url); + + return true; + } + + @Override + public void onPageFinished(WebView view, String url) { + } + }); + String url = model.getUrl(); + if (url.contains("?")) { + url += "&uid=" + IMLoginManager.get(mContext).getUserInfo().getId() + "&token=" + IMLoginManager.get(mContext).getUserInfo().getToken(); + } else { + url += "?uid=" + IMLoginManager.get(mContext).getUserInfo().getId() + "&token=" + IMLoginManager.get(mContext).getUserInfo().getToken(); + } + Log.i("-----弹窗-----", "setWeb: " + url); + mWebView.loadUrl(url); + contentLayout.addView(mWebView); + } + + private void setImage(OpenAdModel model, int width, int height) { + mImageView = new ImageView(mContext); + mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height); + params.gravity = Gravity.CENTER; + mImageView.setLayoutParams(params); + mImageView.setOnClickListener(v -> { - if("home_page_banner_battle".equals(model.getOriginalUrl())){ + if ("home_page_banner_battle".equals(model.getOriginalUrl())) { RouteUtil.forwardBattlePass(); dismiss(); return; @@ -78,19 +190,12 @@ public class OpenAdCenterDialogPopup extends AbsDialogFullScreenPopupWindow { } dismiss(); }); - mClose.setOnClickListener(v -> dismiss()); ImgLoader.display(mContext, model.getImageUrl(), mImageView); - int width = ScreenDimenUtil.getInstance().getScreenWdith() - DpUtil.dp2px(40); - int height = (int) (width * 1.4); - if (model.getModel() == OpenAdModel.MODEL_SQUARE) { - height = width; - } - ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) mImageView.getLayoutParams(); - params.width = width; - params.height = height; - mImageView.setLayoutParams(params); - if (model.getShowTime() > 0) { - mClose.postDelayed(this::dismiss, model.getShowTime()); - } + contentLayout.addView(mImageView); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onJavascriptInterfaceEvent(JavascriptInterfaceEvent event) { + } } diff --git a/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java b/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java index 46242290d..b49247ddd 100644 --- a/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java +++ b/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java @@ -1,25 +1,34 @@ package com.yunbao.common.manager; +import android.app.Activity; import android.content.Context; import android.os.Handler; import android.os.Looper; import android.util.Log; +import com.lzf.easyfloat.enums.ShowPattern; import com.yunbao.common.CommonAppContext; import com.yunbao.common.bean.OpenAdModel; +import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.dialog.OpenAdBottomDialogPopup; import com.yunbao.common.dialog.OpenAdCenterDialogPopup; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.SpUtil; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; +import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Objects; public class OpenAdManager { public static final int TYPE_HOME = 1; @@ -28,19 +37,34 @@ public class OpenAdManager { private Map showMap; private List list = null; private Handler handler = new Handler(Looper.getMainLooper()); - private Map runnableMap = new HashMap<>(); + private Map runnableMap = new LinkedHashMap<>(); + private Map waitRunnableMap = new LinkedHashMap<>();//等待运行的弹窗 private int showType; + private WeakReference runNowRunnable; + private static final boolean IS_QUEUE_SHOW = true;//是否按队列显示弹窗,true就会等待上一个弹窗关闭后弹出,false就按原逻辑顺序直接弹出 private OpenAdManager() { showMap = new HashMap<>(); init(false); } - public void reset() { + public void close() { dismiss(); + clear(); + } + + public void clear() { runnableMap.clear(); showMap.clear(); list.clear(); + waitRunnableMap.clear(); + list = null; + runNowRunnable = null; + } + + public void reset() { + Log.i(TAG, "reset: "); + next(); } private static final class MInstanceHolder { @@ -55,13 +79,14 @@ public class OpenAdManager { if (list != null && list.isEmpty()) { return; } - Context context = CommonAppContext.getTopActivity(); + Context context = AppManager.getInstance().getMainActivity(); if (context == null) { context = CommonAppContext.sInstance; } if (context == null) { return; } + LiveNetManager.get(context).activityPopup(new HttpCallback>() { @Override public void onSuccess(List data) { @@ -70,35 +95,64 @@ public class OpenAdManager { list = new ArrayList<>(); return; } + Collections.sort(data, new AdListComparator()); list = data; if (isShow) { - show(TYPE_HOME, false); + if (showType == 0) { + show(TYPE_HOME, false); + } else { + show(showType, false); + } } } @Override public void onError(String error) { - System.err.println("弹框列表:" + error); + Log.e(TAG, "弹框列表:" + error); } }); } - private static long showTime=0; + private static long showTime = 0; + private OnItemClickListener onItemClickListener=new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + + } + }; + public synchronized void show(int type, boolean isGuard) { + showType = type; if (list == null) { init(true); return; } - if(System.currentTimeMillis()-showTime<100){ + Log.i(TAG, "show: 调用显示 " + type + " " + isGuard); + if (System.currentTimeMillis() - showTime < 100) { return; } - showTime=System.currentTimeMillis(); - showType = type; + /*DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { + @Override + public void run(DebugDialog dialog) { + dialog.setShowPattern(ShowPattern.ALL_TIME); + dialog.show(); + onItemClickListener = new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + dialog.setParams(bean, "剩余:" + position); + } + }; + } + });*/ + showTime = System.currentTimeMillis(); + waitRunnableMap.clear(); + runnableMap.clear(); + runNowRunnable = null; for (OpenAdModel model : list) { if (model.getType() == type) { - if (type == OpenAdModel.TYPE_LIVE && !model.userIsPermission(isGuard)) { + /* if (type == OpenAdModel.TYPE_LIVE && !model.userIsPermission(isGuard)) { continue; - } + }*/ if (model.getShowModel() == OpenAdModel.SHOW_ONE) { if (SpUtil.getInstance().getBooleanValue("open_ad_popup_" + model.getId())) { continue; @@ -122,13 +176,22 @@ public class OpenAdManager { if (!isShow(model)) { Log.i(TAG, "show: " + model); - handler.postDelayed(new AdRunnable(model), model.getDelayShowTime()); + if (IS_QUEUE_SHOW) { + waitRunnableMap.put(new AdRunnable(model), model.getDelayShowTime()); + } else { + handler.postDelayed(new AdRunnable(model), model.getDelayShowTime()); + } } else { Log.i(TAG, "notshow: " + model); } } } + Log.i(TAG, "show: 循环完毕,调用next"); + if (IS_QUEUE_SHOW) { + onItemClickListener.onItemClick("接口返回需要展示的弹窗数:", waitRunnableMap.size()); + next(); + } Log.i(TAG, "------------------------------"); } @@ -144,6 +207,9 @@ public class OpenAdManager { } } runnableMap.clear(); + if (runNowRunnable != null && runNowRunnable.get() != null) { + handler.removeCallbacks(runNowRunnable.get()); + } } private synchronized boolean isShow(OpenAdModel type) { @@ -153,11 +219,45 @@ public class OpenAdManager { return false; } + int getNowType() { + Activity lastActivity = AppManager.getInstance().getLastActivity(); + if (lastActivity == null) { + return -1; + } + if (AppManager.getInstance().isLiveActivity()) { + return TYPE_LIVE; + } else if (AppManager.getInstance().isMainActivity()) { + return TYPE_HOME; + } + return -2; + } + + void next() { + Log.i(TAG, "next: 剩余数" + waitRunnableMap.size()); + if (waitRunnableMap.isEmpty()) return; + for (AdRunnable next : waitRunnableMap.keySet()) { + Log.i(TAG, "next: " + next.model); + if (next.model.getType() == getNowType()) { + Integer i = waitRunnableMap.get(next); + if (i == null) { + i = 0; + } + onItemClickListener.onItemClick("当前加载id:" + next.model.getId() + " " + next.model.getName() + " 延迟展示时间:" + i, (waitRunnableMap.size() - 1)); + handler.postDelayed(next, i); + return; + } + } + + } + private class AdRunnable implements Runnable { OpenAdModel model; + AdRunnable runnable; public AdRunnable(OpenAdModel model) { this.model = model; + this.runnable = this; + runNowRunnable = new WeakReference<>(this); runnableMap.put(model.getId(), this); } @@ -170,36 +270,100 @@ public class OpenAdManager { Log.i(TAG, "run: " + model); if (model == null) { ToastUtil.showDebug("model为空"); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } return; } if (!model.isInTime()) { ToastUtil.showDebug("不在展示时间内:" + model.getStartTime() + "|" + model.getEndTime()); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } return; } if (isShow(model)) { ToastUtil.showDebug(model.getId() + "|model展示过了"); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } return; } if (model.getType() != showType) { + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } return; } - if(isShow(model)){ - Log.i(TAG,"展示过:"+model); + if (isShow(model)) { + Log.i(TAG, "展示过:" + model); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } return; } + if (model.getType() == OpenAdModel.TYPE_HOME && !AppManager.getInstance().isMainActivity()) { + Log.i(TAG, "首页类型弹窗,但当前不是首页"); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } + dismiss(); + return; + } + if (model.getType() == TYPE_LIVE && !AppManager.getInstance().isLiveActivity()) { + Log.i(TAG, "直播类型弹窗,但当前不是直播"); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } + dismiss(); + return; + } + showMap.put(model.getId(), true); if (model.getShowModel() == OpenAdModel.SHOW_DIY) { - String nextTime= String.valueOf(System.currentTimeMillis() + (Long.parseLong(model.getSection()) * 60 * 1000)); + String nextTime = String.valueOf(System.currentTimeMillis() + (Long.parseLong(model.getSection()) * 60 * 1000)); SpUtil.setStringValue("open_ad_popup_time_" + model.getId(), nextTime); showMap.remove(model.getId()); } if (model.getModel() == OpenAdModel.MODEL_BOTTOM) { - new OpenAdBottomDialogPopup(CommonAppContext.getTopActivity(), model).setListener((bean, position) -> { + new OpenAdBottomDialogPopup(AppManager.getInstance().getLastActivity(), model).setListener((bean, position) -> { + Log.i(TAG, "run: 弹框回调:" + position + " id = " + model.getId()); + if (IS_QUEUE_SHOW) { + removeList(bean); + if (position == 0) { + next(); + } + } }).showDialog(); } else { - new OpenAdCenterDialogPopup(CommonAppContext.getTopActivity(), model).setListener((bean, position) -> { + new OpenAdCenterDialogPopup(AppManager.getInstance().getLastActivity(), model).setListener((bean, position) -> { + Log.i(TAG, "run: 弹框回调:" + position + " id = " + model.getId()); + if (IS_QUEUE_SHOW) { + removeList(bean); + if (position == 0) { + next(); + } + } }).showDialog(); } } + + void removeList(OpenAdModel model) { + Log.i(TAG, "removeList: " + model); + for (AdRunnable next : waitRunnableMap.keySet()) { + if (next.model.getId() == model.getId()) { + waitRunnableMap.remove(next); + return; + } + } + } + } + + private class AdListComparator implements Comparator { + + @Override + public int compare(OpenAdModel openAdModel, OpenAdModel t1) { + return openAdModel.getSort() - t1.getSort(); + } } } diff --git a/common/src/main/java/com/yunbao/common/utils/AppManager.java b/common/src/main/java/com/yunbao/common/utils/AppManager.java index f27c2815a..33c5c65c4 100644 --- a/common/src/main/java/com/yunbao/common/utils/AppManager.java +++ b/common/src/main/java/com/yunbao/common/utils/AppManager.java @@ -1,8 +1,10 @@ package com.yunbao.common.utils; import android.app.Activity; +import android.util.Log; import com.yunbao.common.BuildConfig; +import com.yunbao.common.manager.OpenAdManager; import java.util.Stack; @@ -11,7 +13,7 @@ public class AppManager { private static Stack activityStack; public AppManager() { - activityStack=new Stack<>(); + activityStack = new Stack<>(); } /** @@ -36,18 +38,40 @@ public class AppManager { return activity; } } - return null; + return getLastActivity(); } public Activity getLiveActivity() { for (Activity activity : activityStack) { - if (activity.getClass().getSimpleName().contains("LiveAudienceActivity")) { + if (activity.getClass().getSimpleName().contains("LiveActivity")) { return activity; } } return null; } + public void clear() { + activityStack.clear(); + OpenAdManager.getInstance().clear(); + } + + public boolean isMainActivity() { + Activity lastActivity = getLastActivity(); + if (lastActivity == null) { + return false; + } + return lastActivity.getClass().getSimpleName().contains("MainActivity"); + } + + //TODO 首页类型没展示完进直播间会不展示直播间的。 + public boolean isLiveActivity() { + Activity lastActivity = getLastActivity(); + if (lastActivity == null) { + return false; + } + return lastActivity.getClass().getSimpleName().contains("LiveAudienceActivity"); + } + public static class SingleApp { public static AppManager INSTANCE = new AppManager(); } @@ -59,6 +83,10 @@ public class AppManager { if (activityStack == null) { activityStack = new Stack(); } + //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>class com.yunbao.main.activity.MsgAddressBookActivity + if (getActivity(activity.getClass()) != null) { + activityStack.remove(getActivity(activity.getClass())); + } activityStack.add(activity); } diff --git a/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java b/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java index f860e2203..7747bfa9b 100644 --- a/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java +++ b/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java @@ -2,6 +2,7 @@ package com.yunbao.common.views; import android.app.Activity; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; @@ -44,6 +45,7 @@ public class APKUpdateCustomPopup extends CenterPopupView { private ProgressBar progressBar; private Activity mContext; private boolean mInside; + private DialogInterface.OnDismissListener onDismissListener; public APKUpdateCustomPopup(@NonNull Activity context, boolean inside) { super(context); @@ -57,6 +59,11 @@ public class APKUpdateCustomPopup extends CenterPopupView { return R.layout.apk_update_custom_popup; } + public APKUpdateCustomPopup setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) { + this.onDismissListener = onDismissListener; + return this; + } + // 执行初始化操作,比如:findView,设置点击,或者任何你弹窗内的业务逻辑 @Override protected void onCreate() { @@ -69,6 +76,14 @@ public class APKUpdateCustomPopup extends CenterPopupView { } + @Override + protected void onDismiss() { + super.onDismiss(); + if (onDismissListener != null) { + onDismissListener.onDismiss(null); + } + } + private void initView() { if (!mInside) { if (CommonAppConfig.IS_GOOGLE_PLAY == 0 && APKManager.get().getAPKGoogleIsUp() == 1) { diff --git a/common/src/main/res/layout/dialog_open_bottom_ad.xml b/common/src/main/res/layout/dialog_open_bottom_ad.xml index 192f2d295..07cbd6f4f 100644 --- a/common/src/main/res/layout/dialog_open_bottom_ad.xml +++ b/common/src/main/res/layout/dialog_open_bottom_ad.xml @@ -5,16 +5,19 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + app:srcCompat="@mipmap/background_gift_wall"> + + + + diff --git a/common/src/main/res/layout/dialog_open_center_ad.xml b/common/src/main/res/layout/dialog_open_center_ad.xml index dd60e83a6..8e078bb5d 100644 --- a/common/src/main/res/layout/dialog_open_center_ad.xml +++ b/common/src/main/res/layout/dialog_open_center_ad.xml @@ -6,26 +6,28 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + + \ No newline at end of file diff --git a/config.gradle b/config.gradle index 14d48a2a1..dc8bef34b 100644 --- a/config.gradle +++ b/config.gradle @@ -4,15 +4,17 @@ ext { buildToolsVersion: "29.0.2", minSdkVersion : 21, targetSdkVersion : 33, - versionCode : 473, - versionName : "6.6.8" + versionCode : 474, + versionName : "6.7.8" ] manifestPlaceholders = [ //正式、 -// serverHost : "https://napi.yaoulive.com", + //serverHost : "https://napi.yaoulive.com", // 测试 serverHost : "https://ceshi.yaoulive.com", + buildTime : new Date().format("MM-dd HH:mm", TimeZone.getTimeZone("GMT+8")), + //百度语音识别 baiduAppId : "23774720", @@ -21,10 +23,10 @@ ext { baiduAppSecretKey: "nEVSgmuGpU0pjPr6VleEGGAl0hzGW52S", // true表示谷歌支付 false 0 链接包 1 谷歌包 2华为包 3 samsung包 - isGooglePlay : 0, + isGooglePlay : 1, //是否上报异常日志 isUploadLog : true, //是否打包成插件包模式 - isPluginModel : true, + isPluginModel : false, ] } diff --git a/gradle.properties b/gradle.properties index 64e5acf4c..f8c588910 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,10 +21,10 @@ org.gradle.configureondemand=true android.useAndroidX=true android.enableJetifier=true -#systemProp.http.proxyHost=127.0.0.1 -#systemProp.https.proxyHost=127.0.0.1 -#systemProp.https.proxyPort=10809 -#systemProp.http.proxyPort=10809 +systemProp.http.proxyHost=127.0.0.1 +systemProp.https.proxyHost=127.0.0.1 +systemProp.https.proxyPort=10809 +systemProp.http.proxyPort=10809 #android.enableR8.fullMode=true \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 7f4226ec7..b0fb6b6ec 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -15,6 +15,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; @@ -27,8 +28,10 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.GsonUtils; import com.lzf.easyfloat.EasyFloat; +import com.lzf.easyfloat.enums.ShowPattern; import com.lzf.easyfloat.permission.PermissionUtils; import com.lzf.easyfloat.utils.LifecycleUtils; +import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.CommonAppConfig; @@ -115,6 +118,7 @@ import com.yunbao.live.socket.SocketSwChatUtil; import com.yunbao.live.socket.SocketSwClient; import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.utils.LiveImDeletUtil; +import com.yunbao.live.utils.LiveTextRender; import org.greenrobot.eventbus.EventBus; @@ -333,6 +337,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe loading.setVisibility(View.GONE); enterRoomLeaveHandler.post(enterRoomLeaveRunnable); OpenAdManager.getInstance().show(OpenAdManager.TYPE_LIVE, LiveGuardInfo.isGuard(mLiveGuardInfo)); + } }; final Runnable loadTimeoutRunnableGone = new Runnable() { @@ -341,6 +346,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe loading.setVisibility(View.GONE); enterRoomLeaveHandler.post(enterRoomLeaveRunnable); //ToastUtil.show(mContext.getString(R.string.net_error) + " :500");//异常下播,等待加载时间过了后弹出 + OpenAdManager.getInstance().show(OpenAdManager.TYPE_LIVE, LiveGuardInfo.isGuard(mLiveGuardInfo)); } }; diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index e713a8fc0..25f7664a3 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -12,6 +12,7 @@ import android.app.NotificationChannel; import android.app.PendingIntent; import android.content.ClipData; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Build; @@ -224,7 +225,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene SWAuManager.get().initRtcEngine(this); ActivityCompat.postponeEnterTransition(this); ConversationIMListManager.get(this); - OpenAdManager.getInstance(); //在请求一下这个接口给我后台版本号 CommonHttpUtil.getConfig(mContext, new CommonCallback() { @Override @@ -363,6 +363,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene } break; } + OpenAdManager.getInstance().show(OpenAdManager.TYPE_HOME, false); if (mTabButtonGroup.getCurPosition() != position) { System.err.println("重连IM:" + IMLoginManager.isLogin(mContext)); if (!IMLoginManager.isLogin(mContext)) { @@ -845,7 +846,15 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene if (!APKManager.get().getApkVerNew()) { new XPopup.Builder(mContext).isDestroyOnDismiss(true).dismissOnBackPressed(false) // 按返回键是否关闭弹窗,默认为true .dismissOnTouchOutside(false) // 点击外部是否关闭弹窗,默认为true - .asCustom(new APKUpdateCustomPopup(mContext, false)).show(); + .asCustom( + new APKUpdateCustomPopup(mContext, false) + .setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialogInterface) { + requestBonus(); + } + }) + ).show(); } } else { requestBonus(); @@ -855,6 +864,10 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene }); } + private void initAdOpenWindows() { + OpenAdManager.getInstance().show(OpenAdManager.TYPE_HOME, false); + } + /** * 填写邀请码 */ @@ -885,14 +898,21 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene * 签到奖励 */ SigninDialog fragment; + boolean isRequestBonus = false; private void requestBonus() { fragment = new SigninDialog(); MainHttpUtil.requestNewBonus(new HttpCallback() { @Override - public void onSuccess(int code, String msg, String[] info) { + public void onError() { + super.onError(); + isRequestBonus = true; + } + @Override + public void onSuccess(int code, String msg, String[] info) { + isRequestBonus = true; if (info.length > 0) { JSONObject obj = JSON.parseObject(info[0]); if (code == 0) { @@ -901,14 +921,24 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene bundle.putString("send_exp", obj.getString("send_exp")); bundle.putString("sign_day", obj.getString("sign_day")); fragment.setArguments(bundle); + fragment.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialogInterface) { + initAdOpenWindows(); + } + }); if (!getSupportFragmentManager().isStateSaved()) { fragment.show(getSupportFragmentManager(), "SigninDialog"); } + } else { + initAdOpenWindows(); } if (obj != null && obj.containsKey("msg_zdy_send") && obj.containsKey("msg_zdy_send_text")) { Log.e("MainActivity333", info[0]); NoviceInstructorManager.get(mContext).getNetNoviceInstructor(info[0]); } + } else { + initAdOpenWindows(); } } }); @@ -942,6 +972,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene NoviceInstructorManager.get(mContext).getNoviceInstructor(); NoviceInstructorManager.get(mContext).checktHomeZdyPop(); initAnchorRecommendBanner(); + if (isRequestBonus) { + initAdOpenWindows(); + } } /** @@ -1140,7 +1173,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene if (EasyFloat.isShow("LiveFloatView")) { EasyFloat.dismiss("LiveFloatView", true); } - OpenAdManager.getInstance().reset(); + OpenAdManager.getInstance().close(); super.onBackPressed(); } } diff --git a/main/src/main/java/com/yunbao/main/dialog/SigninDialog.java b/main/src/main/java/com/yunbao/main/dialog/SigninDialog.java index 219ede7e6..85c3969fb 100644 --- a/main/src/main/java/com/yunbao/main/dialog/SigninDialog.java +++ b/main/src/main/java/com/yunbao/main/dialog/SigninDialog.java @@ -3,6 +3,7 @@ package com.yunbao.main.dialog; import static com.yunbao.common.utils.RouteUtil.PATH_REWARD; import android.annotation.SuppressLint; +import android.content.DialogInterface; import android.os.Bundle; import android.view.Gravity; import android.view.View; @@ -20,12 +21,18 @@ import com.yunbao.main.R; public class SigninDialog extends AbsDialogFragment { TextView gold, sign_day; + private DialogInterface.OnDismissListener onDismissListener; @Override protected int getLayoutId() { return R.layout.signin_dialog; } + public SigninDialog setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) { + this.onDismissListener = onDismissListener; + return this; + } + @Override protected int getDialogStyle() { return R.style.dialog; @@ -58,7 +65,7 @@ public class SigninDialog extends AbsDialogFragment { goto_sign.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - ARouter.getInstance().build(PATH_REWARD).withString("url", CommonAppConfig.HOST + "/index.php?g=Appapi&m=task&a=index" + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken()+ "&isZh=" + (WordUtil.isNewZh() ? "1" : "0")).navigation(); + ARouter.getInstance().build(PATH_REWARD).withString("url", CommonAppConfig.HOST + "/index.php?g=Appapi&m=task&a=index" + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + (WordUtil.isNewZh() ? "1" : "0")).navigation(); dismiss(); } @@ -79,4 +86,12 @@ public class SigninDialog extends AbsDialogFragment { sign_day.setText(String.format(getString(R.string.this_month), bundle.getString("sign_day"))); } + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + if (onDismissListener != null) { + onDismissListener.onDismiss(dialog); + } + } } diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index 2301f50be..a4f390768 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -567,7 +567,6 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement @Override public void onResume() { super.onResume(); - OpenAdManager.getInstance().show(OpenAdManager.TYPE_HOME, false); } @Override From efce2ad93c618aaac0b347d8965c969290e25b09 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 1 Jun 2024 15:21:23 +0800 Subject: [PATCH 45/64] =?UTF-8?q?fix[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=AB=96=E5=B1=8F]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beautyapi/faceunity/agora/SWManager.java | 63 ++++++------------- .../presenter/LiveSwLinkMicPkPresenter.java | 2 +- .../yunbao/live/socket/SocketSwClient.java | 2 +- .../live/views/LiveNewReadySwViewHolder.java | 4 +- 4 files changed, 23 insertions(+), 48 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index a4946015f..0b09da2f2 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -91,7 +91,7 @@ public class SWManager extends BaseCacheManager { uid = Integer.parseInt(strUid); } try { - if(mRtcEngine==null){ + if (mRtcEngine == null) { // 创建 RtcEngineConfig 对象,并进行配置 RtcEngineConfig config = new RtcEngineConfig(); config.mContext = mContext; @@ -111,21 +111,20 @@ public class SWManager extends BaseCacheManager { mRtcEngine.startPreview(); cfg = new VideoEncoderConfiguration(); + //设置默认分辨率 - switch (IMLoginManager.get(mContext).getSelectClarity()) { - case 0: - cfg.dimensions = VideoEncoderConfiguration.VD_840x480; - break; - case 1: - cfg.dimensions = VideoEncoderConfiguration.VD_1280x720; - break; - case 2: - cfg.dimensions = VideoEncoderConfiguration.VD_1920x1080; - break; - } + VideoEncoderConfiguration.VideoDimensions videoDimensions = new VideoEncoderConfiguration.VideoDimensions(); + videoDimensions.width = 720; + videoDimensions.height = 1280; + cfg.dimensions = videoDimensions; + cfg.frameRate = 20; cfg.bitrate = 0; - cfg.mirrorMode = VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_ENABLED; //镜像 + //镜像 + cfg.mirrorMode = VideoEncoderConfiguration.MIRROR_MODE_TYPE.MIRROR_MODE_ENABLED; + //设置竖屏 + cfg.orientationMode = VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_FIXED_PORTRAIT; + mRtcEngine.setVideoEncoderConfiguration(cfg); // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 @@ -158,33 +157,9 @@ public class SWManager extends BaseCacheManager { * 2人连麦PK:360x640 * 3人连麦PK:左侧主播 360x640,右侧两个主播 360x320 * 4人连麦PK:360X320 + * * @param selectClarity */ - public void setDimensions(int selectClarity) { - if (cfg != null && mRtcEngine != null) { - switch (selectClarity) { - case 0: - cfg.dimensions = VideoEncoderConfiguration.VD_840x480; - L.eSw("VideoEncoderConfiguration.VD_840x480"); - break; - case 1: - cfg.dimensions = VideoEncoderConfiguration.VD_1280x720; - L.eSw("VideoEncoderConfiguration.VD_1280x720"); - break; - case 2: - cfg.dimensions = VideoEncoderConfiguration.VD_1920x1080; - L.eSw("VideoEncoderConfiguration.VD_1920x1080"); - break; - case 3: - cfg.dimensions = VideoEncoderConfiguration.VD_320x240; - L.eSw("VideoEncoderConfiguration.VD_320x240"); - break; - } - mRtcEngine.setVideoEncoderConfiguration(cfg); - } - } - - public void setDrPkNumClarity(int selectClarity) { if (cfg != null && mRtcEngine != null) { VideoEncoderConfiguration.VideoDimensions videoDimensions = new VideoEncoderConfiguration.VideoDimensions(); @@ -211,9 +186,6 @@ public class SWManager extends BaseCacheManager { } - - - /** * 设置镜像模式 */ @@ -344,7 +316,7 @@ public class SWManager extends BaseCacheManager { @Override public void onVideoSizeChanged(Constants.VideoSourceType source, int uid, int width, int height, int rotation) { super.onVideoSizeChanged(source, uid, width, height, rotation); - L.eSw("uid:"+uid+"\nwidth:"+width+"\nheight:"+height); + L.eSw("uid:" + uid + "\nwidth:" + width + "\nheight:" + height); } }); } @@ -358,7 +330,7 @@ public class SWManager extends BaseCacheManager { * @param toUid * @param channelName */ - public void joinChannelDrEx(FrameLayout frameLayout, String strUid, String token, String toUid, String channelName,int position) { + public void joinChannelDrEx(FrameLayout frameLayout, String strUid, String token, String toUid, String channelName, int position) { int tempUid; if (StringUtil.isEmpty(strUid)) { tempUid = 0; @@ -532,10 +504,13 @@ public class SWManager extends BaseCacheManager { } } - public interface onDrPkJoinSuccessListener{ + public interface onDrPkJoinSuccessListener { void joinSuccess1(); + void joinSuccess2(); + void joinSuccess3(); + void joinSuccess4(); } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index f7be14ecb..625805231 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -1010,7 +1010,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } JSONObject obj = JSONObject.parseObject(info[0]); drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - SWManager.get().setDimensions(3);//加入成功后,将分别率设置为 VD_320x240 + SWManager.get().setDrPkNumClarity(3);//加入成功后,将分别率设置为 VD_320x240 //将自己从多人pk列表里剔除 int removeIndex = -1; for (int i = 0; i < drPkbeans.size(); i++) { diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index c1512f98d..16f6c2eb1 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -345,7 +345,7 @@ public class SocketSwClient { // LiveAudienceActivity.getmLivePlayViewHolder().setPkEndview(); Bus.get().post(new LiveAudienceEvent().setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_END_VIEW)); } - SWManager.get().setDimensions(0);//退出直播间,将分别率设置为 VD_840x480 + SWManager.get().setDrPkNumClarity(1);//退出直播间,将分别率设置为 VD_840x480 //創建了多人房間 } else if (action3 == 3) { L.eSw("創建了多人房間action3 == 3"); diff --git a/live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java index ff5bd9ede..44a9a4d5d 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveNewReadySwViewHolder.java @@ -230,7 +230,7 @@ public class LiveNewReadySwViewHolder extends AbsViewHolder implements View.OnCl // Log.e("网速和内存", "内存:" + + " 网速:" + DeviceUtils.getNetSpeed(mContext)); IMLoginManager.get(mContext).setSelectClarity(selectClarity); - setSelectClarity(IMLoginManager.get(mContext).getSelectClarity()); + //setSelectClarity(IMLoginManager.get(mContext).getSelectClarity()); ViewClicksAntiShake .clicksAntiShake( findViewById(R.id.btn_live_clarity), () -> { @@ -324,7 +324,7 @@ public class LiveNewReadySwViewHolder extends AbsViewHolder implements View.OnCl if (liveOpenCustomPopup != null) { liveOpenCustomPopup.setSelectClarity(selectClarity); } - SWManager.get().setDimensions(selectClarity); + //SWManager.get().setDimensions(selectClarity); Log.e("切换分辨率", "时间戳" + System.currentTimeMillis()); //重新发布一下流 Bus.get().post(new LivePushRyEvent()); From 985e626cb5d1c24b335c11dfc2ad55b6191b9287 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sat, 1 Jun 2024 17:31:01 +0800 Subject: [PATCH 46/64] =?UTF-8?q?fix[=E4=BF=AE=E5=A4=8D=E8=9E=8D=E4=BA=91?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=EF=BC=8C=E4=B8=8A=E4=B8=8B=E6=BB=91?= =?UTF-8?q?=E5=8A=A8=E9=97=AA=E9=80=80=E9=97=AE=E9=A2=98]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/live/views/LivePlayRyViewHolder.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index c3cf5e695..e6a66e1e7 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -670,7 +670,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(DpUtil.dp2px(24), DpUtil.dp2px(24)); params.addRule(RelativeLayout.CENTER_IN_PARENT); mLoading.setLayoutParams(params); - mRoot.addView(mLoading); + System.out.println(" changeToBig changeToBig changeToBig"+mLoading.getParent()); + if(mLoading.getParent()!=mRoot){ + mRoot.addView(mLoading); + } } } From cb2729433e66ad1e8a5058122cd769b7c770db06 Mon Sep 17 00:00:00 2001 From: 18142669586 <1669783059@qq.com> Date: Sun, 2 Jun 2024 14:44:36 +0800 Subject: [PATCH 47/64] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=BB=91=E5=8A=A8=E9=BB=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/agora/beautyapi/faceunity/agora/SWAuManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index 7a6c7afe8..3ac3ec00f 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -354,7 +354,7 @@ public class SWAuManager extends BaseCacheManager { } public static String getChannelName(String liveUid) { - if (liveUid.contains("g")) { + if ( liveUid != null &&liveUid.contains("g")) { return liveUid; } else { return CommonAppConfig.SWChannelPrefix + liveUid; From 4bd1e4bc917d8330ece39b2a98997bf9bda8c893 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Sun, 2 Jun 2024 16:57:48 +0800 Subject: [PATCH 48/64] =?UTF-8?q?fix[=E4=BF=AE=E5=A4=8D=E8=9E=8D=E4=BA=91?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=EF=BC=8C=E5=A4=9A=E4=BA=BAPK?= =?UTF-8?q?=E4=B8=BB=E6=92=AD=E4=BF=A1=E6=81=AF=E9=97=AE=E9=A2=98]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/CommonAppConfig.java | 4 ++-- .../live/activity/LiveSwAnchorActivity.java | 4 ++-- .../presenter/LiveSwLinkMicPkPresenter.java | 18 ++++++++++-------- .../com/yunbao/live/socket/SocketSwClient.java | 1 + .../live/views/LivePushSwViewHolder.java | 5 +++-- .../main/res/layout/view_live_pk_details.xml | 10 ++++++---- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index fb294a2ef..2536baf6c 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -80,9 +80,9 @@ public class CommonAppConfig { public static String SWToken = ""; //声网Token public static final String SWChannelPrefix = "g"; //测试服 - //public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; + public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; //正式服 - public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; + //public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index 78c9dbf64..a4240d206 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -165,7 +165,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl private boolean mPaused; String mBeautySdkType; public static int isDRPK = 0; - public static int DRPKing = 0; // 0 多人PK前 1 多人PK中 2多人PK后 + public static int DRPKing = -1; //-1 未发起多人PK 0 多人PK前 1 多人PK中 2多人PK后 public static boolean PKing = false; public static int pk_nub; public static int backIndex = 0;//0=未判断,1=已判断 @@ -874,7 +874,7 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl MicUserManager.get().removeAllMicUserList(); PKing = false; isDRPK = 0; - DRPKing = 0; + DRPKing = -1; endLive(); RandomPkManager.getInstance().release(); } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 625805231..4ee743c42 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -567,7 +567,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { pkScores.remove(removeUid); upDataPkScore(pkScores,"-1",0,false); } - }, 1000); + }, 100); } @@ -802,6 +802,11 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { private String TAG = "多人PK"; + + public void editPkRoom(String uid){ + SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), uid); + } + /** * 退出多人PK */ @@ -1252,12 +1257,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { linearGrade1.setVisibility(View.GONE); } - - public void setPkUserInfoView(UserBean userBean) { - - } - - //多人PK接受申请画 加入副房间 + //多人PK接受申请画 public void dRjoinOtherRoom(UserBean u) { L.eSw("dRjoinOtherRoom UserBeanUserBeanUserBeanUserBeanUserBeanUserBeanUserBeanUserBean "); setMyDrPkDetailsView(); @@ -1972,7 +1972,9 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME2, getNextSecondTime()); } } else { - mLiveAnchorViewHolder.showEndPkBt(); + if(DRPKing!=-1){ + mLiveAnchorViewHolder.showEndPkBt(); + } livePushSwViewHolder.timeTitle.setVisibility(View.GONE); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index 16f6c2eb1..bb4aa29e7 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -335,6 +335,7 @@ public class SocketSwClient { DRPKing = 1; } else if (action3 == 5) {//结束PK // endDRGif(); + DRPKing= -1; LiveRoomViewHolder.d_pk_view.setVisibility(View.GONE); if (LiveSwAnchorActivity.mLiveAnchorViewHolder != null) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); diff --git a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java index 03924503e..f3c5192b9 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -344,8 +344,6 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX } } }); - - mLiveSwLinkMicPkPresenter.setPkUserInfoView(u); } private int currentPosition = 0; @@ -396,7 +394,10 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX } public void anchorClose() { + swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()),pkUid1); swManager.updateMyChannelView((FrameLayout) mBigContainer); //用户主动断开连麦再退出画面 + mPkContainer.setVisibility(View.GONE); + pkUid1 = null; } public void onLinkMicAnchorClose() { diff --git a/live/src/main/res/layout/view_live_pk_details.xml b/live/src/main/res/layout/view_live_pk_details.xml index 1fa312eb6..f7fcfb9d5 100644 --- a/live/src/main/res/layout/view_live_pk_details.xml +++ b/live/src/main/res/layout/view_live_pk_details.xml @@ -5,8 +5,9 @@ @@ -60,8 +61,9 @@ Date: Mon, 3 Jun 2024 15:02:03 +0800 Subject: [PATCH 49/64] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E5=A0=86?= =?UTF-8?q?=E5=9B=BE=E6=A0=87+10=E5=AD=97=E5=90=8D=E5=AD=97=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E6=A1=86=E6=B2=A1=E6=9C=89=E5=9B=BE=E6=A0=87=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/activity/LiveAudienceActivity.java | 25 +++++++++ .../com/yunbao/live/utils/LiveTextRender.java | 51 +++++++++++++++---- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 15fd3aea4..6d51d42b2 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -36,6 +36,9 @@ import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.enums.PopupPosition; import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; +import com.lzf.easyfloat.enums.ShowPattern; +import com.yunbao.common.dialog.DebugDialog; +import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; @@ -126,6 +129,7 @@ import com.yunbao.live.dialog.SignDialogFragment; import com.yunbao.live.event.LinkMicTxAccEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.http.ImHttpUtil; +import com.yunbao.live.utils.LiveTextRender; import com.yunbao.live.views.LiveRoomPlayViewHolder; import com.yunbao.live.views.LiveRoomViewHolder; import com.yunbao.live.views.PortraitLiveManager; @@ -225,6 +229,27 @@ public class LiveAudienceActivity extends LiveActivity { fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "YoursystemisolderDialog"); IMLoginManager.get(mContext).setXiaJBG(true); } + /*new Handler(Looper.getMainLooper()) + .postDelayed(new Runnable() { + @Override + public void run() { + System.out.println("------------------------初始化弹窗------------------------"); + DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { + @Override + public void run(DebugDialog dialog) { + System.out.println("------------------------显示弹窗------------------------"); + dialog.setShowPattern(ShowPattern.ALL_TIME); + dialog.show(); + LiveTextRender.onItemClickListener = new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]); + } + }; + } + }); + } + },1000);*/ } private final MicStatusManager.OnMicStatusListener onMicStatusListener = new MicStatusManager.OnMicStatusListener() { diff --git a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java index f9f67b5ba..c99006b84 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -32,13 +32,16 @@ import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; +import com.lzf.easyfloat.enums.ShowPattern; import com.yunbao.common.CommonAppContext; import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.MsgModel; import com.yunbao.common.bean.NewGuardLevelModel; import com.yunbao.common.bean.NewLevelModel; import com.yunbao.common.custom.VerticalImageSpan; +import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.NewLevelManager; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.StringUtil; @@ -84,6 +87,10 @@ public class LiveTextRender { sFontSizeSpan = new AbsoluteSizeSpan(17, true); sFontSizeSpan2 = new AbsoluteSizeSpan(12, true); sFontSizeSpan3 = new AbsoluteSizeSpan(14, true); + if (!isInit) { + isInit = true; + + } } public void blindBox(Context context, TextView textView, LiveChatBean bean) { @@ -285,7 +292,7 @@ public class LiveTextRender { getGuardImage(CommonAppContext.sInstance, bean.getGuardType(), new ImgLoader.DrawableCallback() { @Override public void onLoadSuccess(Drawable drawable) { - SpannableStringBuilder builder = new SpannableStringBuilder(); + /*SpannableStringBuilder builder = new SpannableStringBuilder(); int index = 0; if (levelDrawable != null) { @@ -354,11 +361,16 @@ public class LiveTextRender { index = builder.length(); } } - createPrefixCallback.onPrefixCallback(builder, 0); + createPrefixCallback.onPrefixCallback(builder, 0);*/ + show(drawable); } @Override public void onLoadFailed() { + show(null); + } + + void show(Drawable drawable) { SpannableStringBuilder builder = new SpannableStringBuilder(); int index = 0; int prefixWidth = 0; @@ -393,10 +405,17 @@ public class LiveTextRender { index = builder.length(); prefixWidth += nhDrawablesMap.get(bean).getBounds().width(); } + if (drawable != null) { + builder.append(" "); + drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17)); + builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + prefixWidth += drawable.getBounds().width(); + } //在这里添加粉丝徽章的图片 if (!TextUtils.isEmpty(bean.getMedalNmae()) && !TextUtils.isEmpty(bean.getMedalLevelImageUrl()) && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 - Drawable drawable = getMedalImage(bean); + drawable = getMedalImage(bean); if (drawable != null) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); @@ -408,23 +427,25 @@ public class LiveTextRender { if (bean.isManager()) {//直播间管理员图标 - Drawable drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); + drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); if (drawable != null) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += drawable.getBounds().width(); } } if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 - Drawable drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); + drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); if (drawable != null) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // new add index = builder.length(); + prefixWidth += drawable.getBounds().width(); } } createPrefixCallback.onPrefixCallback(builder, prefixWidth); @@ -811,6 +832,14 @@ public class LiveTextRender { return mNewBitmap; } + public static OnItemClickListener onItemClickListener=new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + + } + }; + private static boolean isInit = false; + /** * 渲染普通聊天消息 */ @@ -824,21 +853,25 @@ public class LiveTextRender { sb.append(builder).append(name).append(" "); float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; int width = ((ViewGroup) textView.getParent()).getWidth(); + onItemClickListener.onItemClick("测算|" + measuredText, 0); + onItemClickListener.onItemClick("控件宽度|" + width, 0); + onItemClickListener.onItemClick("前缀预留宽度|" + prefixWidth, 0); //检测渲染后图标+名字是否超过父布局宽度,超过了就做换行处理 if (measuredText > width) { sb.clear(); sb.append(builder); for (int i = 0; i < name.length(); i++) { - sb.append(name.charAt(i)).append(" "); + sb.append(name.charAt(i)); measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - if (measuredText + 1 > width) { - name = name.substring(0, i+1) + "\n" + name.substring(i+1); + onItemClickListener.onItemClick(i + "逐测算|" + measuredText, 0); + if (measuredText > width) { + name = name.substring(0, i - 1) + "\n" + name.substring(i -1); break; } } sb.clear(); } - // name=name.substring(0,7)+"\n"+name.substring(7); + // name=name.substring(0,7)+"\n"+name.substring(7); builder.append(name); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) { From 1b57d8bc8f7c265999f5bd55f38d0249355f2e2a Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Mon, 3 Jun 2024 15:41:29 +0800 Subject: [PATCH 50/64] =?UTF-8?q?fix[=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/CommonAppConfig.java | 4 +- .../live/activity/LiveAudienceActivity.java | 25 ++++ .../com/yunbao/live/utils/LiveTextRender.java | 128 ++++++++++++++---- live/src/main/res/layout/item_live_chat.xml | 2 +- .../main/res/layout/view_live_pk_details.xml | 11 +- settings.gradle | 4 +- 6 files changed, 136 insertions(+), 38 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index 2536baf6c..fb294a2ef 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -80,9 +80,9 @@ public class CommonAppConfig { public static String SWToken = ""; //声网Token public static final String SWChannelPrefix = "g"; //测试服 - public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; + //public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; //正式服 - //public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; + public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 432b2ec9a..d0bfb97df 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -36,6 +36,9 @@ import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.enums.PopupPosition; import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; +import com.lzf.easyfloat.enums.ShowPattern; +import com.yunbao.common.dialog.DebugDialog; +import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; @@ -127,6 +130,7 @@ import com.yunbao.live.event.LinkMicTxAccEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.event.LiveOpenSuccessEvent; import com.yunbao.live.http.ImHttpUtil; +import com.yunbao.live.utils.LiveTextRender; import com.yunbao.live.views.LiveRoomPlayViewHolder; import com.yunbao.live.views.LiveRoomViewHolder; import com.yunbao.live.views.PortraitLiveManager; @@ -227,6 +231,27 @@ public class LiveAudienceActivity extends LiveActivity { fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "YoursystemisolderDialog"); IMLoginManager.get(mContext).setXiaJBG(true); } + /*new Handler(Looper.getMainLooper()) + .postDelayed(new Runnable() { + @Override + public void run() { + System.out.println("------------------------初始化弹窗------------------------"); + DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { + @Override + public void run(DebugDialog dialog) { + System.out.println("------------------------显示弹窗------------------------"); + dialog.setShowPattern(ShowPattern.ALL_TIME); + dialog.show(); + LiveTextRender.onItemClickListener = new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]); + } + }; + } + }); + } + },1000);*/ } private final MicStatusManager.OnMicStatusListener onMicStatusListener = new MicStatusManager.OnMicStatusListener() { diff --git a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java index b220d8f07..c99006b84 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -21,6 +21,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.MeasureSpec; +import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; @@ -31,13 +32,16 @@ import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; +import com.lzf.easyfloat.enums.ShowPattern; import com.yunbao.common.CommonAppContext; import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.MsgModel; import com.yunbao.common.bean.NewGuardLevelModel; import com.yunbao.common.bean.NewLevelModel; import com.yunbao.common.custom.VerticalImageSpan; +import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.NewLevelManager; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.StringUtil; @@ -83,6 +87,10 @@ public class LiveTextRender { sFontSizeSpan = new AbsoluteSizeSpan(17, true); sFontSizeSpan2 = new AbsoluteSizeSpan(12, true); sFontSizeSpan3 = new AbsoluteSizeSpan(14, true); + if (!isInit) { + isInit = true; + + } } public void blindBox(Context context, TextView textView, LiveChatBean bean) { @@ -263,7 +271,7 @@ public class LiveTextRender { } public interface CreatePrefixCallback { - void onPrefixCallback(SpannableStringBuilder builder); + void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth); } /** @@ -284,7 +292,7 @@ public class LiveTextRender { getGuardImage(CommonAppContext.sInstance, bean.getGuardType(), new ImgLoader.DrawableCallback() { @Override public void onLoadSuccess(Drawable drawable) { - SpannableStringBuilder builder = new SpannableStringBuilder(); + /*SpannableStringBuilder builder = new SpannableStringBuilder(); int index = 0; if (levelDrawable != null) { @@ -353,19 +361,25 @@ public class LiveTextRender { index = builder.length(); } } - createPrefixCallback.onPrefixCallback(builder); + createPrefixCallback.onPrefixCallback(builder, 0);*/ + show(drawable); } @Override public void onLoadFailed() { + show(null); + } + + void show(Drawable drawable) { SpannableStringBuilder builder = new SpannableStringBuilder(); int index = 0; - + int prefixWidth = 0; if (levelDrawable != null) { builder.append(" "); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += levelDrawable.getBounds().width(); } if (gzDrawablesMap.containsKey(bean)) {//贵族 @@ -373,6 +387,7 @@ public class LiveTextRender { gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += gzDrawablesMap.get(bean).getBounds().width(); } if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 @@ -380,6 +395,7 @@ public class LiveTextRender { ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += ryxzDrawablesMap.get(bean).getBounds().width(); } if (nhDrawablesMap.containsKey(bean)) {//靓号 @@ -387,41 +403,52 @@ public class LiveTextRender { nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += nhDrawablesMap.get(bean).getBounds().width(); + } + if (drawable != null) { + builder.append(" "); + drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17)); + builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + prefixWidth += drawable.getBounds().width(); } //在这里添加粉丝徽章的图片 if (!TextUtils.isEmpty(bean.getMedalNmae()) && !TextUtils.isEmpty(bean.getMedalLevelImageUrl()) && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 - Drawable drawable = getMedalImage(bean); + drawable = getMedalImage(bean); if (drawable != null) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += drawable.getBounds().width(); } } if (bean.isManager()) {//直播间管理员图标 - Drawable drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); + drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); if (drawable != null) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += drawable.getBounds().width(); } } if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 - Drawable drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); + drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); if (drawable != null) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // new add index = builder.length(); + prefixWidth += drawable.getBounds().width(); } } - createPrefixCallback.onPrefixCallback(builder); + createPrefixCallback.onPrefixCallback(builder, prefixWidth); } }); @@ -515,9 +542,9 @@ public class LiveTextRender { } public void getGuardImage(Context mContext, int guardType, ImgLoader.DrawableCallback callback) { - if (guardType==0){ + if (guardType == 0) { callback.onLoadFailed(); - }else { + } else { if (mContext instanceof Activity) { if (((Activity) mContext).isDestroyed()) { mContext = CommonAppContext.getTopActivity(); @@ -684,7 +711,7 @@ public class LiveTextRender { createPrefix(drawable, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int color = Color.parseColor("#68F1F4"); if (bean.isAnchor()) { color = Color.parseColor("#FBEABF"); @@ -696,20 +723,20 @@ public class LiveTextRender { builder = renderGift(color, builder, bean); break; default: - builder = renderChat(color, builder, bean); + builder = renderChat(textView, color, builder, bean, prefixWidth); break; } textView.setText(builder); } }); - } + }// 123123123123123123123123 @Override public void onLoadFailed() { createPrefix(null, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int color = 0; if (bean.isAnchor()) { color = 0xffffdd00; @@ -721,7 +748,7 @@ public class LiveTextRender { builder = renderGift(color, builder, bean); break; default: - builder = renderChat(color, builder, bean); + builder = renderChat(textView, color, builder, bean, prefixWidth); break; } textView.setText(builder); @@ -805,15 +832,46 @@ public class LiveTextRender { return mNewBitmap; } + public static OnItemClickListener onItemClickListener=new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + + } + }; + private static boolean isInit = false; + /** * 渲染普通聊天消息 */ - private SpannableStringBuilder renderChat(int color, SpannableStringBuilder builder, LiveChatBean bean) { + private SpannableStringBuilder renderChat(TextView textView, int color, SpannableStringBuilder builder, LiveChatBean bean, int prefixWidth) { int length = builder.length(); String name = bean.getUserNiceName(); if (bean.getType() != LiveChatBean.ENTER_ROOM) {//产品规定,进场消息不允许加冒号 name += ":"; } + SpannableStringBuilder sb = new SpannableStringBuilder(); + sb.append(builder).append(name).append(" "); + float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + int width = ((ViewGroup) textView.getParent()).getWidth(); + onItemClickListener.onItemClick("测算|" + measuredText, 0); + onItemClickListener.onItemClick("控件宽度|" + width, 0); + onItemClickListener.onItemClick("前缀预留宽度|" + prefixWidth, 0); + //检测渲染后图标+名字是否超过父布局宽度,超过了就做换行处理 + if (measuredText > width) { + sb.clear(); + sb.append(builder); + for (int i = 0; i < name.length(); i++) { + sb.append(name.charAt(i)); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + onItemClickListener.onItemClick(i + "逐测算|" + measuredText, 0); + if (measuredText > width) { + name = name.substring(0, i - 1) + "\n" + name.substring(i -1); + break; + } + } + sb.clear(); + } + // name=name.substring(0,7)+"\n"+name.substring(7); builder.append(name); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) { @@ -823,6 +881,24 @@ public class LiveTextRender { builder.setSpan(new ForegroundColorSpan(color), length, length + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } int lengthContent = builder.length(); + //这一段先别删,万一后面要改内容换行呢 + /* sb.clear(); + sb.append(builder).append(bean.getContent()); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + if (measuredText > width) { + sb.clear(); + sb.append(builder); + for (int i = 0; i < bean.getContent().length(); i++) { + sb.append(bean.getContent().charAt(i)); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + if (measuredText + 3 > width) { + bean.setContent(bean.getContent().substring(0, i) + "\n"+ bean.getContent().substring(i)); + bean.setContent(""); + break; + } + } + } +*/ builder.append(bean.getContent()); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getContentColor())) { @@ -889,7 +965,7 @@ public class LiveTextRender { if (textView != null) { createPrefix(drawable, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int start = builder.length(); String name = bean.getUserNiceName() + " "; builder.append(name); @@ -904,15 +980,15 @@ public class LiveTextRender { @Override public void onLoadFailed() { if (textView != null) { - createPrefix(null, bean, new CreatePrefixCallback() { - @Override - public void onPrefixCallback(SpannableStringBuilder builder) { - int start = builder.length(); - String name = bean.getUserNiceName() + " "; - builder.append(name); - textView.setText(builder); - } - }); + createPrefix(null, bean, new CreatePrefixCallback() { + @Override + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { + int start = builder.length(); + String name = bean.getUserNiceName() + " "; + builder.append(name); + textView.setText(builder); + } + }); } } diff --git a/live/src/main/res/layout/item_live_chat.xml b/live/src/main/res/layout/item_live_chat.xml index c4d360d8c..da2996682 100644 --- a/live/src/main/res/layout/item_live_chat.xml +++ b/live/src/main/res/layout/item_live_chat.xml @@ -10,7 +10,7 @@ @@ -17,7 +16,6 @@ android:layout_height="wrap_content" android:layout_marginStart="5.33dp" android:layout_marginTop="4.67dp" - android:background="@drawable/background_pk_time" android:gravity="center_vertical" android:orientation="horizontal"> @@ -61,9 +59,8 @@ Date: Tue, 4 Jun 2024 09:50:46 +0800 Subject: [PATCH 51/64] =?UTF-8?q?fix[=E4=BF=AE=E5=A4=8DBUG-=E4=B8=BB?= =?UTF-8?q?=E6=92=AD=E5=BC=80=E9=BA=A6=E6=8C=89=E9=92=AE=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E6=9C=AA=E6=98=BE=E7=A4=BA=E5=85=A8]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- live/src/main/res/layout/anchor_open_mic_view.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/live/src/main/res/layout/anchor_open_mic_view.xml b/live/src/main/res/layout/anchor_open_mic_view.xml index 8141f4e93..5f7709c16 100644 --- a/live/src/main/res/layout/anchor_open_mic_view.xml +++ b/live/src/main/res/layout/anchor_open_mic_view.xml @@ -33,7 +33,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:layout_marginTop="8dp" + android:layout_marginTop="6dp" android:text="打開語音連麥權限" android:textColor="#FFFFFF" android:textSize="12sp" /> @@ -43,8 +43,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:layout_marginTop="3dp" - android:layout_marginBottom="8dp" + android:layout_marginTop="2dp" android:text="粉絲等級5以上的用戶可向您發起申請" android:textColor="#259484" android:textSize="8sp" /> From cb0772c9e357b29c050826a92e09baece972e6ae Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 5 Jun 2024 09:48:22 +0800 Subject: [PATCH 52/64] =?UTF-8?q?update=20=E6=9B=B4=E6=96=B0=E5=BC=B9?= =?UTF-8?q?=E5=B9=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/activity/LiveAudienceActivity.java | 25 +++- .../yunbao/live/adapter/LiveChatAdapter.java | 3 +- .../com/yunbao/live/utils/LiveTextRender.java | 122 ++++++++++++------ live/src/main/res/layout/item_live_chat.xml | 2 + 4 files changed, 111 insertions(+), 41 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 6d51d42b2..d093665b1 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -15,6 +15,7 @@ import android.text.TextUtils; import android.util.Log; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.ImageView; import androidx.annotation.IdRes; @@ -229,21 +230,37 @@ public class LiveAudienceActivity extends LiveActivity { fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "YoursystemisolderDialog"); IMLoginManager.get(mContext).setXiaJBG(true); } - /*new Handler(Looper.getMainLooper()) + /* new Handler(Looper.getMainLooper()) .postDelayed(new Runnable() { @Override public void run() { - System.out.println("------------------------初始化弹窗------------------------"); DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { @Override public void run(DebugDialog dialog) { - System.out.println("------------------------显示弹窗------------------------"); dialog.setShowPattern(ShowPattern.ALL_TIME); dialog.show(); + + dialog.setView("+",new Button(mContext),view -> LiveTextRender.textTemp++); + dialog.setView("-",new Button(mContext),view -> LiveTextRender.textTemp--); + dialog.setView("+",new Button(mContext),view -> LiveTextRender.textTemp++); + dialog.setView("中/英",new Button(mContext),view ->{ + if(LiveTextRender.userName.startsWith("中")){ + LiveTextRender.userName="英文34567890"; + }else{ + LiveTextRender.userName="中文测试中文测试中文"; + } + }); + dialog.setView("长/短",new Button(mContext),view ->{ + if(LiveTextRender.userName.length()>5){ + LiveTextRender.userName="abcdefg"; + }else{ + LiveTextRender.userName="中文中文"; + } + }); LiveTextRender.onItemClickListener = new OnItemClickListener() { @Override public void onItemClick(String bean, int position) { - dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]); + dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]+"|"+position); } }; } diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java index 9d515497e..bac417ed9 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -210,7 +210,8 @@ public class LiveChatAdapter extends RecyclerView.Adapter { class Vh extends RecyclerView.ViewHolder { LinearLayout mBg, view_follow, view_action_game, view_zg, xydComplete; - TextView mTextView, tv_chat_active_into, tv_chat_avtive_name, tv_zg_anchorname, textTxt2, automatic_chat; + TextView tv_chat_active_into, tv_chat_avtive_name, tv_zg_anchorname, textTxt2, automatic_chat; + TextView mTextView; RoundedImageView avatar; View v_chat_active_close; RecyclerView rv_chat_active; diff --git a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java index c99006b84..c1014fa45 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -6,6 +6,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; @@ -23,6 +24,7 @@ import android.view.View; import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -296,34 +298,34 @@ public class LiveTextRender { int index = 0; if (levelDrawable != null) { - builder.append(" "); + builder.append("\uFFFC "); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); } if (gzDrawablesMap.containsKey(bean)) {//贵族 - builder.append(" "); + builder.append("\uFFFC "); gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); } if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 - builder.append(" "); + builder.append("\uFFFC "); ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); } if (nhDrawablesMap.containsKey(bean)) {//靓号 - builder.append(" "); + builder.append("\uFFFC "); nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); } if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -333,7 +335,7 @@ public class LiveTextRender { && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 Drawable drawable2 = getMedalImage(bean); if (drawable2 != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable2.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable2), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -344,7 +346,7 @@ public class LiveTextRender { if (bean.isManager()) {//直播间管理员图标 Drawable drawable3 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); if (drawable3 != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable3.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable3), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -354,7 +356,7 @@ public class LiveTextRender { if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 Drawable drawable4 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); if (drawable4 != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable4.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable4), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // new add @@ -375,7 +377,7 @@ public class LiveTextRender { int index = 0; int prefixWidth = 0; if (levelDrawable != null) { - builder.append(" "); + builder.append("\uFFFC "); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -383,7 +385,7 @@ public class LiveTextRender { } if (gzDrawablesMap.containsKey(bean)) {//贵族 - builder.append(" "); + builder.append("\uFFFC "); gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -391,7 +393,7 @@ public class LiveTextRender { } if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 - builder.append(" "); + builder.append("\uFFFC "); ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -399,14 +401,14 @@ public class LiveTextRender { } if (nhDrawablesMap.containsKey(bean)) {//靓号 - builder.append(" "); + builder.append("\uFFFC "); nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); prefixWidth += nhDrawablesMap.get(bean).getBounds().width(); } if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -417,7 +419,7 @@ public class LiveTextRender { && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 drawable = getMedalImage(bean); if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -429,7 +431,7 @@ public class LiveTextRender { if (bean.isManager()) {//直播间管理员图标 drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -440,7 +442,7 @@ public class LiveTextRender { if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // new add @@ -832,13 +834,15 @@ public class LiveTextRender { return mNewBitmap; } - public static OnItemClickListener onItemClickListener=new OnItemClickListener() { + public static OnItemClickListener onItemClickListener = new OnItemClickListener() { @Override public void onItemClick(String bean, int position) { } }; private static boolean isInit = false; + public static int textTemp = 0; + public static String userName = ""; /** * 渲染普通聊天消息 @@ -846,33 +850,48 @@ public class LiveTextRender { private SpannableStringBuilder renderChat(TextView textView, int color, SpannableStringBuilder builder, LiveChatBean bean, int prefixWidth) { int length = builder.length(); String name = bean.getUserNiceName(); + float prefixEmpty = textView.getPaint().measureText(builder, 0, builder.length()) / 2; + if (!StringUtil.isEmpty(userName)) { + // name = userName; + } if (bean.getType() != LiveChatBean.ENTER_ROOM) {//产品规定,进场消息不允许加冒号 name += ":"; } SpannableStringBuilder sb = new SpannableStringBuilder(); - sb.append(builder).append(name).append(" "); + sb.append(name); float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - int width = ((ViewGroup) textView.getParent()).getWidth(); - onItemClickListener.onItemClick("测算|" + measuredText, 0); - onItemClickListener.onItemClick("控件宽度|" + width, 0); - onItemClickListener.onItemClick("前缀预留宽度|" + prefixWidth, 0); + // Rect mRect = new Rect(); + // textView.getPaint().getTextBounds(sb.toString(), 0, sb.length(), mRect); + int width = (int) (((ViewGroup) textView.getParent()).getMeasuredWidth() - prefixEmpty); + String TAG = "文字渲染"; + // Log.i(TAG, "测算|" + measuredText + "|" + mRect.width() + "|" + sb.toString()); + //|810|810|810|786|786 + // Log.i(TAG, "控件宽度|" + width + "|" + ((ViewGroup) textView.getParent()).getWidth() + "|" + ((ViewGroup) textView.getParent()).getMeasuredWidth() + "|" + textView.getWidth() + "|" + textView.getMeasuredWidth()); + // Log.i(TAG, "前缀预留宽度|" + prefixWidth + "|" + prefixEmpty); + // Log.i(TAG, "renderChat: " + textView.getCompoundPaddingLeft() + "|" + textView.getCompoundPaddingRight() + "|"); //检测渲染后图标+名字是否超过父布局宽度,超过了就做换行处理 + String prefixName = ""; if (measuredText > width) { sb.clear(); - sb.append(builder); for (int i = 0; i < name.length(); i++) { sb.append(name.charAt(i)); measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - onItemClickListener.onItemClick(i + "逐测算|" + measuredText, 0); - if (measuredText > width) { - name = name.substring(0, i - 1) + "\n" + name.substring(i -1); + Log.i(TAG, i + "逐测算|" + measuredText + "|" + textTemp); + if (measuredText > width) { + prefixName = name.substring(0, i + textTemp); + name = prefixName + "\n" + name.substring(i + textTemp); break; } } sb.clear(); + } else { + prefixName = name; } + sb.clear(); + sb.append(prefixName); // name=name.substring(0,7)+"\n"+name.substring(7); builder.append(name); + Log.i(TAG, "再测算|" + (textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth) + "|" + textTemp + "|" + sb.toString()); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) { @@ -882,26 +901,56 @@ public class LiveTextRender { } int lengthContent = builder.length(); //这一段先别删,万一后面要改内容换行呢 - /* sb.clear(); - sb.append(builder).append(bean.getContent()); + // TODO 试试 “空Unicode” + /*sb.clear(); + TAG = "文字渲染2"; + String content = bean.getContent(); + Log.i(TAG, "renderChat: " + content); + sb.append(name).append(content); + SpannableStringBuilder csb = null; measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + sb.clear(); + sb.append(prefixName); + prefixEmpty = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + StringBuilder stringBuilder = new StringBuilder(); if (measuredText > width) { sb.clear(); - sb.append(builder); - for (int i = 0; i < bean.getContent().length(); i++) { - sb.append(bean.getContent().charAt(i)); - measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - if (measuredText + 3 > width) { - bean.setContent(bean.getContent().substring(0, i) + "\n"+ bean.getContent().substring(i)); - bean.setContent(""); - break; + sb.append(name); + float lineWidth = 0; + for (int i = 0; i < content.length(); i++) { + char charAt = content.charAt(i); + sb.append(charAt); + lineWidth += textView.getPaint().measureText(String.valueOf(charAt)) + prefixEmpty; + prefixEmpty = 0; + textView.setText(sb); + Log.i(TAG, "renderChat: TextView是否换行:" + textView.getText().toString().split("\n").length); + Log.i(TAG, "逐测算|" + lineWidth + " width|" + width + "|" + sb.toString()); + if (lineWidth > width) { + Log.i(TAG, "renderChat: 换行:" + charAt); + if (!stringBuilder.toString().endsWith("\n")) { + stringBuilder.append("\n"); + } + lineWidth = 0; + --i; + } else { + Log.i(TAG, "renderChat: 直接加入:" + charAt); + stringBuilder.append(content.charAt(i)); } + } + if (stringBuilder.toString().endsWith("\n")) { + Log.i(TAG, "需要删除回车"); + stringBuilder.deleteCharAt(stringBuilder.length() - 1); + } + Log.i(TAG, "分行后内容:" + stringBuilder.toString()); + bean.setContent(stringBuilder.toString()); } */ + builder.append(bean.getContent()); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getContentColor())) { + Log.i(TAG, "lengthContent: " + lengthContent + "|content: " + bean.getContent().length() + "|max: " + (lengthContent + bean.getContent().length())); builder.setSpan(new ForegroundColorSpan(Color.parseColor(bean.getContentColor())), lengthContent, lengthContent + bean.getContent().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (bean.getType() == LiveChatBean.LIGHT) { @@ -913,6 +962,7 @@ public class LiveTextRender { builder.setSpan(new VerticalImageSpan(heartDrawable), length - 1, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } + //textView.setText(""); return builder; } diff --git a/live/src/main/res/layout/item_live_chat.xml b/live/src/main/res/layout/item_live_chat.xml index da2996682..a6e5fddfb 100644 --- a/live/src/main/res/layout/item_live_chat.xml +++ b/live/src/main/res/layout/item_live_chat.xml @@ -16,7 +16,9 @@ android:layout_marginRight="9dp" android:paddingBottom="7dp" android:textColor="#fff" + android:breakStrategy="simple" android:textSize="12sp" + tools:text="aaaaaaaaa111111111111111111111111111111111111111111111111111111111" android:visibility="visible" tools:ignore="RtlHardcoded" /> From 5a924d9fea0f82c392dd1e5fee96ac306e32315f Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Wed, 5 Jun 2024 09:50:57 +0800 Subject: [PATCH 53/64] =?UTF-8?q?fix[=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beautyapi/faceunity/agora/SWManager.java | 14 ++++++- .../live/activity/LiveSwAnchorActivity.java | 12 +++++- .../live/dialog/LiveGiftDialogFragment.java | 3 ++ .../com/yunbao/live/dialog/LiveGiftPopup.java | 5 +++ .../dialog/LiveMicUserDialogFragment.java | 30 ++++++++++----- .../presenter/LiveSwLinkMicPkPresenter.java | 2 +- .../live/views/LivePushSwViewHolder.java | 5 +++ .../yunbao/live/views/LiveRoomViewHolder.java | 37 ++++++++++++------- live/src/main/res/layout/view_live_room.xml | 5 +-- settings.gradle | 4 +- 10 files changed, 84 insertions(+), 33 deletions(-) diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 0b09da2f2..1dbcc7308 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -125,6 +125,8 @@ public class SWManager extends BaseCacheManager { //设置竖屏 cfg.orientationMode = VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_FIXED_PORTRAIT; + + mRtcEngine.setVideoEncoderConfiguration(cfg); // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 @@ -232,7 +234,8 @@ public class SWManager extends BaseCacheManager { ChannelMediaOptions options = new ChannelMediaOptions(); // 设置角色 BROADCASTER (主播) 或 AUDIENCE (观众) options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER; - + options.publishCameraTrack = true; + options.publishMicrophoneTrack = true; mRtcEngine.setAudioProfile(Constants.AUDIO_PROFILE_MUSIC_HIGH_QUALITY); mRtcEngine.setAudioScenario(Constants.AUDIO_SCENARIO_GAME_STREAMING); @@ -433,6 +436,14 @@ public class SWManager extends BaseCacheManager { } } + @Override + public void onUserOffline(int uid, int reason) { + super.onUserOffline(uid, reason); + if (onRtcEngineListener != null) { + //onRtcEngineListener.onOpenSuccess(channel, uid); + } + } + @Override public void onError(int err) { super.onError(err); @@ -486,6 +497,7 @@ public class SWManager extends BaseCacheManager { public interface onRtcEngineListener { void onOpenSuccess(String channel, int uid); + void onUserOffline(int uid); } public void setPkContainer(FrameLayout pkContainer) { diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index a4240d206..1c31f398a 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -87,6 +87,7 @@ import com.yunbao.live.bean.LiveChatBean; import com.yunbao.live.bean.LiveGuardInfo; import com.yunbao.live.bean.LiveKsyConfigBean; import com.yunbao.live.bean.LiveReceiveGiftBean; +import com.yunbao.live.bean.NewAllServerNotifyGuardEvent; import com.yunbao.live.dialog.FreePkDialogFragment; import com.yunbao.live.dialog.LiveInputDialogFragment; import com.yunbao.live.dialog.LiveNewFunctionDialogFragment; @@ -1942,13 +1943,20 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl } break; } - - } + @Subscribe(threadMode = ThreadMode.MAIN) public void onAllServerNotifyFFGGGDJANEvent(AllServerNotifyFFGGGDJANEvent event) { if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.showAllServerNotifyFFGGGD(event,false); } } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onNewAllServerNotifyGuardEvent(NewAllServerNotifyGuardEvent event) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.buyGuardNew(event); + } + } + } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveGiftDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveGiftDialogFragment.java index 12100ee45..c9667ec0f 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveGiftDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveGiftDialogFragment.java @@ -65,6 +65,7 @@ import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.GiftCacheUtil; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.NobleUtil; import com.yunbao.common.utils.SVGAViewUtils; import com.yunbao.common.utils.StringUtil; @@ -1021,9 +1022,11 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On if (u != null) { u.setLevel(obj.getIntValue("level")); //送礼物后更新粉丝徽章等级 + L.eSw("___送礼物后更新粉丝徽章等级_修改前3333___ "+obj.getIntValue("medal_level")); u.setMedalLevel(obj.getIntValue("medal_level")); u.setMedalName(obj.getString("medal_name")); u.setCoin(coin); + L.eSw("___送礼物后更新粉丝徽章等级_修改后3333___ "+obj.getIntValue("medal_level")); } if (mCoin != null) { mCoin.setText(coin); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java index f1069d325..b6c2c946e 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java @@ -44,6 +44,7 @@ import com.opensource.svgaplayer.SVGADrawable; import com.opensource.svgaplayer.SVGAImageView; import com.opensource.svgaplayer.SVGAParser; import com.opensource.svgaplayer.SVGAVideoEntity; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; @@ -656,7 +657,9 @@ public class LiveGiftPopup extends AbsDialogFragment { if (u != null) { u.setLevel(obj.getIntValue("level")); //送礼物后更新粉丝徽章等级 + L.eSw("___送礼物后更新粉丝徽章等级_修改前111___ "+obj.getIntValue("medal_level")); u.setMedalLevel(obj.getIntValue("medal_level")); + L.eSw("___送礼物后更新粉丝徽章等级_修改后111___ "+CommonAppConfig.getInstance().getUserBean().getMedalLevel()); u.setMedalName(obj.getString("medal_name")); u.setCoin(coin); } @@ -1360,8 +1363,10 @@ public class LiveGiftPopup extends AbsDialogFragment { u.setLevel(obj.getIntValue("level")); //送礼物后更新粉丝徽章等级 u.setMedalLevel(obj.getIntValue("medal_level")); + L.eSw("___送礼物后更新粉丝徽章等级_修改前2222___ "+obj.getIntValue("medal_level")); u.setMedalName(obj.getString("medal_name")); u.setCoin(coin); + L.eSw("___送礼物后更新粉丝徽章等级_修改后2222___ "+CommonAppConfig.getInstance().getUserBean().getMedalLevel()); } if (diamondText != null) { diamondText.setText(coin); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java index d41a0b83c..6430619b4 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java @@ -150,16 +150,7 @@ public class LiveMicUserDialogFragment extends AbsDialogFragment implements View mRefreshView = mRootView.findViewById(R.id.refreshView); view_no = mRootView.findViewById(R.id.view_no); apply_btn = mRootView.findViewById(R.id.apply_btn); - if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_DEFAULT) { - apply_btn.setBackgroundResource(R.drawable.background_0fdab8); - apply_btn.setText(mContext.getString(R.string.apply_for_lianmai)); - } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_REQUEST) { - apply_btn.setBackgroundResource(R.drawable.background_00a0e9); - apply_btn.setText(mContext.getString(R.string.cancel_application)); - } else if (MicStatusManager.getInstance().getMicStatus() == MicStatusManager.MIC_TYPE_OPEN) { - apply_btn.setBackgroundResource(R.drawable.background_eb6877); - apply_btn.setText(mContext.getString(R.string.quit_mic)); - } + updateMicType(); apply_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -354,6 +345,12 @@ public class LiveMicUserDialogFragment extends AbsDialogFragment implements View } } if (data.size() > 0 && pg == 1) { + for (int i = 0; i 180) { redPacketQueue.setVisibility(View.GONE); @@ -1743,7 +1751,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis redSchedule.setText(stringBuffer.toString()); openRedPacket.setText(String.format(mContext.getString(R.string.open_red_packet), mRedPacketModel.getRedPacketCount() + "")); } - if (IMLoginManager.get(mContext).getUserInfo().anchorUserType() && mContext instanceof LiveSwAnchorActivity) { + if (IMLoginManager.get(mContext).getUserInfo().anchorUserType() && (mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity)) { anchorTimeHandler.removeCallbacks(anchorTimeRunnable); anchorTimeHandler.post(anchorTimeRunnable); } @@ -1755,7 +1763,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void onViewClicks() { - if (!(mContext instanceof LiveSwAnchorActivity)) { + if (!(mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity)) { LiveNetManager.get(mContext).redPacketInfo(mLiveUid, redPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { @Override public void onSuccess(RedPacketInfoModel data) { @@ -1781,6 +1789,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } + } }); } @@ -2950,7 +2959,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis bundle.putString("toUid", toUid); bundle.putInt("isAttention", isAttention); bundle.putBoolean("isLive", isAnchor); - bundle.putBoolean("SBW", !(mContext instanceof LiveSwAnchorActivity)); + bundle.putBoolean("SBW", !(mContext instanceof LiveSwAnchorActivity ||mContext instanceof LiveRyAnchorActivity )); giftWallDialog.setArguments(bundle); giftWallDialog.show(((AbsActivity) mContext).getSupportFragmentManager(), "GiftWallDialog"); @@ -3315,7 +3324,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis //直播间 粉丝排行榜 openMedalRankWindow(); } else if (i == R.id.btn_guard) { - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow((mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity )); } else if (i == R.id.btn_red_pack) { ((LiveActivity) mContext).openRedPackListWindow(); @@ -3323,13 +3332,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ((LiveActivity) mContext).openPrizePoolWindow(); } else if (i == R.id.user_more) { MobclickAgent.onEvent(mContext, "live_room_audience_list", "直播间上面点观众列表按钮"); - ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity); } else if (i == R.id.hot_btn) { - ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity); } else if (i == R.id.noble_seat) { MobclickAgent.onEvent(mContext, "live_room_noble", "贵族按钮"); - ((LiveActivity) mContext).openUserMoreListWindow(1, false, true, mContext instanceof LiveSwAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, true, mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity); } else if (i == R.id.btn_close) { // if (sudGameMin!=null&&sudGameMin.getVisibility()==View.VISIBLE) { // new XPopup.Builder(mContext) @@ -3362,7 +3371,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } else if (i == R.id.user_guard) { MobclickAgent.onEvent(mContext, "anchor_avatar_guard", "守护按钮"); // ((LiveActivity) mContext).openUserMoreListWindow(2, true); - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity); } if (i == R.id.lt_trickery) { showTrickeryDialog(); @@ -3387,7 +3396,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis * @param in 展示的view */ private void changeMsgView(View out, View in) { - if (mContext instanceof LiveSwAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity) { return; } if (in.getVisibility() == View.VISIBLE) { @@ -4740,7 +4749,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis lt_trickster_salvation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mContext instanceof LiveSwAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity) { dialog.dismiss(); return; } diff --git a/live/src/main/res/layout/view_live_room.xml b/live/src/main/res/layout/view_live_room.xml index d26c53496..da44880cd 100644 --- a/live/src/main/res/layout/view_live_room.xml +++ b/live/src/main/res/layout/view_live_room.xml @@ -1491,10 +1491,10 @@ android:visibility="visible" /> + android:layout_height="wrap_content"> Date: Wed, 5 Jun 2024 09:52:37 +0800 Subject: [PATCH 54/64] =?UTF-8?q?fix[=E6=9B=B4=E6=96=B0=E5=BC=B9=E5=B9=95]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/activity/LiveAudienceActivity.java | 25 +++- .../yunbao/live/adapter/LiveChatAdapter.java | 3 +- .../com/yunbao/live/utils/LiveTextRender.java | 122 ++++++++++++------ live/src/main/res/layout/item_live_chat.xml | 2 + 4 files changed, 111 insertions(+), 41 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index d0bfb97df..c985b8ad6 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -15,6 +15,7 @@ import android.text.TextUtils; import android.util.Log; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.ImageView; import androidx.annotation.IdRes; @@ -231,21 +232,37 @@ public class LiveAudienceActivity extends LiveActivity { fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "YoursystemisolderDialog"); IMLoginManager.get(mContext).setXiaJBG(true); } - /*new Handler(Looper.getMainLooper()) + /* new Handler(Looper.getMainLooper()) .postDelayed(new Runnable() { @Override public void run() { - System.out.println("------------------------初始化弹窗------------------------"); DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { @Override public void run(DebugDialog dialog) { - System.out.println("------------------------显示弹窗------------------------"); dialog.setShowPattern(ShowPattern.ALL_TIME); dialog.show(); + + dialog.setView("+",new Button(mContext),view -> LiveTextRender.textTemp++); + dialog.setView("-",new Button(mContext),view -> LiveTextRender.textTemp--); + dialog.setView("+",new Button(mContext),view -> LiveTextRender.textTemp++); + dialog.setView("中/英",new Button(mContext),view ->{ + if(LiveTextRender.userName.startsWith("中")){ + LiveTextRender.userName="英文34567890"; + }else{ + LiveTextRender.userName="中文测试中文测试中文"; + } + }); + dialog.setView("长/短",new Button(mContext),view ->{ + if(LiveTextRender.userName.length()>5){ + LiveTextRender.userName="abcdefg"; + }else{ + LiveTextRender.userName="中文中文"; + } + }); LiveTextRender.onItemClickListener = new OnItemClickListener() { @Override public void onItemClick(String bean, int position) { - dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]); + dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]+"|"+position); } }; } diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java index 9d515497e..bac417ed9 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -210,7 +210,8 @@ public class LiveChatAdapter extends RecyclerView.Adapter { class Vh extends RecyclerView.ViewHolder { LinearLayout mBg, view_follow, view_action_game, view_zg, xydComplete; - TextView mTextView, tv_chat_active_into, tv_chat_avtive_name, tv_zg_anchorname, textTxt2, automatic_chat; + TextView tv_chat_active_into, tv_chat_avtive_name, tv_zg_anchorname, textTxt2, automatic_chat; + TextView mTextView; RoundedImageView avatar; View v_chat_active_close; RecyclerView rv_chat_active; diff --git a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java index c99006b84..c1014fa45 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -6,6 +6,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; @@ -23,6 +24,7 @@ import android.view.View; import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -296,34 +298,34 @@ public class LiveTextRender { int index = 0; if (levelDrawable != null) { - builder.append(" "); + builder.append("\uFFFC "); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); } if (gzDrawablesMap.containsKey(bean)) {//贵族 - builder.append(" "); + builder.append("\uFFFC "); gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); } if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 - builder.append(" "); + builder.append("\uFFFC "); ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); } if (nhDrawablesMap.containsKey(bean)) {//靓号 - builder.append(" "); + builder.append("\uFFFC "); nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); } if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -333,7 +335,7 @@ public class LiveTextRender { && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 Drawable drawable2 = getMedalImage(bean); if (drawable2 != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable2.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable2), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -344,7 +346,7 @@ public class LiveTextRender { if (bean.isManager()) {//直播间管理员图标 Drawable drawable3 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); if (drawable3 != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable3.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable3), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -354,7 +356,7 @@ public class LiveTextRender { if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 Drawable drawable4 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); if (drawable4 != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable4.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable4), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // new add @@ -375,7 +377,7 @@ public class LiveTextRender { int index = 0; int prefixWidth = 0; if (levelDrawable != null) { - builder.append(" "); + builder.append("\uFFFC "); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -383,7 +385,7 @@ public class LiveTextRender { } if (gzDrawablesMap.containsKey(bean)) {//贵族 - builder.append(" "); + builder.append("\uFFFC "); gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -391,7 +393,7 @@ public class LiveTextRender { } if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 - builder.append(" "); + builder.append("\uFFFC "); ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -399,14 +401,14 @@ public class LiveTextRender { } if (nhDrawablesMap.containsKey(bean)) {//靓号 - builder.append(" "); + builder.append("\uFFFC "); nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); prefixWidth += nhDrawablesMap.get(bean).getBounds().width(); } if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -417,7 +419,7 @@ public class LiveTextRender { && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 drawable = getMedalImage(bean); if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -429,7 +431,7 @@ public class LiveTextRender { if (bean.isManager()) {//直播间管理员图标 drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -440,7 +442,7 @@ public class LiveTextRender { if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // new add @@ -832,13 +834,15 @@ public class LiveTextRender { return mNewBitmap; } - public static OnItemClickListener onItemClickListener=new OnItemClickListener() { + public static OnItemClickListener onItemClickListener = new OnItemClickListener() { @Override public void onItemClick(String bean, int position) { } }; private static boolean isInit = false; + public static int textTemp = 0; + public static String userName = ""; /** * 渲染普通聊天消息 @@ -846,33 +850,48 @@ public class LiveTextRender { private SpannableStringBuilder renderChat(TextView textView, int color, SpannableStringBuilder builder, LiveChatBean bean, int prefixWidth) { int length = builder.length(); String name = bean.getUserNiceName(); + float prefixEmpty = textView.getPaint().measureText(builder, 0, builder.length()) / 2; + if (!StringUtil.isEmpty(userName)) { + // name = userName; + } if (bean.getType() != LiveChatBean.ENTER_ROOM) {//产品规定,进场消息不允许加冒号 name += ":"; } SpannableStringBuilder sb = new SpannableStringBuilder(); - sb.append(builder).append(name).append(" "); + sb.append(name); float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - int width = ((ViewGroup) textView.getParent()).getWidth(); - onItemClickListener.onItemClick("测算|" + measuredText, 0); - onItemClickListener.onItemClick("控件宽度|" + width, 0); - onItemClickListener.onItemClick("前缀预留宽度|" + prefixWidth, 0); + // Rect mRect = new Rect(); + // textView.getPaint().getTextBounds(sb.toString(), 0, sb.length(), mRect); + int width = (int) (((ViewGroup) textView.getParent()).getMeasuredWidth() - prefixEmpty); + String TAG = "文字渲染"; + // Log.i(TAG, "测算|" + measuredText + "|" + mRect.width() + "|" + sb.toString()); + //|810|810|810|786|786 + // Log.i(TAG, "控件宽度|" + width + "|" + ((ViewGroup) textView.getParent()).getWidth() + "|" + ((ViewGroup) textView.getParent()).getMeasuredWidth() + "|" + textView.getWidth() + "|" + textView.getMeasuredWidth()); + // Log.i(TAG, "前缀预留宽度|" + prefixWidth + "|" + prefixEmpty); + // Log.i(TAG, "renderChat: " + textView.getCompoundPaddingLeft() + "|" + textView.getCompoundPaddingRight() + "|"); //检测渲染后图标+名字是否超过父布局宽度,超过了就做换行处理 + String prefixName = ""; if (measuredText > width) { sb.clear(); - sb.append(builder); for (int i = 0; i < name.length(); i++) { sb.append(name.charAt(i)); measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - onItemClickListener.onItemClick(i + "逐测算|" + measuredText, 0); - if (measuredText > width) { - name = name.substring(0, i - 1) + "\n" + name.substring(i -1); + Log.i(TAG, i + "逐测算|" + measuredText + "|" + textTemp); + if (measuredText > width) { + prefixName = name.substring(0, i + textTemp); + name = prefixName + "\n" + name.substring(i + textTemp); break; } } sb.clear(); + } else { + prefixName = name; } + sb.clear(); + sb.append(prefixName); // name=name.substring(0,7)+"\n"+name.substring(7); builder.append(name); + Log.i(TAG, "再测算|" + (textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth) + "|" + textTemp + "|" + sb.toString()); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) { @@ -882,26 +901,56 @@ public class LiveTextRender { } int lengthContent = builder.length(); //这一段先别删,万一后面要改内容换行呢 - /* sb.clear(); - sb.append(builder).append(bean.getContent()); + // TODO 试试 “空Unicode” + /*sb.clear(); + TAG = "文字渲染2"; + String content = bean.getContent(); + Log.i(TAG, "renderChat: " + content); + sb.append(name).append(content); + SpannableStringBuilder csb = null; measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + sb.clear(); + sb.append(prefixName); + prefixEmpty = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + StringBuilder stringBuilder = new StringBuilder(); if (measuredText > width) { sb.clear(); - sb.append(builder); - for (int i = 0; i < bean.getContent().length(); i++) { - sb.append(bean.getContent().charAt(i)); - measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - if (measuredText + 3 > width) { - bean.setContent(bean.getContent().substring(0, i) + "\n"+ bean.getContent().substring(i)); - bean.setContent(""); - break; + sb.append(name); + float lineWidth = 0; + for (int i = 0; i < content.length(); i++) { + char charAt = content.charAt(i); + sb.append(charAt); + lineWidth += textView.getPaint().measureText(String.valueOf(charAt)) + prefixEmpty; + prefixEmpty = 0; + textView.setText(sb); + Log.i(TAG, "renderChat: TextView是否换行:" + textView.getText().toString().split("\n").length); + Log.i(TAG, "逐测算|" + lineWidth + " width|" + width + "|" + sb.toString()); + if (lineWidth > width) { + Log.i(TAG, "renderChat: 换行:" + charAt); + if (!stringBuilder.toString().endsWith("\n")) { + stringBuilder.append("\n"); + } + lineWidth = 0; + --i; + } else { + Log.i(TAG, "renderChat: 直接加入:" + charAt); + stringBuilder.append(content.charAt(i)); } + } + if (stringBuilder.toString().endsWith("\n")) { + Log.i(TAG, "需要删除回车"); + stringBuilder.deleteCharAt(stringBuilder.length() - 1); + } + Log.i(TAG, "分行后内容:" + stringBuilder.toString()); + bean.setContent(stringBuilder.toString()); } */ + builder.append(bean.getContent()); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getContentColor())) { + Log.i(TAG, "lengthContent: " + lengthContent + "|content: " + bean.getContent().length() + "|max: " + (lengthContent + bean.getContent().length())); builder.setSpan(new ForegroundColorSpan(Color.parseColor(bean.getContentColor())), lengthContent, lengthContent + bean.getContent().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (bean.getType() == LiveChatBean.LIGHT) { @@ -913,6 +962,7 @@ public class LiveTextRender { builder.setSpan(new VerticalImageSpan(heartDrawable), length - 1, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } + //textView.setText(""); return builder; } diff --git a/live/src/main/res/layout/item_live_chat.xml b/live/src/main/res/layout/item_live_chat.xml index da2996682..a6e5fddfb 100644 --- a/live/src/main/res/layout/item_live_chat.xml +++ b/live/src/main/res/layout/item_live_chat.xml @@ -16,7 +16,9 @@ android:layout_marginRight="9dp" android:paddingBottom="7dp" android:textColor="#fff" + android:breakStrategy="simple" android:textSize="12sp" + tools:text="aaaaaaaaa111111111111111111111111111111111111111111111111111111111" android:visibility="visible" tools:ignore="RtlHardcoded" /> From 419e3a7ab5931caeb960e01547601cce8482371d Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Wed, 5 Jun 2024 13:27:22 +0800 Subject: [PATCH 55/64] =?UTF-8?q?fix[=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FaceUnity/build.gradle | 2 +- Share/build.gradle | 2 +- app/build.gradle | 3 ++- baidu/build.gradle | 2 +- beauty/build.gradle | 2 +- build.gradle | 2 +- common/build.gradle | 4 ++-- config.gradle | 14 +++++++------- .../faceunity/utils/egl/GLFrameBuffer.java | 4 ++-- live/build.gradle | 2 +- .../yunbao/live/activity/LiveSwAnchorActivity.java | 11 ++++++----- .../com/yunbao/live/socket/SocketSwChatUtil.java | 2 +- .../com/yunbao/live/socket/SocketSwClient.java | 1 - live/src/main/res/layout/view_live_room.xml | 4 ++-- main/build.gradle | 2 +- pluginsForAnchor/build.gradle | 2 +- video/build.gradle | 2 +- 17 files changed, 31 insertions(+), 30 deletions(-) diff --git a/FaceUnity/build.gradle b/FaceUnity/build.gradle index e69ef51ea..99cc08f51 100644 --- a/FaceUnity/build.gradle +++ b/FaceUnity/build.gradle @@ -33,7 +33,7 @@ android { versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { - abiFilters "armeabi-v7a", "arm64-v8a" + abiFilters "armeabi-v7a", "arm64-v8a","x86","x86_64" } } aaptOptions { diff --git a/Share/build.gradle b/Share/build.gradle index e3acfbeca..d312a0a6e 100644 --- a/Share/build.gradle +++ b/Share/build.gradle @@ -33,7 +33,7 @@ android { versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { - abiFilters "armeabi-v7a", "arm64-v8a" + abiFilters "armeabi-v7a", "arm64-v8a","x86","x86_64" } } aaptOptions { diff --git a/app/build.gradle b/app/build.gradle index 0a84badf9..3c5940adb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -257,7 +257,8 @@ android { multiDexEnabled true ndk { // TODO: 谷歌商城需要兼容两个平台 - abiFilters "armeabi-v7a", "arm64-v8a" + //abiFilters "armeabi-v7a", "arm64-v8a" + abiFilters "armeabi-v7a", "arm64-v8a","x86","x86_64" } javaCompileOptions { annotationProcessorOptions { diff --git a/baidu/build.gradle b/baidu/build.gradle index 61deab963..336b61624 100644 --- a/baidu/build.gradle +++ b/baidu/build.gradle @@ -31,7 +31,7 @@ android { versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { - abiFilters "armeabi-v7a","arm64-v8a" + abiFilters "armeabi-v7a","arm64-v8a","x86","x86_64" } } buildTypes { diff --git a/beauty/build.gradle b/beauty/build.gradle index a41bf38a8..b8e03678c 100644 --- a/beauty/build.gradle +++ b/beauty/build.gradle @@ -31,7 +31,7 @@ android { versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { - abiFilters "armeabi-v7a","arm64-v8a" + abiFilters "armeabi-v7a","arm64-v8a","x86","x86_64" } } aaptOptions { diff --git a/build.gradle b/build.gradle index a388b398e..50b7646dd 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ task clean(type: Delete) { ext { IS_PUBLISH_LOCAL=true LIB_VERSION="1.0.6" - AGORA_RTC_SDK= 'io.agora.rtc:agora-special-full:4.1.1.28' + AGORA_RTC_SDK= 'io.agora.rtc:agora-special-full:4.2.6.12' // AGORA_RTC_SDK= "${rootProject.rootDir.absolutePath}/sdk" // AGORA_RTC_SDK="io.agora.rtc:full-sdk:4.2.6" } diff --git a/common/build.gradle b/common/build.gradle index 9e4efa8e3..dfc910ce1 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -14,7 +14,7 @@ android { versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { - abiFilters "armeabi-v7a", "arm64-v8a" + abiFilters "armeabi-v7a", "arm64-v8a","x86","x86_64" } } @@ -212,7 +212,7 @@ dependencies { api 'com.yanzhenjie.recyclerview:x:1.3.2' //华为支付插件包 -// api project(':lib_huawei') + //api project(':lib_huawei') //google插件包 api project(':lib_google') diff --git a/config.gradle b/config.gradle index dc8bef34b..717d8024b 100644 --- a/config.gradle +++ b/config.gradle @@ -4,14 +4,14 @@ ext { buildToolsVersion: "29.0.2", minSdkVersion : 21, targetSdkVersion : 33, - versionCode : 474, - versionName : "6.7.8" + versionCode : 676, + versionName : "6.6.9" ] manifestPlaceholders = [ //正式、 - //serverHost : "https://napi.yaoulive.com", + serverHost : "https://napi.yaoulive.com", // 测试 - serverHost : "https://ceshi.yaoulive.com", + //serverHost : "https://ceshi.yaoulive.com", buildTime : new Date().format("MM-dd HH:mm", TimeZone.getTimeZone("GMT+8")), @@ -22,11 +22,11 @@ ext { baiduAppSecretKey: "nEVSgmuGpU0pjPr6VleEGGAl0hzGW52S", -// true表示谷歌支付 false 0 链接包 1 谷歌包 2华为包 3 samsung包 - isGooglePlay : 1, +// true表示谷歌支付 false 0 链接包(isPluginModel-> true) 1 谷歌包 2华为包 3 samsung包 + isGooglePlay : 0, //是否上报异常日志 isUploadLog : true, //是否打包成插件包模式 - isPluginModel : false, + isPluginModel : true, ] } diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java index ff8495f5a..3b61c1c73 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/utils/egl/GLFrameBuffer.java @@ -115,10 +115,10 @@ public class GLFrameBuffer { synchronized (EglBase.lock){ if(textureType == GLES11Ext.GL_TEXTURE_EXTERNAL_OES){ - drawer.drawOes(textureId,0, matrix, mWidth, mHeight, 0, 0, mWidth, mHeight); + drawer.drawOes(textureId,matrix, mWidth, mHeight, 0, 0, mWidth, mHeight); }else{ - drawer.drawRgb(textureId,0, matrix, mWidth, mHeight, 0, 0, mWidth, mHeight); + drawer.drawRgb(textureId, matrix, mWidth, mHeight, 0, 0, mWidth, mHeight); } } diff --git a/live/build.gradle b/live/build.gradle index 6f1d3dc42..319d5a3dd 100644 --- a/live/build.gradle +++ b/live/build.gradle @@ -1 +1 @@ -apply plugin: 'com.android.library' apply plugin: 'img-optimizer' apply plugin: 'kotlin-android' android { compileSdkVersion rootProject.ext.android.compileSdkVersion buildToolsVersion rootProject.ext.android.buildToolsVersion aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false packagingOptions { pickFirst "lib/armeabi/libyuvutils.so" pickFirst "lib/arm64-v8a/libyuvutils.so" pickFirst "lib/armeabi-v7a/libyuvutils.so" pickFirst "lib/armeabi/libyuvtools.so" pickFirst "lib/arm64-v8a/libyuvtools.so" pickFirst "lib/armeabi-v7a/libyuvtools.so" exclude "lib/arm64-v8a/libmmcv_api_handgesture.so" exclude "lib/arm64-v8a/libmmcv_api_express.so" exclude "lib/arm64-v8a/libMediaEncoder.so" exclude "lib/arm64-v8a/libarcore_sdk_c.so" exclude "lib/arm64-v8a/libmediadecoder.so" exclude "lib/arm64-v8a/libMediaMuxer.so" exclude "lib/arm64-v8a/libarcore_sdk_jni.so" exclude "lib/arm64-v8a/libMediaUtils.so" exclude "lib/arm64-v8a/libcosmosffmpeg.so" } defaultConfig { minSdkVersion rootProject.ext.android.minSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion versionCode rootProject.ext.android.versionCode versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { abiFilters "armeabi-v7a", "arm64-v8a" } javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } aaptOptions { cruncherEnabled = false useNewCruncher = false } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } kotlinOptions { allWarningsAsErrors = true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { flatDir { dirs 'libs', '../libs' } mavenCentral() } dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.0' implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation (name:'../libs/beautysdk-202202241203',ext:'aar') implementation (name:'../libs/svgaplayer-release-v1.2.1',ext:'aar') //socket.io implementation('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } //common api project(path:':lib_faceunity')//新娱美颜 api project(':Share')//分享 annotationProcessor rootProject.ext.dependencies["arouter-compiler"] //工具 api rootProject.ext.dependencies["blank-utilcode"] implementation 'com.eightbitlab:blurview:1.6.6' implementation 'com.google.code.gson:gson:2.8.6' implementation "com.getkeepsafe.relinker:relinker:1.4.4" //ExoPlayer,腾讯的播放器不支持无缝切换 implementation 'com.google.android.exoplayer:exoplayer:2.18.2' implementation 'com.google.android.exoplayer:exoplayer-core:2.18.2@aar' } \ No newline at end of file +apply plugin: 'com.android.library' apply plugin: 'img-optimizer' apply plugin: 'kotlin-android' android { compileSdkVersion rootProject.ext.android.compileSdkVersion buildToolsVersion rootProject.ext.android.buildToolsVersion aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false packagingOptions { pickFirst "lib/armeabi/libyuvutils.so" pickFirst "lib/arm64-v8a/libyuvutils.so" pickFirst "lib/armeabi-v7a/libyuvutils.so" pickFirst "lib/armeabi/libyuvtools.so" pickFirst "lib/arm64-v8a/libyuvtools.so" pickFirst "lib/armeabi-v7a/libyuvtools.so" exclude "lib/arm64-v8a/libmmcv_api_handgesture.so" exclude "lib/arm64-v8a/libmmcv_api_express.so" exclude "lib/arm64-v8a/libMediaEncoder.so" exclude "lib/arm64-v8a/libarcore_sdk_c.so" exclude "lib/arm64-v8a/libmediadecoder.so" exclude "lib/arm64-v8a/libMediaMuxer.so" exclude "lib/arm64-v8a/libarcore_sdk_jni.so" exclude "lib/arm64-v8a/libMediaUtils.so" exclude "lib/arm64-v8a/libcosmosffmpeg.so" } defaultConfig { minSdkVersion rootProject.ext.android.minSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion versionCode rootProject.ext.android.versionCode versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { abiFilters "armeabi-v7a", "arm64-v8a","x86","x86_64" } javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } aaptOptions { cruncherEnabled = false useNewCruncher = false } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } kotlinOptions { allWarningsAsErrors = true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { flatDir { dirs 'libs', '../libs' } mavenCentral() } dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.0' implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation (name:'../libs/beautysdk-202202241203',ext:'aar') implementation (name:'../libs/svgaplayer-release-v1.2.1',ext:'aar') //socket.io implementation('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } //common api project(path:':lib_faceunity')//新娱美颜 api project(':Share')//分享 annotationProcessor rootProject.ext.dependencies["arouter-compiler"] //工具 api rootProject.ext.dependencies["blank-utilcode"] implementation 'com.eightbitlab:blurview:1.6.6' implementation 'com.google.code.gson:gson:2.8.6' implementation "com.getkeepsafe.relinker:relinker:1.4.4" //ExoPlayer,腾讯的播放器不支持无缝切换 implementation 'com.google.android.exoplayer:exoplayer:2.18.2' implementation 'com.google.android.exoplayer:exoplayer-core:2.18.2@aar' } \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index 1c31f398a..3c288e87f 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -1652,15 +1652,15 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl } break; case LEAVE_DR_ROOM: - if (mLiveSwLinkMicPkPresenter != null) { - mLiveSwLinkMicPkPresenter.leaveDRRoom(); - } if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.seisShowGif(true); - if(isDRPK==1){ + if(DRPKing==1){ mLiveRoomViewHolder.endDRGif(); } } + if (mLiveSwLinkMicPkPresenter != null) { + mLiveSwLinkMicPkPresenter.leaveDRRoom(); + } SWManager.get().setDrPkNumClarity(1); // if (mLiveRoomViewHolder != null) { // mLiveRoomViewHolder.hotAddVisibility(false); @@ -1943,8 +1943,9 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl } break; } - } + + } @Subscribe(threadMode = ThreadMode.MAIN) public void onAllServerNotifyFFGGGDJANEvent(AllServerNotifyFFGGGDJANEvent event) { if (mLiveRoomViewHolder != null) { diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java index 91f5e2239..0efeb8a44 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java @@ -104,7 +104,7 @@ public class SocketSwChatUtil { .param("vip_type", u.getVip().getType()) .param("guard_type", IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getGuardType()) .param("medal_name", u.getMedalName()) - .param("medal_level", model.getMedalLevel()) + .param("medal_level", u.getMedalLevel()) .param("good_num", u.getGoodnum()) .param("ct", content) .param("noble_id", String.valueOf(model.getNobleId())) diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index bb4aa29e7..16f6c2eb1 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -335,7 +335,6 @@ public class SocketSwClient { DRPKing = 1; } else if (action3 == 5) {//结束PK // endDRGif(); - DRPKing= -1; LiveRoomViewHolder.d_pk_view.setVisibility(View.GONE); if (LiveSwAnchorActivity.mLiveAnchorViewHolder != null) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); diff --git a/live/src/main/res/layout/view_live_room.xml b/live/src/main/res/layout/view_live_room.xml index da44880cd..501c5c43a 100644 --- a/live/src/main/res/layout/view_live_room.xml +++ b/live/src/main/res/layout/view_live_room.xml @@ -1491,12 +1491,11 @@ android:visibility="visible" /> - Date: Wed, 5 Jun 2024 15:12:35 +0800 Subject: [PATCH 56/64] =?UTF-8?q?fix[=E4=BF=AE=E5=A4=8D-=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E6=88=BF=E6=B6=88=E6=81=AF=E9=97=AE=E9=A2=98]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 76 +++++++++++-------- .../common/event/SudGameSocketImEvent.java | 9 +++ .../manager/imrongcloud/GameSwMicManager.java | 8 ++ .../yunbao/live/views/LiveRoomViewHolder.java | 10 +-- live/src/main/res/layout/view_live_room.xml | 2 +- 5 files changed, 67 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index af4de4c66..90b419900 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -30,6 +30,7 @@ import com.tencent.imsdk.v2.V2TIMGroupMemberInfo; import com.tencent.imsdk.v2.V2TIMManager; import com.tencent.imsdk.v2.V2TIMSimpleMsgListener; import com.tencent.imsdk.v2.V2TIMUserInfo; +import com.yunbao.common.http.Data; import com.yunbao.common.manager.OpenAdManager; import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.BuildConfig; @@ -65,6 +66,7 @@ import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import io.rong.imkit.config.RongConfigCenter; @@ -123,7 +125,7 @@ public class AppContext extends CommonAppContext { @Override public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { activities.add(new WeakReference<>(activity)); - if(activity instanceof LoginActivity){ + if (activity instanceof LoginActivity) { AppManager.getInstance().clear(); } CrashSaveBean.getInstance().setActivitySize(activities); @@ -205,7 +207,7 @@ public class AppContext extends CommonAppContext { RongcloudIMManager.addRongcloudIMOnReceiveMessageListener(new RongIMClient.OnReceiveMessageWrapperListener() { @Override public boolean onReceived(io.rong.imlib.model.Message message, int i, boolean b, boolean b1) { - Log.e("wewe", message.getConversationType() + "112121 "+message.getContent()); + Log.e("wewe", message.getConversationType() + "112121 " + message.getContent()); MessageIMManager.get(sInstance).getSystemForRongcloud(message); //融云直播间聊天 Message msg = Message.obtain(); @@ -216,41 +218,51 @@ public class AppContext extends CommonAppContext { if (content.getContent().contains("_method_")) { msg.obj = content.getContent(); //观众页面 + + String time = String.valueOf(new Date().getTime()); //声网 - if (SocketSwClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { - SocketSwClient.mSocketHandler.sendMessage(msg); - } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 - SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); - JSONObject map = received.getMsg().getJSONObject(0); - sendStartAnchorLive(map); - } else if (message.getTargetId().contains("v")) { - String contentJson = ((TextMessage) message.getContent()).getContent(); - Log.e("wewe", contentJson); - SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); - Bus.get().post(sudGameSocketImEvent); - } - //主播页面 - if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.sendMessage(msg); + if (SocketSwClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { + SocketSwClient.mSocketHandler.sendMessage(msg); + } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 + SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); + JSONObject map = received.getMsg().getJSONObject(0); + sendStartAnchorLive(map); + } else if (message.getTargetId().contains("v")) { + String contentJson = ((TextMessage) message.getContent()).getContent(); + Log.e("wewe", contentJson); + SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); + if (sudGameSocketImEvent.getMsg().isEmpty()) { + return false; } + sudGameSocketImEvent.getMsg().get(0).setTime(time); + Bus.get().post(sudGameSocketImEvent); + } + //主播页面 + if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.sendMessage(msg); + } //融云 - if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { - SocketRyClient.mSocketHandler.sendMessage(msg); - } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 - SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); - JSONObject map = received.getMsg().getJSONObject(0); - sendStartAnchorLive(map); - } else if (message.getTargetId().contains("v")) { - String contentJson = ((TextMessage) message.getContent()).getContent(); - Log.e("wewe", contentJson); - SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); - Bus.get().post(sudGameSocketImEvent); - } - //主播页面 - if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.sendMessage(msg); + if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) { + SocketRyClient.mSocketHandler.sendMessage(msg); + } else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知 + SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class); + JSONObject map = received.getMsg().getJSONObject(0); + sendStartAnchorLive(map); + } else if (message.getTargetId().contains("v")) { + String contentJson = ((TextMessage) message.getContent()).getContent(); + Log.e("wewe", contentJson); + SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); + if (sudGameSocketImEvent.getMsg().isEmpty()) { + return false; } + sudGameSocketImEvent.getMsg().get(0).setTime(time); + Bus.get().post(sudGameSocketImEvent); + } + //主播页面 + if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.sendMessage(msg); + } } else if (message.getConversationType() == Conversation.ConversationType.PRIVATE) {//私聊信息 EventBus.getDefault().post(message); } diff --git a/common/src/main/java/com/yunbao/common/event/SudGameSocketImEvent.java b/common/src/main/java/com/yunbao/common/event/SudGameSocketImEvent.java index 31d9ec28e..6956f7d18 100644 --- a/common/src/main/java/com/yunbao/common/event/SudGameSocketImEvent.java +++ b/common/src/main/java/com/yunbao/common/event/SudGameSocketImEvent.java @@ -53,6 +53,15 @@ public class SudGameSocketImEvent extends BaseModel { private String method; @SerializedName("equipment") private String equipment; + private String time; + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } public String getAction() { return action; diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java index b4c9abc59..2b3f90f2b 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java @@ -433,6 +433,8 @@ public class GameSwMicManager { }); } + String lastTime = ""; + /** * 处理游戏房Im消息 */ @@ -441,6 +443,11 @@ public class GameSwMicManager { List msgDTOS = socketImModel.getMsg(); if (msgDTOS.isEmpty()) return; SudGameSocketImEvent.MsgDTO msgDTO = msgDTOS.get(0); + + if(lastTime.equals(msgDTO.getTime())){ + return; + } + lastTime = msgDTO.getTime(); //正常文字消息 if (TextUtils.equals(msgDTO.getMethod(), "SendMsg")) { getView().insertItem(new SudGameChatImModel().setWelcomMessage(false).setNickname(msgDTO.getUname()).setTextMessage(msgDTO.getCt())); @@ -498,6 +505,7 @@ public class GameSwMicManager { String contentJson = ((TextMessage) message.getContent()).getContent(); Log.e("wewe", contentJson); SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); + sudGameSocketImEvent.getMsg().get(0).setTime("11"); processingMessage(sudGameSocketImEvent); } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 1f520ef19..244446584 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -407,6 +407,11 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis return this; } + @Override + protected int getLayoutId() { + return R.layout.view_live_room; + } + @Subscribe(threadMode = ThreadMode.MAIN) public void onUpdata(String str) { if ("svga_new_user_gif".equals(str)) { @@ -713,11 +718,6 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis sudNameHandler.postDelayed(sudNameRunnable, 10000); } - @Override - protected int getLayoutId() { - return R.layout.view_live_room; - } - private View sudGameMin; public void onShowHideEvent() { diff --git a/live/src/main/res/layout/view_live_room.xml b/live/src/main/res/layout/view_live_room.xml index 501c5c43a..64345b088 100644 --- a/live/src/main/res/layout/view_live_room.xml +++ b/live/src/main/res/layout/view_live_room.xml @@ -691,7 +691,7 @@ android:layout_height="27dp" android:layout_below="@id/open_sidebar" android:layout_alignParentRight="true" - android:layout_marginTop="16dp" + android:layout_marginTop="20dp" android:layout_marginRight="9dp" android:background="@drawable/bg_live_other_ico" android:gravity="center"> From 62e50ae310fb018deef87cd2f9609a682fdf8404 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Wed, 5 Jun 2024 16:06:04 +0800 Subject: [PATCH 57/64] =?UTF-8?q?fix[=E5=A3=B0=E7=BD=91APPId]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/CommonAppConfig.java | 26 +++++++++---------- .../faceunity/agora/SWAuManager.java | 4 +-- .../beautyapi/faceunity/agora/SWManager.java | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index fb294a2ef..9f78b5fac 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -80,18 +80,26 @@ public class CommonAppConfig { public static String SWToken = ""; //声网Token public static final String SWChannelPrefix = "g"; //测试服 - //public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; + public static final String SWAPPId_debug = "4cf0376582d742ac8a96778b25b1079e"; //正式服 public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; + public static String getSwAppId() { + if (BuildConfig.DEBUG) { + return SWAPPId_debug; + } else { + return SWAPPId; + } + } /** * 获取通道 + * * @return */ public static String getChannelName() { - return SWChannelPrefix+ getInstance().getUid(); + return SWChannelPrefix + getInstance().getUid(); } private CommonAppConfig() { @@ -135,8 +143,7 @@ public class CommonAppConfig { public String getUid() { if (TextUtils.isEmpty(mUid)) { - String[] uidAndToken = SpUtil.getInstance() - .getMultiStringValue(new String[]{SpUtil.UID, SpUtil.TOKEN}); + String[] uidAndToken = SpUtil.getInstance().getMultiStringValue(new String[]{SpUtil.UID, SpUtil.TOKEN}); if (uidAndToken != null) { if (!TextUtils.isEmpty(uidAndToken[0]) && !TextUtils.isEmpty(uidAndToken[1])) { mUid = uidAndToken[0]; @@ -327,9 +334,7 @@ public class CommonAppConfig { mUid = null; mToken = null; mLoginIM = false; - SpUtil.getInstance().removeValue( - SpUtil.UID, SpUtil.TOKEN, SpUtil.USER_INFO, SpUtil.IM_LOGIN - ); + SpUtil.getInstance().removeValue(SpUtil.UID, SpUtil.TOKEN, SpUtil.USER_INFO, SpUtil.IM_LOGIN); } @@ -365,12 +370,7 @@ public class CommonAppConfig { mProvince = null; mCity = null; mDistrict = null; - SpUtil.getInstance().removeValue( - SpUtil.LOCATION_LNG, - SpUtil.LOCATION_LAT, - SpUtil.LOCATION_PROVINCE, - SpUtil.LOCATION_CITY, - SpUtil.LOCATION_DISTRICT); + SpUtil.getInstance().removeValue(SpUtil.LOCATION_LNG, SpUtil.LOCATION_LAT, SpUtil.LOCATION_PROVINCE, SpUtil.LOCATION_CITY, SpUtil.LOCATION_DISTRICT); } diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index 3ac3ec00f..f64ea9637 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -103,7 +103,7 @@ public class SWAuManager extends BaseCacheManager { // 创建 RtcEngineConfig 对象,并进行配置 RtcEngineConfig config = new RtcEngineConfig(); config.mContext = mContext; - config.mAppId = CommonAppConfig.SWAPPId; + config.mAppId = CommonAppConfig.getSwAppId(); config.mEventHandler = mRtcEventHandler; // 创建并初始化 RtcEngine mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); @@ -125,7 +125,7 @@ public class SWAuManager extends BaseCacheManager { if(mRtcEngine==null){ RtcEngineConfig config = new RtcEngineConfig(); config.mContext = mContext; - config.mAppId = CommonAppConfig.SWAPPId; + config.mAppId = CommonAppConfig.getSwAppId(); config.mEventHandler = mEventHandler; // 创建并初始化 RtcEngine mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 1dbcc7308..80711372a 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -95,7 +95,7 @@ public class SWManager extends BaseCacheManager { // 创建 RtcEngineConfig 对象,并进行配置 RtcEngineConfig config = new RtcEngineConfig(); config.mContext = mContext; - config.mAppId = CommonAppConfig.SWAPPId; + config.mAppId = CommonAppConfig.getSwAppId(); config.mEventHandler = mRtcEventHandler; // 创建并初始化 RtcEngine mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); From c91947ce713ecfb98eaebaa4e283619b4042a24c Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 5 Jun 2024 16:37:24 +0800 Subject: [PATCH 58/64] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8C=96=E5=A3=B0?= =?UTF-8?q?=E7=BD=91AppId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 3 +++ .../src/main/java/com/yunbao/common/CommonAppConfig.java | 7 ++++--- config.gradle | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0b83186e1..adc2c0efc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -165,6 +165,9 @@ + diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index 9f78b5fac..c72a2207d 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -38,6 +38,7 @@ public class CommonAppConfig { //是否为插件包模式 public static final boolean IS_PLUGIN_MODEL = getMetaDataBoolean("IS_PLUGIN_MODEL"); public static final String BUILD_TIME = getMetaDataString("BUILD_TIME"); + public static final boolean IS_SW_RELEASE = getMetaDataBoolean("SW_RELEASE_MODEL"); //外部sd卡 public static final String DCMI_PATH = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath(); @@ -85,10 +86,10 @@ public class CommonAppConfig { public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; public static String getSwAppId() { - if (BuildConfig.DEBUG) { - return SWAPPId_debug; - } else { + if (IS_SW_RELEASE) { return SWAPPId; + } else { + return SWAPPId_debug; } } diff --git a/config.gradle b/config.gradle index 717d8024b..1bd0a5f16 100644 --- a/config.gradle +++ b/config.gradle @@ -17,6 +17,8 @@ ext { //百度语音识别 + swReleaseModel : true, //true声网正式服 false测试服 + baiduAppId : "23774720", baiduAppKey : "zgCgFhUKEOV7I3ZXDFpTfnRB", From 73847c46a3a4d6fb27d1809714c871735507e0b3 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 7 Jun 2024 14:50:39 +0800 Subject: [PATCH 59/64] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E6=88=BF=E5=8F=91=E8=A8=80=E9=87=8D=E5=A4=8D/=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=B4=B5=E6=97=8F=E4=B8=8D=E6=98=BE=E7=A4=BA=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/shayu/phonelive/AppContext.java | 4 ++-- .../yunbao/common/manager/imrongcloud/GameSwMicManager.java | 6 +----- config.gradle | 4 ++-- gradle.properties | 6 +++--- .../main/java/com/yunbao/live/socket/SocketRyClient.java | 3 ++- .../main/java/com/yunbao/live/socket/SocketSwChatUtil.java | 1 + .../main/java/com/yunbao/live/socket/SocketSwClient.java | 2 ++ 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 90b419900..101f0d95b 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -228,14 +228,14 @@ public class AppContext extends CommonAppContext { JSONObject map = received.getMsg().getJSONObject(0); sendStartAnchorLive(map); } else if (message.getTargetId().contains("v")) { - String contentJson = ((TextMessage) message.getContent()).getContent(); + /*String contentJson = ((TextMessage) message.getContent()).getContent(); Log.e("wewe", contentJson); SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class); if (sudGameSocketImEvent.getMsg().isEmpty()) { return false; } sudGameSocketImEvent.getMsg().get(0).setTime(time); - Bus.get().post(sudGameSocketImEvent); + Bus.get().post(sudGameSocketImEvent);*/ } //主播页面 if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketSwClient.mSocketHandler != null) { diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java index 2b3f90f2b..467dbecd3 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/GameSwMicManager.java @@ -433,7 +433,6 @@ public class GameSwMicManager { }); } - String lastTime = ""; /** * 处理游戏房Im消息 @@ -444,10 +443,7 @@ public class GameSwMicManager { if (msgDTOS.isEmpty()) return; SudGameSocketImEvent.MsgDTO msgDTO = msgDTOS.get(0); - if(lastTime.equals(msgDTO.getTime())){ - return; - } - lastTime = msgDTO.getTime(); + //正常文字消息 if (TextUtils.equals(msgDTO.getMethod(), "SendMsg")) { getView().insertItem(new SudGameChatImModel().setWelcomMessage(false).setNickname(msgDTO.getUname()).setTextMessage(msgDTO.getCt())); diff --git a/config.gradle b/config.gradle index 1bd0a5f16..b809fb2cd 100644 --- a/config.gradle +++ b/config.gradle @@ -11,7 +11,7 @@ ext { //正式、 serverHost : "https://napi.yaoulive.com", // 测试 - //serverHost : "https://ceshi.yaoulive.com", +// serverHost : "https://ceshi.yaoulive.com", buildTime : new Date().format("MM-dd HH:mm", TimeZone.getTimeZone("GMT+8")), @@ -29,6 +29,6 @@ ext { //是否上报异常日志 isUploadLog : true, //是否打包成插件包模式 - isPluginModel : true, + isPluginModel : false, ] } diff --git a/gradle.properties b/gradle.properties index f8c588910..5759f9c1a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ #Thu Feb 04 00:05:45 CST 2021 android.injected.testOnly=false org.gradle.daemon=true -org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.parallel=true org.gradle.configureondemand=true @@ -23,8 +23,8 @@ android.enableJetifier=true systemProp.http.proxyHost=127.0.0.1 systemProp.https.proxyHost=127.0.0.1 -systemProp.https.proxyPort=10809 -systemProp.http.proxyPort=10809 +systemProp.https.proxyPort=7890 +systemProp.http.proxyPort=7890 #android.enableR8.fullMode=true \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index f6b19583b..3d32dc0ea 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -1048,7 +1048,7 @@ public class SocketRyClient { chatBean.setBubble(obj.getString("bubble")); chatBean.setMedal(obj.getString("medal")); chatBean.setMedal_new(obj.getString("medal_new")); - chatBean.setMedal_new_en(map.getString("medal_new_en")); + chatBean.setMedal_new_en(obj.getString("medal_new_en")); chatBean.setHot_num(obj.getString("hot_num")); UserBean.DressBean dressBean = new UserBean.DressBean(); dressBean.setAvatar_frame(obj.getString("avatar_frame")); @@ -1069,6 +1069,7 @@ public class SocketRyClient { FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); u.setFansLevel(obj.getIntValue("medal_level")); u.setFansEnterRoomUrl(obj.getString("medal_backgroup_thumb")); + CommonAppConfig.getInstance().getUserBean().getDress().setMedal_new_en(obj.getString("medal_new_en")); if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); mListener.onEnterRoom(new LiveEnterRoomBean(u, chatBean)); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java index 0efeb8a44..017e8c6da 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java @@ -99,6 +99,7 @@ public class SocketSwChatUtil { .param("medal_honor", u.getMedal_no_display_src()) .param("medal", u.getDress().getMedal()) .param("medal_new", u.getDress().getMedal_new()) + .param("medal_new_en", u.getDress().getMedal_new_en()) .param("uid", u.getId()) .param("liangname", u.getGoodName()) .param("vip_type", u.getVip().getType()) diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index 16f6c2eb1..0241f086e 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -954,6 +954,7 @@ public class SocketSwClient { chatBean.setBubble(obj.getString("bubble")); chatBean.setMedal(obj.getString("medal")); chatBean.setMedal_new(obj.getString("medal_new")); + chatBean.setMedal_new_en(obj.getString("medal_new_en")); chatBean.setHot_num(obj.getString("hot_num")); UserBean.DressBean dressBean = new UserBean.DressBean(); dressBean.setAvatar_frame(obj.getString("avatar_frame")); @@ -971,6 +972,7 @@ public class SocketSwClient { //增加粉丝徽章信息 chatBean.setMedalNmae(obj.getString("medal_name")); chatBean.setUserNiceName(obj.getString("user_nicename"));//名字 + CommonAppConfig.getInstance().getUserBean().getDress().setMedal_new_en(obj.getString("medal_new_en")); FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); u.setFansLevel(obj.getIntValue("medal_level")); u.setFansEnterRoomUrl(obj.getString("medal_backgroup_thumb")); From d70c3a8b274f94dfbecd5cd3afa282786cf2b162 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 7 Jun 2024 16:53:48 +0800 Subject: [PATCH 60/64] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E6=88=BF=E5=8F=91=E8=A8=80=E9=87=8D=E5=A4=8D/=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=B4=B5=E6=97=8F=E4=B8=8D=E6=98=BE=E7=A4=BA=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- live/src/main/java/com/yunbao/live/socket/SocketRyClient.java | 1 + live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java | 1 + live/src/main/java/com/yunbao/live/socket/SocketSwClient.java | 1 + 3 files changed, 3 insertions(+) diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index 3d32dc0ea..f171b12b0 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -1007,6 +1007,7 @@ public class SocketRyClient { try { //增加粉丝徽章信息 chatBean.setMedalNmae(map.getString("medal_name")); + chatBean.setMedal_new_en(map.getString("medal_new_en")); FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java index 017e8c6da..c769a988d 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwChatUtil.java @@ -181,6 +181,7 @@ public class SocketSwChatUtil { .param("bubble", u.getDress().getBubble()) .param("medal", u.getDress().getMedal()) .param("medal_new", u.getDress().getMedal_new()) + .param("medal_new_en", u.getDress().getMedal_new_en()) .param("guard_type", IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getGuardType()) .param("medal_name", u.getMedalName()) .param("medal_level", u.getMedalLevel()) diff --git a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java index 0241f086e..76cd96cf1 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketSwClient.java @@ -913,6 +913,7 @@ public class SocketSwClient { try { //增加粉丝徽章信息 chatBean.setMedalNmae(map.getString("medal_name")); + chatBean.setMedal_new_en(map.getString("medal_new_en")); FansModel fansMedalBean = new NewLevelManager(mContext).getFansModel(map.getIntValue("medal_level")); if (fansMedalBean != null) chatBean.setMedalLevelImageUrl(fansMedalBean.getThumb()); From 5ae55f87faf5aefe796d39e35e7f428dbbcf8382 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Tue, 11 Jun 2024 14:08:45 +0800 Subject: [PATCH 61/64] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A3=B0=E7=BD=91?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E4=BC=9A=E7=99=BD=E5=B1=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E8=B0=83=E6=95=B4=E6=A8=A1=E5=9D=97=E9=97=B4?= =?UTF-8?q?=E7=9A=84=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/build.gradle | 3 +++ config.gradle | 4 +-- lib_faceunity/build.gradle | 1 + .../faceunity/agora/SWAuManager.java | 26 +++++++++---------- live/build.gradle | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/common/build.gradle b/common/build.gradle index dfc910ce1..75a00d20a 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -227,4 +227,7 @@ dependencies { //声网SDK //api 'io.agora.rtc:agora-special-full:4.2.6.245' + //ExoPlayer,腾讯的播放器不支持无缝切换 + api 'com.google.android.exoplayer:exoplayer:2.18.2' + api 'com.google.android.exoplayer:exoplayer-core:2.18.2@aar' } diff --git a/config.gradle b/config.gradle index b809fb2cd..1b62950f7 100644 --- a/config.gradle +++ b/config.gradle @@ -9,9 +9,9 @@ ext { ] manifestPlaceholders = [ //正式、 - serverHost : "https://napi.yaoulive.com", +// serverHost : "https://napi.yaoulive.com", // 测试 -// serverHost : "https://ceshi.yaoulive.com", + serverHost : "https://ceshi.yaoulive.com", buildTime : new Date().format("MM-dd HH:mm", TimeZone.getTimeZone("GMT+8")), diff --git a/lib_faceunity/build.gradle b/lib_faceunity/build.gradle index cfa97aa94..ae0f6f9cb 100644 --- a/lib_faceunity/build.gradle +++ b/lib_faceunity/build.gradle @@ -40,6 +40,7 @@ dependencies { api "$AGORA_RTC_SDK" } api project(path: ':FaceUnity') + api project(path: ':common') } // Because the components are created only during the afterEvaluate phase, you must diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index f64ea9637..43960605d 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -3,7 +3,7 @@ package io.agora.beautyapi.faceunity.agora; import android.app.Activity; import android.content.Context; import android.util.Log; -import android.view.SurfaceView; +import android.view.TextureView; import android.widget.FrameLayout; @@ -166,8 +166,8 @@ public class SWAuManager extends BaseCacheManager { */ public void updateMyChannelView(FrameLayout frameLayout, int uid) { mRtcEngine.setupLocalVideo(null); - SurfaceView surfaceView = new SurfaceView(mContext); - surfaceView.setZOrderMediaOverlay(true); + TextureView surfaceView = new TextureView(mContext); + //surfaceView.setZOrderMediaOverlay(true); frameLayout.addView(surfaceView); VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid); @@ -185,8 +185,8 @@ public class SWAuManager extends BaseCacheManager { } else { uid = Integer.parseInt(strUid); } - // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 - SurfaceView surfaceView = new SurfaceView(mContext); + // 创建一个 TextureView 对象,并将其作为 FrameLayout 的子对象 + TextureView surfaceView = new TextureView(mContext); audienceContainer.addView(surfaceView); // 启用视频模块 @@ -228,8 +228,8 @@ public class SWAuManager extends BaseCacheManager { @Override public void run() { L.eSw("onJoinChannelSuccess:" + channel + " uid " + uid + " elapsed: " + elapsed); - SurfaceView surfaceView = new SurfaceView(mContext); - surfaceView.setZOrderMediaOverlay(true); + TextureView surfaceView = new TextureView(mContext); + // surfaceView.setZOrderMediaOverlay(true); pkContainer1.addView(surfaceView); VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, strUid); mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); @@ -308,8 +308,8 @@ public class SWAuManager extends BaseCacheManager { mContext.runOnUiThread(new Runnable() { @Override public void run() { - SurfaceView surfaceView = new SurfaceView(mContext); - surfaceView.setZOrderMediaOverlay(true); + TextureView surfaceView = new TextureView(mContext); + // surfaceView.setZOrderMediaOverlay(true); frameLayout.addView(surfaceView); VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, Integer.parseInt(toUid)); mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); @@ -389,10 +389,10 @@ public class SWAuManager extends BaseCacheManager { //设置对方主播视图 public void setupRemoteVideo(int uid) { - SurfaceView surfaceView = new SurfaceView(mContext); - surfaceView.setZOrderMediaOverlay(true); + TextureView surfaceView = new TextureView(mContext); + // surfaceView.setZOrderMediaOverlay(true); audienceContainer.addView(surfaceView); - // 将 SurfaceView 对象传入声网实时互动 SDK,设置远端视图 + // 将 TextureView 对象传入声网实时互动 SDK,设置远端视图 mRtcEngine.setupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid)); } @@ -422,7 +422,7 @@ public class SWAuManager extends BaseCacheManager { public void preloadChannel(List uids){ for (int i = 0; i Date: Tue, 11 Jun 2024 17:03:13 +0800 Subject: [PATCH 62/64] =?UTF-8?q?=E4=BF=AE=E5=A4=8Duserlist=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E4=B8=BA=E7=A9=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/live/views/PortraitLiveManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 71db9cb55..5b36482e2 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -697,7 +697,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")) { JSONArray array = pkInfo.getJSONArray("userlist"); //判断是否是多人连麦 - if (array.size() > 0) {//多人連麥 + if (array!=null&& !array.isEmpty()) {//多人連麥 if (mLivePlayViewHolder != null) { List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { @@ -783,6 +783,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } if (mLivePlayViewHolder != null) { JSONArray array = pkInfo.getJSONArray("userlist"); + if(array==null){ + array=new JSONArray(); + } List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { UserBean userBean = new UserBean(); @@ -2379,7 +2382,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe * @param time */ public void upDataPkScore(JSONArray pkScores, int time) { - L.eSw("upDataPkScore" + time); + L.eSw("upDataPkScore" + time+"|"+pkScores); + if(pkScores==null){ + return; + } this.pkScores = pkScores; if (mLiveRoomViewHolder != null) { String liveId = mLiveBean.getUid(); From b41bd3b89b4110780062cadbbe37d48129995199 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 13 Jun 2024 09:47:38 +0800 Subject: [PATCH 63/64] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=201=EF=BC=9A=E5=BC=80?= =?UTF-8?q?=E6=92=AD=E9=97=AA=E5=B1=8F=E9=97=AE=E9=A2=98=202=EF=BC=9A?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E6=88=BF=E6=B6=88=E6=81=AF=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=EF=BC=88=E6=88=96=E4=B8=8D=E6=98=BE=E7=A4=BA=EF=BC=89=203?= =?UTF-8?q?=EF=BC=9A=E6=A8=A1=E6=8B=9F=E5=99=A8=E6=88=96=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=9C=BA=E5=9E=8B=E6=BB=91=E5=8A=A8=E5=A3=B0=E7=BD=91=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=97=B4=E4=BC=9A=E7=99=BD=E5=B1=8F=E9=97=AE=E9=A2=98?= =?UTF-8?q?=204=EF=BC=9APK=E6=9D=A1=E5=9C=A8=E5=B9=B3=E6=9D=BF=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E6=98=BE=E7=A4=BA=E5=A4=AA=E9=AB=98=E9=97=AE?= =?UTF-8?q?=E9=A2=98=205=EF=BC=9APK=E6=B2=A1=E6=96=AD=E5=BC=80=E8=83=BD?= =?UTF-8?q?=E6=94=B6=E5=88=B0=E5=85=B6=E4=BB=96=E4=BA=BA=E9=82=80=E8=AF=B7?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/manager/RandomPkManager.java | 8 +- config.gradle | 10 +- .../yunbao/live/activity/LiveActivity.java | 4 + .../live/activity/LiveRyAnchorActivity.java | 2 - .../live/activity/LiveSwAnchorActivity.java | 5 +- .../live/adapter/FreePkRecyclerAdapter.java | 120 +-- .../live/presenter/AbsLinkMicPkPresenter.java | 160 ++++ .../presenter/LiveRyLinkMicPkPresenter.java | 649 ++++++++------- .../presenter/LiveSwLinkMicPkPresenter.java | 788 +++++++++--------- .../yunbao/live/views/LiveRoomViewHolder.java | 35 +- live/src/main/res/layout/view_live_room.xml | 1 + 11 files changed, 989 insertions(+), 793 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/presenter/AbsLinkMicPkPresenter.java diff --git a/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java b/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java index e0bd21378..6f89f5683 100644 --- a/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java +++ b/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java @@ -143,6 +143,9 @@ public class RandomPkManager { .randomPK(new HttpCallback() { @Override public void onSuccess(String data) { + if (debugUid != null) { + pkUid = data = debugUid; + } try { Integer.parseInt(data);//检测返回的data是否为数字uid,不是的话开始下一轮 } catch (Exception e) { @@ -152,9 +155,8 @@ public class RandomPkManager { return; } pkUid = data; - if (debugUid != null) { - pkUid = data = debugUid; - } + + ToastUtil.showDebug("随机PK:"+pkUid+"|"+data); for (OnRandomPkTimer pkTimer : randomPkTimer) { pkTimer.onStartPK(data); } diff --git a/config.gradle b/config.gradle index 1b62950f7..b25433db4 100644 --- a/config.gradle +++ b/config.gradle @@ -4,20 +4,20 @@ ext { buildToolsVersion: "29.0.2", minSdkVersion : 21, targetSdkVersion : 33, - versionCode : 676, - versionName : "6.6.9" + versionCode : 678, + versionName : "6.7.0" ] manifestPlaceholders = [ //正式、 -// serverHost : "https://napi.yaoulive.com", + serverHost : "https://napi.yaoulive.com", // 测试 - serverHost : "https://ceshi.yaoulive.com", +// serverHost : "https://ceshi.yaoulive.com", buildTime : new Date().format("MM-dd HH:mm", TimeZone.getTimeZone("GMT+8")), //百度语音识别 - swReleaseModel : true, //true声网正式服 false测试服 + swReleaseModel : true, //true 声网正式服 false 测试服 baiduAppId : "23774720", baiduAppKey : "zgCgFhUKEOV7I3ZXDFpTfnRB", diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index e4fb57369..93d0aff7a 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -169,6 +169,10 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL public static boolean isSw; + public static boolean PKing = false; + public static int isDRPK = 0; + public static int DRPKing = -1; //-1 未发起多人PK 0 多人PK前 1 多人PK中 2多人PK后 + @Override protected void main() { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 2a8a7fc6c..7f8f63d23 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -170,8 +170,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl private int mReqCount; private boolean mPaused; String mBeautySdkType; - public static int isDRPK = 0; - public static boolean PKing = false; public static int pk_nub; public static int backIndex = 0;//0=未判断,1=已判断 private FaceManager manager; diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index 3c288e87f..594a4de35 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -165,9 +165,8 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl private int mReqCount; private boolean mPaused; String mBeautySdkType; - public static int isDRPK = 0; - public static int DRPKing = -1; //-1 未发起多人PK 0 多人PK前 1 多人PK中 2多人PK后 - public static boolean PKing = false; + + public static int pk_nub; public static int backIndex = 0;//0=未判断,1=已判断 private FaceManager manager; diff --git a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java index 03130178a..6ce23c031 100644 --- a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java @@ -1,6 +1,7 @@ package com.yunbao.live.adapter; import android.content.Context; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -10,6 +11,8 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.makeramen.roundedimageview.RoundedImageView; import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.bean.RandomPkUserBean; @@ -18,6 +21,8 @@ import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; @@ -134,61 +139,82 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { ToastUtil.show(mContext.getString(R.string.free_pk_num_null)); return; } - LiveHttpUtil.getMicList(liveUid, 0, new com.yunbao.common.http.HttpCallback() { + //检查自己是不是在PK中 + LiveHttpUtil.livePkCheckLive(IMLoginManager.get(AppManager.getInstance().getMainActivity()).getUserInfo().getId() + "", "", "", new com.yunbao.common.http.HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { - System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - //非0认为未开通连麦权限 - if (code != 0) { - if (mDrPkNum == -1) { - if (WordUtil.isNewZh()) { - ToastUtil.show("邀请 " + bean.getUserNiceName() + " 发送成功"); - } else { - ToastUtil.show("invite " + bean.getUserNiceName() + " successful"); - } - mOnItemClickListener.onItemClick(bean, -1); - if(mContext instanceof LiveSwAnchorActivity){ - ((LiveSwAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), - false); - }else{ - ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), - ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() - ); - } - return; - } - if (mDrPkNum <= 0) { - if (WordUtil.isNewZh()) { - ToastUtil.show("多人次數已用完"); - } else { - ToastUtil.show("Multiple times have been used up"); - } - return; - } - yaoqing.put(bean.getId(), bean.getId()); - if (yaoqing.size() < 5) { - if(mContext instanceof LiveSwAnchorActivity){ - ((LiveSwAnchorActivity) mContext).linkDrMicAnchorApply(bean.getId(), bean.getId()); - }else{ - ((LiveRyAnchorActivity) mContext).linkDrMicAnchorApply(bean.getId(), bean.getId()); - } - } else { - ToastUtil.show(WordUtil.isNewZh() ? "多人PK最大參與人數為4人" : "The maximum number of participants in a multiplayer PK is 4 people"); - } - if (freePkRecyclerListener != null) { - freePkRecyclerListener.onClose(); - } + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (TextUtils.equals(obj.getString("ispk"), "0")) {//自己不在PK,可以发起邀请 - } else { - if (WordUtil.isNewZh()) { - ToastUtil.show("請先關閉語音連麥"); - } else { - ToastUtil.show("Please disable the voice connection first"); + LiveHttpUtil.getMicList(liveUid, 0, new com.yunbao.common.http.HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + //非0认为未开通连麦权限 + if (code != 0) { + if (mDrPkNum == -1) { + if (WordUtil.isNewZh()) { + ToastUtil.show("邀请 " + bean.getUserNiceName() + " 发送成功"); + } else { + ToastUtil.show("invite " + bean.getUserNiceName() + " successful"); + } + mOnItemClickListener.onItemClick(bean, -1); + if(mContext instanceof LiveSwAnchorActivity){ + ((LiveSwAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), + false); + }else{ + ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), + ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() + ); + } + return; + } + if (mDrPkNum <= 0) { + if (WordUtil.isNewZh()) { + ToastUtil.show("多人次數已用完"); + } else { + ToastUtil.show("Multiple times have been used up"); + } + return; + } + yaoqing.put(bean.getId(), bean.getId()); + if (yaoqing.size() < 5) { + if(mContext instanceof LiveSwAnchorActivity){ + ((LiveSwAnchorActivity) mContext).linkDrMicAnchorApply(bean.getId(), bean.getId()); + }else{ + ((LiveRyAnchorActivity) mContext).linkDrMicAnchorApply(bean.getId(), bean.getId()); + } + } else { + ToastUtil.show(WordUtil.isNewZh() ? "多人PK最大參與人數為4人" : "The maximum number of participants in a multiplayer PK is 4 people"); + } + if (freePkRecyclerListener != null) { + freePkRecyclerListener.onClose(); + } + + } else { + if (WordUtil.isNewZh()) { + ToastUtil.show("請先關閉語音連麥"); + } else { + ToastUtil.show("Please disable the voice connection first"); + } + } + } + }); + }else{ + if (WordUtil.isNewZh()) { + ToastUtil.show("請先關閉PK"); + } else { + ToastUtil.show("Please disable the PK"); + } + } } } } }); + }); mFollow.setOnClickListener(v -> { RandomPkUserBean bean = (RandomPkUserBean) itemView.getTag(); diff --git a/live/src/main/java/com/yunbao/live/presenter/AbsLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/AbsLinkMicPkPresenter.java new file mode 100644 index 000000000..8b1602252 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/presenter/AbsLinkMicPkPresenter.java @@ -0,0 +1,160 @@ +package com.yunbao.live.presenter; + +import android.text.TextUtils; +import android.util.Log; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.LiveHttpUtil; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.AppManager; + +public abstract class AbsLinkMicPkPresenter { + private boolean isSw = false; + protected boolean mIsPk;//是否已经Pk了 + public static String mPkUid;//正在Pk的对方主播的uid + public static String oldmPkUid;//正在Pk的对方主播的uid + public boolean mIsPkEnd;//pk是否结束,进入惩罚时间 + private static boolean init = false; + + public AbsLinkMicPkPresenter(boolean isSw) { + this.isSw = isSw; + } + + public static String mApplyUid;//正在申请Pk的主播的uid + protected String mApplyUrl;//正在申请Pk的主播的头像 + protected String mApplyNmae;//正在申请Pk的主播的名字 + protected boolean mIsApplyDialogShow;//是否显示了申请PK的弹窗 + + + /** + * 主播与主播PK 主播收到其他主播发过来的多人PK申请的回调 + */ + public void onLinkDRMicPkApply(UserBean u) { + Log.e("ry", "多人收到"); + showDRApplyDialogTmp(u); + } + + /** + * 主播与主播PK 主播收到其他主播发过来的PK申请的回调 + */ + public void onLinkMicPkApply(UserBean u, String stream, int by) { + Log.e("ry", u.getUserNiceName() + "单人收到" + u.getAvatar()); + mApplyUid = u.getId(); + mApplyUrl = u.getAvatar(); + mApplyNmae = u.getUserNiceName(); + if (by != 1) { + if (mIsApplyDialogShow == false) { + if (u.isRandomPk()) { + showPkDialogTmp(u); + } else { + showApplyDialogTmp(u); + } + } + } else { + isPKTmp(u); + } + } + + protected void checkPK(OnItemClickListener onItemClickListener) { + LiveHttpUtil.livePkCheckLive(IMLoginManager.get(AppManager.getInstance().getMainActivity()).getUserInfo().getId() + "", "", "", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (TextUtils.equals(obj.getString("ispk"), "1")) { + onItemClickListener.onItemClick(true, 0); + return; + } + } + } + onItemClickListener.onItemClick(false, 0); + } + }); + } + + protected void showDRApplyDialogTmp(UserBean u) { + checkPK((bean, position) -> { + if(bean){ + onDRPkRefuse(u); + return; + } + showDRApplyDialog(u); + }); + + } + + protected void showApplyDialogTmp(UserBean u) { + checkPK((bean, position) -> { + if(bean){ + onPkRefuse(u); + return; + } + showApplyDialog(u); + }); + } + + protected void showPkDialogTmp(UserBean u) { + checkPK((bean, position) -> { + if(bean){ + onPkRefuse(u); + return; + } + showPkDialog(u); + }); + } + + protected void isPKTmp(UserBean u) { + isPK(u); + } + + protected void onDRPkApplyTmp(UserBean u) { + onDRPkApply(u); + } + + protected void onDRPkTimeoutTmp(UserBean u) { + onDRPkTimeout(u); + } + + protected void onDRPkRefuseTmp(UserBean u) { + onDRPkRefuse(u); + } + + protected void onPkApplyTmp(UserBean u) { + onPkApply(u); + } + + protected void onPkTimeoutTmp(UserBean u) { + onPkTimeout(u); + } + + protected void onPkRefuseTmp(UserBean u) { + onPkRefuse(u); + } + + + protected abstract void showDRApplyDialog(UserBean u);//多人PK弹窗 + + protected abstract void showApplyDialog(UserBean u);//PK弹窗 + + protected abstract void showPkDialog(UserBean u);//随机PK弹框 + + protected abstract void isPK(UserBean bean); + + protected abstract void onDRPkApply(UserBean u); + + protected abstract void onDRPkTimeout(UserBean u); + + protected abstract void onDRPkRefuse(UserBean u); + + protected abstract void onPkApply(UserBean u); + + protected abstract void onPkTimeout(UserBean u); + + protected abstract void onPkRefuse(UserBean u); + +} diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index b911365d6..191620881 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -111,7 +111,7 @@ import io.rong.message.TextMessage; * 主播与主播PK逻辑 */ -public class LiveRyLinkMicPkPresenter implements View.OnClickListener { +public class LiveRyLinkMicPkPresenter extends AbsLinkMicPkPresenter implements View.OnClickListener { private static final int WHAT_PK_WAIT_RECEIVE = 0;//收到pk申请等待 what private static final int WHAT_PK_WAIT_SEND = 1;//发送pk申请等待 what @@ -125,17 +125,11 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { private boolean mIsAnchor;//自己是否是主播 private SocketRyClient mSocketRyClient; private ViewGroup mPkContainer; - private boolean mIsApplyDialogShow;//是否显示了申请PK的弹窗 + private boolean mAcceptPk;//是否接受连麦 - private boolean mIsPk;//是否已经Pk了 - public static String mApplyUid;//正在申请Pk的主播的uid - private String mApplyUrl;//正在申请Pk的主播的头像 - private String mApplyNmae;//正在申请Pk的主播的名字 private String mApplyStream;//正在申请Pk的主播的stream private String mLiveUid;//自己主播的uid private String mUrl;//主播的头像 - public static String mPkUid;//正在Pk的对方主播的uid - public static String oldmPkUid;//正在Pk的对方主播的uid private ProgressTextView mLinkMicWaitProgress; private int mPkWaitCount;//Pk弹窗等待倒计时Live private int mPkTimeCount;//pk时间 @@ -144,7 +138,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { private LiveLinkMicPkViewHolder mLiveLinkMicPkViewHolder; private String mPkTimeString1; private String mPkTimeString2; - private boolean mIsPkEnd;//pk是否结束,进入惩罚时间 private boolean mPkSend;//pk请求是否已经发送 private int mPkSendWaitCount;//发送pk请求后的等待时间 private String mSelfStream; @@ -214,6 +207,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { }; public LiveRyLinkMicPkPresenter(Context context, ILiveLinkMicViewHolder linkMicViewHolder, boolean isAnchor, View root) { + super(false); mContext = context; mIsAnchor = isAnchor; mRoot = root; @@ -254,6 +248,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } public LiveRyLinkMicPkPresenter(Context context, LivePushRyViewHolder linkMicViewHolder, boolean isAnchor, View root) { + super(false); mContext = context; mIsAnchor = isAnchor; mRoot = root; @@ -516,14 +511,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } } - /** - * 主播与主播PK 主播收到其他主播发过来的多人PK申请的回调 - */ - public void onLinkDRMicPkApply(UserBean u) { - Log.e("ry", "多人收到"); - showDRApplyDialog(u); - } - /** * 主播与主播PK 主播收到其他主播发过来的多人PK申请同意了的回调 */ @@ -660,26 +647,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } - /** - * 主播与主播PK 主播收到其他主播发过来的PK申请的回调 - */ - public void onLinkMicPkApply(UserBean u, String stream, int by) { - Log.e("ry", u.getUserNiceName() + "单人收到" + u.getAvatar()); - mApplyUid = u.getId(); - mApplyUrl = u.getAvatar(); - mApplyNmae = u.getUserNiceName(); - if (by != 1) { - if (mIsApplyDialogShow == false) { - if (u.isRandomPk()) { - showPkDialog(u); - } else { - showApplyDialog(u); - } - } - } else { - isPK(u); - } - } + /** * 主播与主播PK PK主播发过来的已经接受 @@ -829,7 +797,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } - private void isPK(UserBean bean) { + @Override + protected void isPK(UserBean bean) { ScreenDimenUtil util = ScreenDimenUtil.getInstance(); int mScreenWdith = util.getScreenWdith(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, mScreenWdith * 720 / 960); @@ -964,6 +933,312 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } + @Override + protected void onDRPkApply(UserBean u) { + HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("pkuid", u.getId()) + .params("type", "1") + .params("sign", "1") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msgs, String[] info) { + if (code == 0) { + Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); + HttpClient.getInstance().get("live.getdrnum", "live.getdrnum") + .execute(new HttpCallback() { + + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + if (info.length > 0) { + + JSONObject datas = JSONObject.parseObject(info[0]); + boolean agree = true; + if (datas.getIntValue("pk_num_day") <= 0) { + ToastUtil.show("多人PK次数已用完"); + agree = false; + } + boolean finalAgree = agree; + IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, agree, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + if (finalAgree == true) { + HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("roomid", u.getId()) + .execute(new HttpCallback() { + + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i("多人PK", "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LIVE_DRPK) + .param("action", 10) + .param("uid", CommonAppConfig.getInstance().getUid()); + msg1.create(); + String targetId = "g" + CommonAppConfig.getInstance().getUid(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗"); + } + }); + if (info.length == 0) { + return; + } + JSONObject obj = JSONObject.parseObject(info[0]); + JSONArray users = obj.getJSONArray("userlist"); + + //添加水印 +// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f); +// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect); + dRjoinOtherRoom(u.getId(), 1); + + for (int i = 0; i < users.size(); i++) { + JSONObject user = users.getJSONObject(i); + Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); + if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { + if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { + /** + * 向指定用户发送跨房间连麦请求 + *

+ * 1: inviterAutoMix为true时: + * + * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 + * + * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 + * + * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 + *

+ */ + IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { + @Override + public void onSuccess() { + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + }); + } + } + } + } + }); + } + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + ToastUtil.show("接受失败"); + } + }); + } else { + ToastUtil.show(msg); + } + } + + }); + + + } + } + }); + + /*LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (obj.getString("ispk").equals("0")) { + + + }else{ + ToastUtil.show(mContext.getString(R.string.pking_over)); + } + } + } + }});*/ + } + + @Override + protected void onDRPkTimeout(UserBean u) { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 8); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + mApplyUid); + } + }); + } + }); + } + + @Override + protected void onDRPkRefuse(UserBean u) { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 3); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗"); + } + }); + } + }); + } + + @Override + protected void onPkApply(UserBean u) { + LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (obj.getString("ispk").equals("0")) { + isPKTmp(u); + } else { + ToastUtil.show(mContext.getString(R.string.pking_over)); + } + } + } + } + }); + } + + @Override + protected void onPkTimeout(UserBean u) { + rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 8); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + + Log.e("ry", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + u.getId()); + } + }); + } + }); + } + + @Override + protected void onPkRefuse(UserBean u) { + onPkTimeoutTmp(u); + } + //与用户连麦 public void setUserMic(String liveid) { JSONObject msg1 = new JSONObject(); @@ -1032,7 +1307,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { /** * 显示申请PK的弹窗 */ - private void showApplyDialog(UserBean u) { + @Override + protected void showApplyDialog(UserBean u) { mIsApplyDialogShow = true; mAcceptPk = false; View v = LayoutInflater.from(mContext).inflate(R.layout.dialog_link_mic_pk_wait, null); @@ -1050,63 +1326,10 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); } if (mAcceptPk) { - - LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - JSONObject obj = JSON.parseObject(info[0]); - if (obj != null) { - if (obj.getString("ispk").equals("0")) { - isPK(u); - }else{ - ToastUtil.show(mContext.getString(R.string.pking_over)); - } - } - }}}); + onPkApplyTmp(u); } else { if (mPkWaitCount < 0) { - rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 8); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + u.getId()); - } - }); - } - }); + onPkTimeoutTmp(u); } mApplyUid = null; @@ -1260,7 +1483,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { /** * 随机PK拒绝对话框 */ - public void showPkDialog(UserBean u) { + @Override + protected void showPkDialog(UserBean u) { new DialogUitl.Builder(mContext) .setHtmlCode(Html.fromHtml( "有人向您发起PK请求。
" + @@ -1333,7 +1557,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { void apply() { - isPK(u); + isPKTmp(u); } }) .build().show(); @@ -1388,7 +1612,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { /** * 显示申请多人PK的弹窗 */ - private void showDRApplyDialog(UserBean u) { + @Override + protected void showDRApplyDialog(UserBean u) { mApplyUid = u.getId(); mIsApplyDialogShow = true; mAcceptPk = false; @@ -1407,236 +1632,14 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); } if (mAcceptPk) { - HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("pkuid", u.getId()) - .params("type", "1") - .params("sign", "1") - .execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msgs, String[] info) { - if (code == 0) { - Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); - HttpClient.getInstance().get("live.getdrnum", "live.getdrnum") - .execute(new HttpCallback() { - - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - if (info.length > 0) { - - JSONObject datas = JSONObject.parseObject(info[0]); - boolean agree = true; - if (datas.getIntValue("pk_num_day") <= 0) { - ToastUtil.show("多人PK次数已用完"); - agree = false; - } - boolean finalAgree = agree; - IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, agree, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - if (finalAgree == true) { - HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("roomid", u.getId()) - .execute(new HttpCallback() { - - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.i("多人PK", "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LIVE_DRPK) - .param("action", 10) - .param("uid", CommonAppConfig.getInstance().getUid()); - msg1.create(); - String targetId = "g" + CommonAppConfig.getInstance().getUid(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗"); - } - }); - if (info.length == 0) { - return; - } - JSONObject obj = JSONObject.parseObject(info[0]); - JSONArray users = obj.getJSONArray("userlist"); - - //添加水印 -// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f); -// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect); - dRjoinOtherRoom(u.getId(), 1); - - for (int i = 0; i < users.size(); i++) { - JSONObject user = users.getJSONObject(i); - Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { - /** - * 向指定用户发送跨房间连麦请求 - *

- * 1: inviterAutoMix为true时: - * - * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 - * - * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 - * - * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 - *

- */ - IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { - @Override - public void onSuccess() { - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - }); - } - } - } - } - }); - } - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - ToastUtil.show("接受失败"); - } - }); - } else { - ToastUtil.show(msg); - } - } - - }); - - - } - } - }); - - /*LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - JSONObject obj = JSON.parseObject(info[0]); - if (obj != null) { - if (obj.getString("ispk").equals("0")) { - - - }else{ - ToastUtil.show(mContext.getString(R.string.pking_over)); - } - } - } - }});*/ + onDRPkApplyTmp(u); } else { if (mPkWaitCount < 0) { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 8); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + mApplyUid); - } - }); - } - }); + onDRPkTimeoutTmp(u); } else { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 3); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongcloudIMManager.sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗"); - } - }); - } - }); + onDRPkRefuseTmp(u); } mApplyUid = null; mApplyStream = null; @@ -2541,7 +2544,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { String pkTime = StringUtil.getDurationText(time * 1000); livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime)); mPkTimeCount = time; - if (time>0){ + if (time > 0) { String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); livePushRyViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); mHandler.sendEmptyMessage(WHAT_PK_TIME2); diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 15d222453..26132c1ab 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -107,7 +107,7 @@ import io.rong.message.TextMessage; * 主播与主播PK逻辑 */ -public class LiveSwLinkMicPkPresenter implements View.OnClickListener { +public class LiveSwLinkMicPkPresenter extends AbsLinkMicPkPresenter implements View.OnClickListener { private static final int WHAT_PK_WAIT_RECEIVE = 0;//收到pk申请等待 what private static final int WHAT_PK_WAIT_SEND = 1;//发送pk申请等待 what @@ -123,15 +123,11 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { private ViewGroup mPkContainer; private boolean mIsApplyDialogShow;//是否显示了申请PK的弹窗 private boolean mAcceptPk;//是否接受连麦 - private boolean mIsPk;//是否已经Pk了 - public static String mApplyUid;//正在申请Pk的主播的uid private String mApplyUrl;//正在申请Pk的主播的头像 private String mApplyNmae;//正在申请Pk的主播的名字 private String mApplyStream;//正在申请Pk的主播的stream private String mLiveUid;//自己主播的uid private String mUrl;//主播的头像 - public static String mPkUid;//正在Pk的对方主播的uid - public static String oldmPkUid;//正在Pk的对方主播的uid private ProgressTextView mLinkMicWaitProgress; private int mPkWaitCount;//Pk弹窗等待倒计时Live private int mPkTimeCount;//pk时间 @@ -140,7 +136,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { private LiveLinkMicPkViewHolder mLiveLinkMicPkViewHolder; private String mPkTimeString1; private String mPkTimeString2; - private boolean mIsPkEnd;//pk是否结束,进入惩罚时间 + private boolean mPkSend;//pk请求是否已经发送 private int mPkSendWaitCount;//发送pk请求后的等待时间 private String mSelfStream; @@ -169,6 +165,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } public LiveSwLinkMicPkPresenter(Context context, ILiveLinkMicViewHolder linkMicViewHolder, boolean isAnchor, View root) { + super(true); mContext = context; mIsAnchor = isAnchor; mRoot = root; @@ -209,6 +206,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } public LiveSwLinkMicPkPresenter(Context context, LivePushSwViewHolder linkMicViewHolder, boolean isAnchor, View root) { + super(true); mContext = context; mIsAnchor = isAnchor; mRoot = root; @@ -456,13 +454,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } - /** - * 主播与主播PK 主播收到其他主播发过来的多人PK申请的回调 - */ - public void onLinkDRMicPkApply(UserBean u) { - Log.e("ry", "多人收到"); - showDRApplyDialog(u); - } public void onLinkDRMicPkQuit(String uid) { HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { @@ -560,18 +551,17 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { for (int k = 0; k < pkScores.size(); k++) { JSONObject score = pkScores.getJSONObject(k); String userID = score.getString("id"); - if(userID.equals(uid)){ + if (userID.equals(uid)) { removeUid = k; } } pkScores.remove(removeUid); - upDataPkScore(pkScores,"-1",0,false); + upDataPkScore(pkScores, "-1", 0, false); } }, 100); } - SWManager.get().setDrPkNumClarity(drPkbeans.size()); if (drPkbeans.size() == 1) { mLiveAnchorViewHolder.closeEndPkBt(); @@ -619,30 +609,6 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mLiveAnchorViewHolder.showEndPkBt(); } - /** - * 主播与主播PK 主播收到其他主播发过来的PK申请的回调 - */ - public void onLinkMicPkApply(UserBean u, String stream, int by) { - Log.e("ry", u.getUserNiceName() + "单人收到" + u.getAvatar()); - mApplyUid = u.getId(); - mApplyUrl = u.getAvatar(); - mApplyNmae = u.getUserNiceName(); - if (by != 1) { - Log.e("ry", "1" + u.getUserNiceName() + "单人收到" + u.getAvatar()); - if (mIsApplyDialogShow == false) { - if (u.isRandomPk()) { - Log.e("ry", "2" + u.getUserNiceName() + "单人收到" + u.getAvatar()); - showPkDialog(u); - } else { - Log.e("ry", "3" + u.getUserNiceName() + "单人收到" + u.getAvatar()); - showApplyDialog(u); - } - } - } else { - Log.e("ry", "4" + u.getUserNiceName() + "单人收到" + u.getAvatar()); - isPK(u); - } - } /** * 主播与主播PK PK主播发过来的已经接受 @@ -658,7 +624,8 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { LivePushSwViewHolder.btn_close.setVisibility(View.VISIBLE); } - private void isPK(UserBean bean) { + @Override + protected void isPK(UserBean bean) { EventBus.getDefault().post(new AnchorInfoEvent(false, bean.getId(), bean.getUserNiceName(), bean.getAvatar())); ScreenDimenUtil util = ScreenDimenUtil.getInstance(); int mScreenWdith = util.getScreenWdith(); @@ -720,10 +687,313 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { }); } + @Override + protected void onDRPkApply(UserBean u) { + HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive").params("uid", CommonAppConfig.getInstance().getUid()).params("pkuid", u.getId()).params("type", "1").params("sign", "1").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msgs, String[] info) { + if (code == 0) { + Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); + HttpClient.getInstance().get("live.getdrnum", "live.getdrnum").execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + if (info.length > 0) { + JSONObject datas = JSONObject.parseObject(info[0]); + boolean agree = true; + if (datas.getIntValue("pk_num_day") <= 0) { + ToastUtil.show("多人PK次数已用完"); + agree = false; + } + boolean finalAgree = agree; + if (finalAgree) { + HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", u.getId()).execute(new HttpCallback() { + + @Override + public void onSuccess(int code, String msg, String[] info) { + L.eSw("多人PK" + "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + if (info.length == 0) { + return; + } + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + SWManager.get().setDrPkNumClarity(3);//加入成功后,将分别率设置为 VD_320x240 + //将自己从多人pk列表里剔除 + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; + } + } + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); + L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); + } + + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + for (int i = 0; i < drPkbeans.size(); i++) { + if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 2).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("msgtype", 2).param("uid", drPkbeans.get(i).getId()).param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + L.eSw("uiduiduiduiduiduiduiduid" + drPkbeans.get(i).getId()); + String targetId = String.valueOf(drPkbeans.get(i).getId()); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + + // + int index = livePushSwViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); + + L.eSw("onLinkDRMicPkApplyOk(UserBean u)-点击接收 1 " + u.getUserNiceName()); + L.eSw("發送action = 2"); + + } + + if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("msgtype", 3).param("uid", drPkbeans.get(i).getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName() );; + msg1.create(); + L.eSw("發送給自己直播間" + drPkbeans.get(i).getId()); + String targetId = "g" + CommonAppConfig.getInstance().getUid(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + } + + + if (!mApplyUid.equals(String.valueOf(drPkbeans.get(i).getId())) && !CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("msgtype", 3).param("uid", drPkbeans.get(i).getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.create(); + L.eSw("發送給其他主播直播间" + drPkbeans.get(i).getId()); + String targetId = "g" + drPkbeans.get(i).getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("tx", "aaa" + errorCode.toString()); + ToastUtil.show(errorCode.code + ":" + errorCode.msg); + } + }); + } + } + dRjoinOtherRoom(u); + //展示结束连麦按钮 + //设置多人PK 房主ROOM UID + mLiveAnchorViewHolder.setDrpkRoomId(mApplyUid); + mLiveAnchorViewHolder.showEndPkBt(); + } + } + }); + } + }); + } + } else { + ToastUtil.show(msg); + } + } + + }); + + + } + } + }); + } + + @Override + protected void onDRPkTimeout(UserBean u) { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + mApplyUid); + } + }); + } + }); + } + + @Override + protected void onDRPkRefuse(UserBean u) { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 3); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗"); + } + }); + } + }); + } + + @Override + protected void onPkApply(UserBean u) { + LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + if (obj != null) { + if (obj.getString("ispk").equals("0")) { + isPKTmp(u); + } else { + ToastUtil.show(mContext.getString(R.string.pking_over)); + } + } + } + } + }); + } + + @Override + protected void onPkTimeout(UserBean u) { + final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); + msg1.create(); + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + + Log.e("ry", "发送成功"); + if (SocketSwClient.mSocketHandler != null) { + SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + u.getId()); + } + }); + } + + @Override + protected void onPkRefuse(UserBean u) { + onPkTimeoutTmp(u); + } + /** * 显示申请PK的弹窗 */ - private void showApplyDialog(UserBean u) { + @Override + protected void showApplyDialog(UserBean u) { mIsApplyDialogShow = true; mAcceptPk = false; View v = LayoutInflater.from(mContext).inflate(R.layout.dialog_link_mic_pk_wait, null); @@ -741,50 +1011,10 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); } if (mAcceptPk) { - LiveHttpUtil.livePkCheckLive(u.getId(), "", "", new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0 && info.length > 0) { - JSONObject obj = JSON.parseObject(info[0]); - if (obj != null) { - if (obj.getString("ispk").equals("0")) { - isPK(u); - } else { - ToastUtil.show(mContext.getString(R.string.pking_over)); - } - } - } - } - }); + onPkApplyTmp(u); } else { if (mPkWaitCount < 0) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); - msg1.create(); - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - - Log.e("ry", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + u.getId()); - } - }); + onPkTimeoutTmp(u); } mApplyUid = null; mApplyStream = null; @@ -803,7 +1033,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { private String TAG = "多人PK"; - public void editPkRoom(String uid){ + public void editPkRoom(String uid) { SWManager.get().exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), uid); } @@ -852,7 +1082,8 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { /** * 随机PK拒绝对话框 */ - public void showPkDialog(UserBean u) { + @Override + protected void showPkDialog(UserBean u) { new DialogUitl.Builder(mContext).setHtmlCode(Html.fromHtml("有人向您发起PK请求。
" + "若拒绝PK,将会10分钟内不会再收到任何随机PK请求。")).setConfirmString("接受").setCancelString("拒絕").setView(R.layout.dialog_live_random_pk).setSimpleCallbackView(new DialogUitl.SimpleCallbackView() { boolean clickCancel = false; String titleVal; @@ -914,7 +1145,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { void apply() { - isPK(u); + isPKTmp(u); } }).build().show(); } @@ -968,7 +1199,8 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { /** * 显示申请多人PK的弹窗 */ - private void showDRApplyDialog(UserBean u) { + @Override + protected void showDRApplyDialog(UserBean u) { mApplyUid = u.getId(); mIsApplyDialogShow = true; mAcceptPk = false; @@ -987,245 +1219,13 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mHandler.removeMessages(WHAT_PK_WAIT_RECEIVE); } if (mAcceptPk) { - HttpClient.getInstance().get("Livepk.changeLive", "Livepk.changeLive").params("uid", CommonAppConfig.getInstance().getUid()).params("pkuid", u.getId()).params("type", "1").params("sign", "1").execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msgs, String[] info) { - if (code == 0) { - Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); - HttpClient.getInstance().get("live.getdrnum", "live.getdrnum").execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - if (info.length > 0) { - JSONObject datas = JSONObject.parseObject(info[0]); - boolean agree = true; - if (datas.getIntValue("pk_num_day") <= 0) { - ToastUtil.show("多人PK次数已用完"); - agree = false; - } - boolean finalAgree = agree; - if (finalAgree) { - HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", u.getId()).execute(new HttpCallback() { - - @Override - public void onSuccess(int code, String msg, String[] info) { - L.eSw("多人PK" + "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - if (info.length == 0) { - return; - } - JSONObject obj = JSONObject.parseObject(info[0]); - drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - SWManager.get().setDrPkNumClarity(3);//加入成功后,将分别率设置为 VD_320x240 - //将自己从多人pk列表里剔除 - int removeIndex = -1; - for (int i = 0; i < drPkbeans.size(); i++) { - if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - removeIndex = i; - } - } - if (removeIndex != -1) { - drPkbeans.remove(removeIndex); - L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); - } - - HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (info.length > 0) { - JSONObject obj = JSONObject.parseObject(info[0]); - drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); - for (int i = 0; i < drPkbeans.size(); i++) { - if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 2).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("msgtype", 2).param("uid", drPkbeans.get(i).getId()).param("uhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - L.eSw("uiduiduiduiduiduiduiduid" + drPkbeans.get(i).getId()); - String targetId = String.valueOf(drPkbeans.get(i).getId()); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); - - // - int index = livePushSwViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); - - L.eSw("onLinkDRMicPkApplyOk(UserBean u)-点击接收 1 " + u.getUserNiceName()); - L.eSw("發送action = 2"); - - } - - if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("msgtype", 3).param("uid", drPkbeans.get(i).getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName() );; - msg1.create(); - L.eSw("發送給自己直播間" + drPkbeans.get(i).getId()); - String targetId = "g" + CommonAppConfig.getInstance().getUid(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); - } - - - if (!mApplyUid.equals(String.valueOf(drPkbeans.get(i).getId())) && !CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 3).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", CommonAppConfig.getInstance().getUid()).param("msgtype", 3).param("uid", drPkbeans.get(i).getId()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - L.eSw("發送給其他主播直播间" + drPkbeans.get(i).getId()); - String targetId = "g" + drPkbeans.get(i).getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; //群聊 - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); - } - }); - } - } - dRjoinOtherRoom(u); - //展示结束连麦按钮 - //设置多人PK 房主ROOM UID - mLiveAnchorViewHolder.setDrpkRoomId(mApplyUid); - mLiveAnchorViewHolder.showEndPkBt(); - } - } - }); - } - }); - } - } else { - ToastUtil.show(msg); - } - } - - }); - - - } - } - }); + onDRPkApplyTmp(u); } else { if (mPkWaitCount < 0) { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 8); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + mApplyUid); - } - }); - } - }); + onDRPkTimeoutTmp(u); } else { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LINK_MIC_PK).param("action", 3); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketSwClient.mSocketHandler != null) { - SocketSwClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗"); - } - }); - } - }); + onDRPkRefuseTmp(u); } mApplyUid = null; mApplyStream = null; @@ -1285,76 +1285,76 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { private void setDrPkUserInfoView(List drPkbeanList) { L.eSw("setDrPkUserInfoView" + new Gson().toJson(drPkbeanList)); - for (int j = 0; j < drPkbeanList.size(); j++) { - if (j == 0) { - L.eSw("j == 0:" + j); - //设置多人PK数据 - if (detailsView2 != null) { - livePushSwViewHolder.dr2_preview.removeView(detailsView2); - } - detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); - linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); - textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); - imageGrade2 = detailsView2.findViewById(R.id.image_grade2); - textGrade2 = detailsView2.findViewById(R.id.text_grade2); - imageGrade2.setTag(String.valueOf(drPkbeanList.get(0).getId())); - textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); - livePushSwViewHolder.dr2_preview.addView(detailsView2); - detailsLinearLayout2.setVisibility(View.GONE); - linearGrade2.setVisibility(View.GONE); - } else if (j == 1) { - L.eSw("j == 1:" + j); - if (detailsView4 != null) { - livePushSwViewHolder.dr4_preview.removeView(detailsView4); - } - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(String.valueOf(drPkbeanList.get(1).getId())); - textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); - livePushSwViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.GONE); - linearGrade4.setVisibility(View.GONE); - } else if (j == 2) { - L.eSw("j == 2:" + j); + for (int j = 0; j < drPkbeanList.size(); j++) { + if (j == 0) { + L.eSw("j == 0:" + j); + //设置多人PK数据 + if (detailsView2 != null) { + livePushSwViewHolder.dr2_preview.removeView(detailsView2); + } + detailsView2 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout2 = detailsView2.findViewById(R.id.lin_pk2); + linearGrade2 = detailsView2.findViewById(R.id.linear_grade2); + textPkName2 = detailsView2.findViewById(R.id.text_pk_name2); + imageGrade2 = detailsView2.findViewById(R.id.image_grade2); + textGrade2 = detailsView2.findViewById(R.id.text_grade2); + imageGrade2.setTag(String.valueOf(drPkbeanList.get(0).getId())); + textPkName2.setText(drPkbeanList.get(0).getUser_nicename()); + livePushSwViewHolder.dr2_preview.addView(detailsView2); + detailsLinearLayout2.setVisibility(View.GONE); + linearGrade2.setVisibility(View.GONE); + } else if (j == 1) { + L.eSw("j == 1:" + j); + if (detailsView4 != null) { + livePushSwViewHolder.dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(String.valueOf(drPkbeanList.get(1).getId())); + textPkName4.setText(drPkbeanList.get(1).getUser_nicename()); + livePushSwViewHolder.dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); + } else if (j == 2) { + L.eSw("j == 2:" + j); - if (detailsView4 != null) { - livePushSwViewHolder.dr4_preview.removeView(detailsView4); - } - detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); - linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); - textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); - imageGrade4 = detailsView4.findViewById(R.id.image_grade4); - textGrade4 = detailsView4.findViewById(R.id.text_grade4); - imageGrade4.setTag(String.valueOf(drPkbeanList.get(2).getId())); - textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); - livePushSwViewHolder.dr4_preview.addView(detailsView4); - detailsLinearLayout4.setVisibility(View.GONE); - linearGrade4.setVisibility(View.GONE); + if (detailsView4 != null) { + livePushSwViewHolder.dr4_preview.removeView(detailsView4); + } + detailsView4 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout4 = detailsView4.findViewById(R.id.lin_pk4); + linearGrade4 = detailsView4.findViewById(R.id.linear_grade4); + textPkName4 = detailsView4.findViewById(R.id.text_pk_name4); + imageGrade4 = detailsView4.findViewById(R.id.image_grade4); + textGrade4 = detailsView4.findViewById(R.id.text_grade4); + imageGrade4.setTag(String.valueOf(drPkbeanList.get(2).getId())); + textPkName4.setText(drPkbeanList.get(2).getUser_nicename()); + livePushSwViewHolder.dr4_preview.addView(detailsView4); + detailsLinearLayout4.setVisibility(View.GONE); + linearGrade4.setVisibility(View.GONE); - if (detailsView3 != null) { - livePushSwViewHolder.dr3_preview.removeView(detailsView3); - } - detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); - detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); - linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); - textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); - imageGrade3 = detailsView3.findViewById(R.id.image_grade3); - textGrade3 = detailsView3.findViewById(R.id.text_grade3); - imageGrade3.setTag(String.valueOf(drPkbeanList.get(1).getId())); - textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); - livePushSwViewHolder.dr3_preview.addView(detailsView3); - detailsLinearLayout3.setVisibility(View.GONE); - linearGrade3.setVisibility(View.GONE); + if (detailsView3 != null) { + livePushSwViewHolder.dr3_preview.removeView(detailsView3); + } + detailsView3 = LayoutInflater.from(mContext).inflate(R.layout.view_live_pk_details, null); + detailsLinearLayout3 = detailsView3.findViewById(R.id.lin_pk3); + linearGrade3 = detailsView3.findViewById(R.id.linear_grade3); + textPkName3 = detailsView3.findViewById(R.id.text_pk_name3); + imageGrade3 = detailsView3.findViewById(R.id.image_grade3); + textGrade3 = detailsView3.findViewById(R.id.text_grade3); + imageGrade3.setTag(String.valueOf(drPkbeanList.get(1).getId())); + textPkName3.setText(drPkbeanList.get(1).getUser_nicename()); + livePushSwViewHolder.dr3_preview.addView(detailsView3); + detailsLinearLayout3.setVisibility(View.GONE); + linearGrade3.setVisibility(View.GONE); - ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); - } + ToastUtil.show(WordUtil.isNewZh() ? "接受成功" : "Success"); } + } L.eSw("dRjoinOtherRoom:size:" + drPkbeanList.size() + " json " + new Gson().toJson(drPkbeanList)); } @@ -1694,14 +1694,14 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { /** * 更新Pk分数 */ - public void upDataPkScore(JSONArray pkScores, String uid, int time,boolean isShowTimeTitle) { + public void upDataPkScore(JSONArray pkScores, String uid, int time, boolean isShowTimeTitle) { this.pkScores = pkScores; L.eSw("更新Pk分数 upDataPkScore time:" + time + " " + pkScores); String userID1 = (String) imageGrade1.getTag(); String userID2 = (String) imageGrade2.getTag(); String userID4 = (String) imageGrade4.getTag(); - if (livePushSwViewHolder.timeTitle.getVisibility() == View.GONE &&isShowTimeTitle) { + if (livePushSwViewHolder.timeTitle.getVisibility() == View.GONE && isShowTimeTitle) { mHandler.removeMessages(WHAT_PK_TIME2); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) livePushSwViewHolder.timeTitle.getLayoutParams(); layoutParams.topMargin = DpUtil.dp2px(123); @@ -1795,7 +1795,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } } - } else if(pkScoreSize == 4){ + } else if (pkScoreSize == 4) { String userID3 = (String) imageGrade3.getTag(); detailsLinearLayout1.setVisibility(View.VISIBLE); @@ -1899,7 +1899,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { } } - }else{ + } else { detailsLinearLayout1.setVisibility(View.VISIBLE); detailsLinearLayout2.setVisibility(View.VISIBLE); @@ -1972,7 +1972,7 @@ public class LiveSwLinkMicPkPresenter implements View.OnClickListener { mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME2, getNextSecondTime()); } } else { - if(DRPKing!=-1){ + if (DRPKing != -1) { mLiveAnchorViewHolder.showEndPkBt(); } livePushSwViewHolder.timeTitle.setVisibility(View.GONE); diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 244446584..5fc3bc3d7 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -218,6 +218,8 @@ import pl.droidsonroids.gif.GifImageView; */ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickListener { + private static final int PK_LINE_HEIGHT = (960 + DpUtil.dp2px(65));//单人PK席位高度线 + private static final int PK_BOTTOM = ScreenDimenUtil.getInstance().getScreenWdith() / 2; public static Context Contexts; private int mOffsetY; private ViewGroup mRoot; @@ -1728,8 +1730,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis layoutParams.topMargin = DpUtil.dp2px(190); dragonImmediateParticipationTime.setLayoutParams(layoutParams); } - if(mContext instanceof LiveRyAnchorActivity ||mContext instanceof LiveSwAnchorActivity){ - if (dragonImmediateParticipationTime.getVisibility() == View.GONE ) { + if (mContext instanceof LiveRyAnchorActivity || mContext instanceof LiveSwAnchorActivity) { + if (dragonImmediateParticipationTime.getVisibility() == View.GONE) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) redPacket.getLayoutParams(); layoutParams.topMargin = DpUtil.dp2px(110); redPacket.setLayoutParams(layoutParams); @@ -1751,7 +1753,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis redSchedule.setText(stringBuffer.toString()); openRedPacket.setText(String.format(mContext.getString(R.string.open_red_packet), mRedPacketModel.getRedPacketCount() + "")); } - if (IMLoginManager.get(mContext).getUserInfo().anchorUserType() && (mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity)) { + if (IMLoginManager.get(mContext).getUserInfo().anchorUserType() && (mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity)) { anchorTimeHandler.removeCallbacks(anchorTimeRunnable); anchorTimeHandler.post(anchorTimeRunnable); } @@ -1763,7 +1765,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void onViewClicks() { - if (!(mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity)) { + if (!(mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity)) { LiveNetManager.get(mContext).redPacketInfo(mLiveUid, redPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { @Override public void onSuccess(RedPacketInfoModel data) { @@ -1789,7 +1791,6 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } - } }); } @@ -2761,7 +2762,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ScreenDimenUtil util = ScreenDimenUtil.getInstance(); int mScreenWdith = util.getScreenWdith(); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) lt_pk_line.getLayoutParams(); - params.height = mScreenWdith * 720 / 1120; + params.height = mScreenWdith * 720 / PK_LINE_HEIGHT; + //params.bottomMargin = (mScreenWdith * 720 / 960); lt_pk_line.requestLayout(); lt_pk_line.setVisibility(View.VISIBLE); @@ -2819,7 +2821,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ScreenDimenUtil util = ScreenDimenUtil.getInstance(); int mScreenWdith = util.getScreenWdith(); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) lt_pk_line.getLayoutParams(); - params.height = mScreenWdith * 720 / 1120; + params.height = mScreenWdith * 720 / PK_LINE_HEIGHT; + //params.bottomMargin=(mScreenWdith * 720 / 960); lt_pk_line.requestLayout(); lt_pk_line.setVisibility(View.VISIBLE); @@ -2959,7 +2962,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis bundle.putString("toUid", toUid); bundle.putInt("isAttention", isAttention); bundle.putBoolean("isLive", isAnchor); - bundle.putBoolean("SBW", !(mContext instanceof LiveSwAnchorActivity ||mContext instanceof LiveRyAnchorActivity )); + bundle.putBoolean("SBW", !(mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity)); giftWallDialog.setArguments(bundle); giftWallDialog.show(((AbsActivity) mContext).getSupportFragmentManager(), "GiftWallDialog"); @@ -3324,7 +3327,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis //直播间 粉丝排行榜 openMedalRankWindow(); } else if (i == R.id.btn_guard) { - ((LiveActivity) mContext).openNewGuardListWindow((mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity )); + ((LiveActivity) mContext).openNewGuardListWindow((mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity)); } else if (i == R.id.btn_red_pack) { ((LiveActivity) mContext).openRedPackListWindow(); @@ -3332,13 +3335,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ((LiveActivity) mContext).openPrizePoolWindow(); } else if (i == R.id.user_more) { MobclickAgent.onEvent(mContext, "live_room_audience_list", "直播间上面点观众列表按钮"); - ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity); } else if (i == R.id.hot_btn) { - ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, false, mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity); } else if (i == R.id.noble_seat) { MobclickAgent.onEvent(mContext, "live_room_noble", "贵族按钮"); - ((LiveActivity) mContext).openUserMoreListWindow(1, false, true, mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openUserMoreListWindow(1, false, true, mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity); } else if (i == R.id.btn_close) { // if (sudGameMin!=null&&sudGameMin.getVisibility()==View.VISIBLE) { // new XPopup.Builder(mContext) @@ -3371,7 +3374,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } else if (i == R.id.user_guard) { MobclickAgent.onEvent(mContext, "anchor_avatar_guard", "守护按钮"); // ((LiveActivity) mContext).openUserMoreListWindow(2, true); - ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity); + ((LiveActivity) mContext).openNewGuardListWindow(mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity); } if (i == R.id.lt_trickery) { showTrickeryDialog(); @@ -3396,7 +3399,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis * @param in 展示的view */ private void changeMsgView(View out, View in) { - if (mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity) { return; } if (in.getVisibility() == View.VISIBLE) { @@ -4749,7 +4752,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis lt_trickster_salvation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mContext instanceof LiveSwAnchorActivity||mContext instanceof LiveRyAnchorActivity) { + if (mContext instanceof LiveSwAnchorActivity || mContext instanceof LiveRyAnchorActivity) { dialog.dismiss(); return; } @@ -5360,7 +5363,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (pkScores.size() == 2) { linearGrade3.setVisibility(View.GONE); linearGrade4.setVisibility(View.GONE); - } else if(pkScores.size()==3){ + } else if (pkScores.size() == 3) { linearGrade4.setVisibility(View.GONE); } for (int i = 0; i < pkScores.size(); i++) { diff --git a/live/src/main/res/layout/view_live_room.xml b/live/src/main/res/layout/view_live_room.xml index 64345b088..1f22db57e 100644 --- a/live/src/main/res/layout/view_live_room.xml +++ b/live/src/main/res/layout/view_live_room.xml @@ -1493,6 +1493,7 @@ From 020b5c1025753d8c14cb315f3736a1c73810cd85 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 13 Jun 2024 16:06:21 +0800 Subject: [PATCH 64/64] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=BD=98=E5=A4=9A?= =?UTF-8?q?=E6=8B=89=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/manager/OpenAdManager.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java b/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java index b49247ddd..1807686db 100644 --- a/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java +++ b/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java @@ -54,10 +54,18 @@ public class OpenAdManager { } public void clear() { - runnableMap.clear(); - showMap.clear(); - list.clear(); - waitRunnableMap.clear(); + if (runnableMap != null) { + runnableMap.clear(); + } + if (showMap != null) { + showMap.clear(); + } + if (list != null) { + list.clear(); + } + if (waitRunnableMap != null) { + waitRunnableMap.clear(); + } list = null; runNowRunnable = null; }