add[声望升级]

This commit is contained in:
Martin 2024-04-12 18:29:26 +08:00
parent 5922f4c08b
commit 3f68e2a3aa
22 changed files with 413 additions and 254 deletions

View File

@ -76,6 +76,17 @@ public class CommonAppConfig {
public static boolean isGetNewWrap = false;//是否获取到新的包裹礼物 public static boolean isGetNewWrap = false;//是否获取到新的包裹礼物
public static int alert_time = 1; public static int alert_time = 1;
public static int alert_end_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() { private CommonAppConfig() {

View File

@ -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;
}
}

View File

@ -70,6 +70,7 @@ import com.yunbao.common.bean.StarChallengeStatusModel;
import com.yunbao.common.bean.SudGameUserModel; import com.yunbao.common.bean.SudGameUserModel;
import com.yunbao.common.bean.SudRoomListModel; import com.yunbao.common.bean.SudRoomListModel;
import com.yunbao.common.bean.SudgameCodeModel; import com.yunbao.common.bean.SudgameCodeModel;
import com.yunbao.common.bean.SwTokenModel;
import com.yunbao.common.bean.UserAreaBean; import com.yunbao.common.bean.UserAreaBean;
import com.yunbao.common.bean.UserAvatarSelectBean; import com.yunbao.common.bean.UserAvatarSelectBean;
import com.yunbao.common.bean.VipModel; import com.yunbao.common.bean.VipModel;
@ -1192,4 +1193,6 @@ public interface PDLiveApi {
Observable<ResponseModel<CheckUpgradesModel>> checkUpgrades(@Query("liveuid") String liveUid); Observable<ResponseModel<CheckUpgradesModel>> checkUpgrades(@Query("liveuid") String liveUid);
@GET("/api/public/?service=Guard.getRewards") @GET("/api/public/?service=Guard.getRewards")
Observable<ResponseModel<Object>> guardGetRewards(@Query("guard_level") String guardLevel,@Query("liveuid") String liveUid); Observable<ResponseModel<Object>> guardGetRewards(@Query("guard_level") String guardLevel,@Query("liveuid") String liveUid);
@GET("/api/public/?service=Tx.getShengwangToken")
Observable<ResponseModel<SwTokenModel>> getSwToken();
} }

View File

@ -66,6 +66,7 @@ import com.yunbao.common.bean.StarChallengeStatusModel;
import com.yunbao.common.bean.SudGameUserModel; import com.yunbao.common.bean.SudGameUserModel;
import com.yunbao.common.bean.SudRoomListModel; import com.yunbao.common.bean.SudRoomListModel;
import com.yunbao.common.bean.SudgameCodeModel; import com.yunbao.common.bean.SudgameCodeModel;
import com.yunbao.common.bean.SwTokenModel;
import com.yunbao.common.bean.UserAreaBean; import com.yunbao.common.bean.UserAreaBean;
import com.yunbao.common.bean.UserAvatarSelectBean; import com.yunbao.common.bean.UserAvatarSelectBean;
import com.yunbao.common.bean.VipModel; import com.yunbao.common.bean.VipModel;
@ -3133,7 +3134,6 @@ public class LiveNetManager {
} }
} }
}).isDisposed(); }).isDisposed();
} }
public void guardGetRewards(String guardLevel, String liveUid, HttpCallback<Object> callback) { public void guardGetRewards(String guardLevel, String liveUid, HttpCallback<Object> callback) {
@ -3160,6 +3160,30 @@ public class LiveNetManager {
} }
public void getSwToken( HttpCallback<SwTokenModel> callback) {
API.get().pdLiveApi(mContext)
.getSwToken()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ResponseModel<SwTokenModel>>() {
@Override
public void accept(ResponseModel<SwTokenModel> listResponseModel) throws Exception {
if (callback != null) {
callback.onSuccess(listResponseModel.getData().getInfo());
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
throwable.printStackTrace();
if (callback != null) {
callback.onError(mContext.getString(R.string.net_error));
}
}
}).isDisposed();
}
/** /**
* 直播间取消网络请求 * 直播间取消网络请求
*/ */

View File

@ -5,15 +5,18 @@ import android.content.Context;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext; import com.yunbao.common.CommonAppContext;
import com.yunbao.common.manager.base.BaseCacheManager; import com.yunbao.common.manager.base.BaseCacheManager;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.StringUtil;
import io.agora.rtc2.ChannelMediaOptions; import io.agora.rtc2.ChannelMediaOptions;
import io.agora.rtc2.Constants; import io.agora.rtc2.Constants;
import io.agora.rtc2.IRtcEngineEventHandler; import io.agora.rtc2.IRtcEngineEventHandler;
import io.agora.rtc2.RtcEngine; import io.agora.rtc2.RtcConnection;
import io.agora.rtc2.RtcEngineConfig; import io.agora.rtc2.RtcEngineConfig;
import io.agora.rtc2.RtcEngineEx;
import io.agora.rtc2.video.VideoCanvas; import io.agora.rtc2.video.VideoCanvas;
/** /**
@ -24,12 +27,9 @@ public class SWAuManager extends BaseCacheManager {
// 填写项目的 App ID可在声网控制台中生成 // 填写项目的 App ID可在声网控制台中生成
public static final String shengwang_appId = "4cf0376582d742ac8a96778b25b1079e"; 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; private Activity mContext;
public static SWAuManager manager; public static SWAuManager manager;
private RtcEngine mRtcEngine; private RtcEngineEx mRtcEngine;
private FrameLayout audienceContainer; //主播视图 private FrameLayout audienceContainer; //主播视图
private FrameLayout pkContainer1; //pk主播视图1 private FrameLayout pkContainer1; //pk主播视图1
private FrameLayout pkContainer2; //pk主播视图2 private FrameLayout pkContainer2; //pk主播视图2
@ -64,7 +64,7 @@ public class SWAuManager extends BaseCacheManager {
config.mAppId = SWAuManager.shengwang_appId; config.mAppId = SWAuManager.shengwang_appId;
config.mEventHandler = mRtcEventHandler; config.mEventHandler = mRtcEventHandler;
// 创建并初始化 RtcEngine // 创建并初始化 RtcEngine
mRtcEngine = RtcEngine.create(config); mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Check the error."); 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) { public void joinRoom(String strUid, String token, String channelName) {
@ -96,11 +95,60 @@ public class SWAuManager extends BaseCacheManager {
options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE; options.clientRoleType = Constants.CLIENT_ROLE_AUDIENCE;
// 直播场景下设置频道场景为 BROADCASTING (直播场景) // 直播场景下设置频道场景为 BROADCASTING (直播场景)
options.audienceLatencyLevel = Constants.AUDIENCE_LATENCY_LEVEL_LOW_LATENCY; // 觀眾走極速直播 options.audienceLatencyLevel = Constants.AUDIENCE_LATENCY_LEVEL_LOW_LATENCY; // 觀眾走極速直播
// 使用临时 Token 加入频道自行指定用户 ID 并确保其在频道内的唯一性 // 使用临时 Token 加入频道自行指定用户 ID 并确保其在频道内的唯一性
mRtcEngine.joinChannel(token, channelName, uid, options); 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() { private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() {
@Override @Override
@ -110,7 +158,7 @@ public class SWAuManager extends BaseCacheManager {
@Override @Override
public void run() { public void run() {
// 获取 uid 设置远端视频视图 // 获取 uid 设置远端视频视图
setupRemoteVideo(uid); //setupRemoteVideo(uid);
} }
}); });
} }

View File

@ -5,17 +5,23 @@ import android.content.Context;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext; 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.manager.base.BaseCacheManager;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.ToastUtil;
import cn.rongcloud.rtc.base.RCRTCParamsType;
import io.agora.rtc2.ChannelMediaOptions; import io.agora.rtc2.ChannelMediaOptions;
import io.agora.rtc2.Constants; import io.agora.rtc2.Constants;
import io.agora.rtc2.IRtcEngineEventHandler; import io.agora.rtc2.IRtcEngineEventHandler;
import io.agora.rtc2.RtcConnection;
import io.agora.rtc2.RtcEngine; import io.agora.rtc2.RtcEngine;
import io.agora.rtc2.RtcEngineConfig; import io.agora.rtc2.RtcEngineConfig;
import io.agora.rtc2.RtcEngineEx;
import io.agora.rtc2.video.VideoCanvas; import io.agora.rtc2.video.VideoCanvas;
import io.agora.rtc2.video.VideoEncoderConfiguration; import io.agora.rtc2.video.VideoEncoderConfiguration;
@ -27,12 +33,9 @@ public class SWManager extends BaseCacheManager {
// 填写项目的 App ID可在声网控制台中生成 // 填写项目的 App ID可在声网控制台中生成
public static final String shengwang_appId = "4cf0376582d742ac8a96778b25b1079e"; 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; private Activity mContext;
public static SWManager manager; public static SWManager manager;
private RtcEngine mRtcEngine; private RtcEngineEx mRtcEngine;
private int uid; private int uid;
VideoEncoderConfiguration cfg; VideoEncoderConfiguration cfg;
private FrameLayout anchorContainer; //主播视图 private FrameLayout anchorContainer; //主播视图
@ -79,7 +82,7 @@ public class SWManager extends BaseCacheManager {
config.mAppId = SWManager.shengwang_appId; config.mAppId = SWManager.shengwang_appId;
config.mEventHandler = mRtcEventHandler; config.mEventHandler = mRtcEventHandler;
// 创建并初始化 RtcEngine // 创建并初始化 RtcEngine
mRtcEngine = RtcEngine.create(config); mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Check the error."); 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); 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() { private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() {
@Override @Override
@ -152,7 +216,7 @@ public class SWManager extends BaseCacheManager {
@Override @Override
public void run() { public void run() {
// 获取 uid 设置远端视频视图 // 获取 uid 设置远端视频视图
setupRemoteVideo(uid); //setupRemoteVideo(uid);
} }
}); });
} }
@ -170,8 +234,36 @@ public class SWManager extends BaseCacheManager {
super.onError(err); super.onError(err);
ToastUtil.show("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<SwTokenModel>() {
@Override
public void onSuccess(SwTokenModel data) {
if (mRtcEngine != null) {
mRtcEngine.renewToken(data.getToken());
}
}
@Override
public void onError(String error) {
}
});
}
//设置对方主播视图 //设置对方主播视图
private void setupRemoteVideo(int uid) { private void setupRemoteVideo(int uid) {
SurfaceView surfaceView = new SurfaceView(mContext); SurfaceView surfaceView = new SurfaceView(mContext);

View File

@ -12,10 +12,18 @@ public class L {
private final static String TAG = "log--->"; private final static String TAG = "log--->";
private final static String TAG_SW = "log--->TAG_SW";
public static void e(String s) { public static void e(String s) {
e(TAG, 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) { public static void e(String tag, String s) {
if (sDeBug) { if (sDeBug) {
Log.e(tag, s); Log.e(tag, s);

View File

@ -124,10 +124,6 @@
<activity <activity
android:name=".activity.CompensateActivity" android:name=".activity.CompensateActivity"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity
android:name=".activity.NewLiveActivity"
android:screenOrientation="portrait" />
</application> </application>
</manifest> </manifest>

View File

@ -3,6 +3,7 @@ package com.yunbao.live.activity;
import static com.blankj.utilcode.util.SnackbarUtils.dismiss; 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_DISABLE;
import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_ENABLE; 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;
import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK_RANDOM; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK_RANDOM;
import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_dr_pk_nub; 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.interfaces.LivePushListener;
import com.yunbao.live.music.LiveMusicDialogFragment; import com.yunbao.live.music.LiveMusicDialogFragment;
import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter;
import com.yunbao.live.presenter.LiveLinkMicPkPresenter;
import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter;
import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter;
import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyChatUtil;
@ -1235,8 +1237,40 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
if (obj != null) { if (obj != null) {
if (obj.getString("ispk").equals("0")) { 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 @Override
public void onSuccess() { public void onSuccess() {
// ToastUtil.show("邀请 " + pkUid + " 发送成功"); // ToastUtil.show("邀请 " + pkUid + " 发送成功");
@ -1264,7 +1298,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
ToastUtil.show("invite " + pkUid + " failed:" + rtcErrorCode); ToastUtil.show("invite " + pkUid + " failed:" + rtcErrorCode);
} }
} }
}); });*/
} else { } else {
ToastUtil.show("主播正在PK稍後再試"); ToastUtil.show("主播正在PK稍後再試");

View File

@ -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();
}
}

View File

@ -52,6 +52,7 @@ import com.yunbao.common.manager.RandomPkManager;
import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.ScreenDimenUtil; import com.yunbao.common.utils.ScreenDimenUtil;
import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.ToastUtil;
@ -683,9 +684,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
public void onLinkMicToPk(UserBean u) { public void onLinkMicToPk(UserBean u) {
EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar())); EventBus.getDefault().post(new AnchorInfoEvent(false, u.getId(), u.getUserNiceName(), u.getAvatar()));
Log.e("eve", u.getId() + ""); Log.e("eve", u.getId() + "");
L.eSw("主播接受了主播的PK邀請");
/** /**
* 加入副房间 * 加入副房间
*
* 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间 * 前提必须已经 通过 {@link RCRTCEngine#joinRoom(String, RCRTCRoomType, IRCRTCResultDataCallback)} {@link RCRTCEngine#joinRoom(String, IRCRTCResultDataCallback)} 加入了主房间
* *
* @param roomId 房间 ID 长度 64 个字符可包含`A-Z``a-z``0-9``+``=``-``_` * @param roomId 房间 ID 长度 64 个字符可包含`A-Z``a-z``0-9``+``=``-``_`
@ -693,7 +694,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
* @group 房间管理 * @group 房间管理
*/ */
RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START);
RCRTCEngine.getInstance().joinOtherRoom(u.getId(), new IRCRTCResultDataCallback<RCRTCOtherRoom>() { /*RCRTCEngine.getInstance().joinOtherRoom(u.getId(), new IRCRTCResultDataCallback<RCRTCOtherRoom>() {
@Override @Override
public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) {
rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener); rcrtcOtherRoom.registerOtherRoomEventsListener(otherRoomEventsListener);
@ -779,17 +780,18 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
public void onFailed(RTCErrorCode rtcErrorCode) { public void onFailed(RTCErrorCode rtcErrorCode) {
Log.i("ry", "11111加入其他房间失败 " + rtcErrorCode.getReason()); Log.i("ry", "11111加入其他房间失败 " + rtcErrorCode.getReason());
} }
}); });*/
LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE);
LiveRyAnchorActivity.isDRPK = 1; LiveRyAnchorActivity.isDRPK = 1;
ScreenDimenUtil util = ScreenDimenUtil.getInstance(); ScreenDimenUtil util = ScreenDimenUtil.getInstance();
int mScreenWdith = util.getScreenWdith(); 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.weight = 1;
params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
livePushRyViewHolder.camera.setLayoutParams(params); livePushRyViewHolder.camera.setLayoutParams(params);
livePushRyViewHolder.mPreView1.setLayoutParams(params); livePushRyViewHolder.mPreView1.setLayoutParams(params);
livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE); livePushRyViewHolder.mPreView1.setVisibility(View.VISIBLE);*/
livePushRyViewHolder.setAnPkRtc(u);//设置对方主播视图
final SocketSendBean msg1 = new SocketSendBean() final SocketSendBean msg1 = new SocketSendBean()
.param("_method_", SOCKET_LINK_MIC_PK) .param("_method_", SOCKET_LINK_MIC_PK)
@ -801,7 +803,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
.param("pkname", u.getUserNiceName()); .param("pkname", u.getUserNiceName());
msg1.create(); msg1.create();
Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; /*Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM;
TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); 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); 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()); Log.e("tx", "发送失败" + errorCode.getMessage());
} }
}); });*/
} }
@ -837,7 +839,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE); LivePushRyViewHolder.btn_close.setVisibility(View.VISIBLE);
LiveRyAnchorActivity.isDRPK = 1; LiveRyAnchorActivity.isDRPK = 1;
JSONObject msg1 = new JSONObject(); /*JSONObject msg1 = new JSONObject();
msg1.put("uid", CommonAppConfig.getInstance().getUid()); msg1.put("uid", CommonAppConfig.getInstance().getUid());
msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); msg1.put("pkuid", CommonAppConfig.getInstance().getUid());
msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb()); msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb());
@ -847,9 +849,47 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
if (bean != null && bean.isRandomPk()) { if (bean != null && bean.isRandomPk()) {
msg1.put("random_pk", bean.isRandomPk() ? 1 : 0); msg1.put("random_pk", bean.isRandomPk() ? 1 : 0);
msg1.put("is_ladders", bean.getRankPkImgUrl()); 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()); 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 @Override
public void onSuccess() { public void onSuccess() {
RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback<RCRTCOtherRoom>() { RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback<RCRTCOtherRoom>() {
@ -956,7 +996,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
public void onFailed(RTCErrorCode errorCode) { public void onFailed(RTCErrorCode errorCode) {
ToastUtil.show("接受失败"); ToastUtil.show("接受失败");
} }
}); });*/
} }

View File

@ -1374,7 +1374,7 @@ public class SocketRyClient {
private void processAnchorLinkMicPk(JSONObject map) { private void processAnchorLinkMicPk(JSONObject map) {
int action = map.getIntValue("action"); int action = map.getIntValue("action");
Log.i("Socket", "action = " + action + " json = " + map.toString()); Log.i("Socket", "action = " + action + " json = " + map.toString());
L.eSw("处理主播与主播PK逻辑action = " + action + " json = " + map.toString());
switch (action) { switch (action) {
case 1://收到对方主播PK回调 case 1://收到对方主播PK回调
UserBean u = new UserBean(); UserBean u = new UserBean();

View File

@ -11,6 +11,8 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.utils.L; import com.yunbao.common.utils.L;
import com.yunbao.common.views.AbsViewHolder; import com.yunbao.common.views.AbsViewHolder;
@ -30,7 +32,7 @@ public class AbsRyLivePushViewHolder extends AbsViewHolder implements ILivePushV
protected ViewGroup mBigContainer; protected ViewGroup mBigContainer;
protected ViewGroup mSmallContainer; protected ViewGroup mSmallContainer;
protected ViewGroup mLeftContainer; protected ViewGroup mLeftContainer;
protected ViewGroup mRightContainer; protected FrameLayout mRightContainer;
protected ViewGroup mPkContainer; protected ViewGroup mPkContainer;
public FrameLayout mPreView, mPreView1, cameraPreview3, dr1_preview, dr2_preview, dr3_preview, dr4_preview; public FrameLayout mPreView, mPreView1, cameraPreview3, dr1_preview, dr2_preview, dr3_preview, dr4_preview;
public ImageView leave; public ImageView leave;
@ -59,7 +61,7 @@ public class AbsRyLivePushViewHolder extends AbsViewHolder implements ILivePushV
mBigContainer = (ViewGroup) findViewById(R.id.big_container); mBigContainer = (ViewGroup) findViewById(R.id.big_container);
mSmallContainer = (ViewGroup) findViewById(R.id.small_container); mSmallContainer = (ViewGroup) findViewById(R.id.small_container);
mLeftContainer = (ViewGroup) findViewById(R.id.left_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); mPkContainer = (ViewGroup) findViewById(R.id.pk_container);
mCameraFront = true; mCameraFront = true;
String mBeautySdkType = CommonAppConfig.getInstance().getBeautySdkType(); String mBeautySdkType = CommonAppConfig.getInstance().getBeautySdkType();

View File

@ -308,7 +308,6 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl
} }
private void setSelectClarity(int selectClarity) { private void setSelectClarity(int selectClarity) {
this.selectClarity = selectClarity; this.selectClarity = selectClarity;
IMLoginManager.get(mContext).setSelectClarity(selectClarity); IMLoginManager.get(mContext).setSelectClarity(selectClarity);
switch (selectClarity) { switch (selectClarity) {
@ -330,7 +329,6 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl
} }
SWManager.get().setDimensions(selectClarity); SWManager.get().setDimensions(selectClarity);
/*//設置開播分辨率 /*//設置開播分辨率
RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848; RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848;
int minRate = 200; int minRate = 200;

View File

@ -31,6 +31,7 @@ import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.interfaces.XPopupCallback; import com.lxj.xpopup.interfaces.XPopupCallback;
import com.lzf.easyfloat.EasyFloat; import com.lzf.easyfloat.EasyFloat;
import com.lzy.okserver.OkDownload; import com.lzy.okserver.OkDownload;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.EnterRoomNewModel;
import com.yunbao.common.dialog.LiveFontSizeSettingDialog; import com.yunbao.common.dialog.LiveFontSizeSettingDialog;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
@ -100,6 +101,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public StyledPlayerView mVideoView; public StyledPlayerView mVideoView;
private FrameLayout playFrameLayout; private FrameLayout playFrameLayout;
private FrameLayout playFrameLayout1;
private View mLoading, mLoading2; private View mLoading, mLoading2;
private ImageView mCover; private ImageView mCover;
@ -127,6 +129,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
RCRTCRoom rcrtcRoom; RCRTCRoom rcrtcRoom;
String purl, srcUrl; String purl, srcUrl;
SWAuManager swAuManager; SWAuManager swAuManager;
String liveUid;
public int getLandscape() { public int getLandscape() {
return landscape; return landscape;
@ -137,9 +140,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
contexts = context; contexts = context;
landscape = landscapes; landscape = landscapes;
Log.i("收收收", landscape + ""); Log.i("收收收", landscape + "");
L.eSw("liveUid:" + liveUid);
} }
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {
return R.layout.view_live_play_ksy; return R.layout.view_live_play_ksy;
@ -152,6 +155,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
Bus.getOn(this); Bus.getOn(this);
mRoot = (ViewGroup) findViewById(R.id.root); mRoot = (ViewGroup) findViewById(R.id.root);
playFrameLayout = (FrameLayout) findViewById(R.id.playView); playFrameLayout = (FrameLayout) findViewById(R.id.playView);
playFrameLayout1 = (FrameLayout) findViewById(R.id.playView1);
mSmallContainer = (ViewGroup) findViewById(R.id.small_container); mSmallContainer = (ViewGroup) findViewById(R.id.small_container);
mLeftContainer = (ViewGroup) findViewById(R.id.left_container); mLeftContainer = (ViewGroup) findViewById(R.id.left_container);
mRightContainer = (ViewGroup) findViewById(R.id.right_container); mRightContainer = (ViewGroup) findViewById(R.id.right_container);
@ -174,15 +178,21 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
mPlayer.setMainView(mVideoView); mPlayer.setMainView(mVideoView);
mPlayer.setListener(new ExoPlayerListener()); mPlayer.setListener(new ExoPlayerListener());
debugView = new TextView(mContext);
debugView.setBackgroundColor(Color.WHITE);
}
public void initSwEngine(String liveUid) {
this.liveUid = liveUid;
swAuManager = SWAuManager.get(); swAuManager = SWAuManager.get();
swAuManager.setAudienceContainer(playFrameLayout); swAuManager.setAudienceContainer(playFrameLayout);
swAuManager.initRtcEngine((Activity) mContext); swAuManager.initRtcEngine((Activity) mContext);
swAuManager.setupRemoteVideo(11); swAuManager.setupRemoteVideo(Integer.parseInt(liveUid));
swAuManager.joinRoom("9999", SWAuManager.shengwang_token, SWAuManager.shengwang_channelName); swAuManager.joinRoom(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid));
debugView = new TextView(mContext);
debugView.setBackgroundColor(Color.WHITE);
//测试-模拟PK场景加入第二个主播视图
swAuManager.setPkContainer1(playFrameLayout1);
swAuManager.joinExRoomEx(CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, SWAuManager.getChannelName(liveUid));
} }
@Override @Override

View File

@ -46,6 +46,7 @@ import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.IMRTCManager;
import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.manager.RandomPkManager;
import com.yunbao.common.manager.SWAuManager;
import com.yunbao.common.manager.SWManager; import com.yunbao.common.manager.SWManager;
import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DialogUitl;
@ -503,7 +504,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
} }
}); });
HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK") HttpClient.getInstance().get("Livepk.endPK", "Livepk.endPK")
.params("uid", CommonAppConfig.getInstance().getUid()) .params("uid", CommonAppConfig.getInstance().getUid())
.params("addtime", "1") .params("addtime", "1")
@ -772,23 +772,36 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
*/ */
private void initRtcEngine() { private void initRtcEngine() {
swManager = SWManager.get(); swManager = SWManager.get();
swManager.setAnchorContainer(mPreView); swManager.setAnchorContainer((FrameLayout) mLeftContainer);
swManager.initRtcEngine((Activity) mContext, "11"); swManager.initRtcEngine((Activity) mContext, CommonAppConfig.getInstance().getUid());
swManager.setOnRtcEngineListener(new SWManager.onRtcEngineListener() { swManager.setOnRtcEngineListener(new SWManager.onRtcEngineListener() {
@Override @Override
public void onOpenSuccess(String channel, int uid) { 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 @Override
public void changeToLeft() { public void changeToLeft() {
if (mPreView != null) { if (mPreView != null) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mPreView.getLayoutParams(); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mPreView.getLayoutParams();
params.width = mPreView.getWidth() / 2; params.width = mPreView.getWidth() / 2;
params.height = DpUtil.dp2px(250); params.height = DpUtil.dp2px(mPreView.getHeight());
params.topMargin = DpUtil.dp2px(130); params.topMargin = DpUtil.dp2px(130);
camera.setLayoutParams(params); camera.setLayoutParams(params);
} }
@ -844,7 +857,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
ToastUtil.show(mContext.getString(R.string.live_open_flash)); ToastUtil.show(mContext.getString(R.string.live_open_flash));
return; return;
} }
} }
/** /**
@ -856,7 +868,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
public void startPush(String pushUrl) { public void startPush(String pushUrl) {
//开播成功创建频道 //开播成功创建频道
if (swManager != null) { if (swManager != null) {
swManager.createRoom(SWManager.shengwang_token, SWManager.shengwang_channelName); swManager.createRoom(CommonAppConfig.SWToken, CommonAppConfig.getChannelName());
} }
if (rcrtcLiveInfo != null) { if (rcrtcLiveInfo != null) {
rcrtcLiveInfo.addPublishStreamUrl(pushUrl, new IRCRTCResultDataCallback<String[]>() { rcrtcLiveInfo.addPublishStreamUrl(pushUrl, new IRCRTCResultDataCallback<String[]>() {

View File

@ -365,6 +365,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
liveHandler.removeCallbacks(loadTimeoutRunnableGone); liveHandler.removeCallbacks(loadTimeoutRunnableGone);
if (mLivePlayViewHolder == null) { if (mLivePlayViewHolder == null) {
mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); 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());
mLiveAudienceViewHolder = new LiveAudienceViewHolder(mContext, mContainer); mLiveAudienceViewHolder = new LiveAudienceViewHolder(mContext, mContainer);
mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, mLiveAudienceViewHolder.getContentView()); mLiveLinkMicPresenter = new LiveLinkMicPresenter(mContext, mLivePlayViewHolder, false, mLiveSDK, mLiveAudienceViewHolder.getContentView());

View File

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.NewLiveActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Video Call!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/local_video_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white" />
<FrameLayout
android:id="@+id/remote_video_view_container"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:background="@android:color/darker_gray"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,23 +2,39 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root" android:id="@+id/root"
android:animateLayoutChanges="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:animateLayoutChanges="true">
<com.google.android.exoplayer2.ui.StyledPlayerView <com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/video_view" android:id="@+id/video_view"
android:layout_width="match_parent" android:layout_width="match_parent"
app:surface_type="texture_view" android:layout_height="match_parent"
app:use_controller="false"
android:visibility="gone" android:visibility="gone"
android:layout_height="match_parent" /> app:surface_type="texture_view"
app:use_controller="false" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_centerVertical="true"
android:orientation="horizontal">
<FrameLayout <FrameLayout
android:id="@+id/playView" android:id="@+id/playView"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="match_parent"/> android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/playView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<ImageView <ImageView
android:id="@+id/leave" android:id="@+id/leave"
@ -78,18 +94,19 @@
android:id="@+id/loading" android:id="@+id/loading"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginTop="240dp"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="240dp"
android:indeterminateBehavior="repeat" android:indeterminateBehavior="repeat"
android:indeterminateDrawable="@drawable/anim_loading" android:indeterminateDrawable="@drawable/anim_loading"
android:indeterminateOnly="true" android:indeterminateOnly="true"
android:visibility="invisible" /> android:visibility="invisible" />
<ProgressBar <ProgressBar
android:id="@+id/loading2" android:id="@+id/loading2"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginTop="240dp"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="240dp"
android:indeterminateBehavior="repeat" android:indeterminateBehavior="repeat"
android:indeterminateDrawable="@drawable/anim_loading" android:indeterminateDrawable="@drawable/anim_loading"
android:indeterminateOnly="true" android:indeterminateOnly="true"

View File

@ -4,7 +4,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -30,7 +29,6 @@
</LinearLayout> </LinearLayout>
<FrameLayout <FrameLayout
android:id="@+id/camera_preview1" android:id="@+id/camera_preview1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -91,7 +89,6 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<FrameLayout <FrameLayout
@ -161,17 +158,20 @@
android:id="@+id/pk_container" android:id="@+id/pk_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="270dp" android:layout_height="270dp"
android:background="@color/red"
android:layout_marginTop="130dp"> android:layout_marginTop="130dp">
<com.yunbao.live.custom.MyFrameLayout4 <com.yunbao.live.custom.MyFrameLayout4
android:id="@+id/left_container" android:id="@+id/left_container"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/green"
android:layout_marginBottom="20dp" /> android:layout_marginBottom="20dp" />
<com.yunbao.live.custom.MyFrameLayout4 <com.yunbao.live.custom.MyFrameLayout4
android:id="@+id/right_container" android:id="@+id/right_container"
android:layout_width="0dp" android:layout_width="0dp"
android:background="@color/gray1"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="right" android:layout_gravity="right"
android:layout_marginBottom="20dp" /> android:layout_marginBottom="20dp" />
@ -195,7 +195,6 @@
android:textSize="13sp" android:textSize="13sp"
android:visibility="gone" /> android:visibility="gone" />
<com.yunbao.live.custom.MyFrameLayout3 <com.yunbao.live.custom.MyFrameLayout3
android:id="@+id/small_container" android:id="@+id/small_container"
android:layout_width="0dp" android:layout_width="0dp"
@ -205,7 +204,6 @@
android:layout_marginBottom="120dp" android:layout_marginBottom="120dp"
app:mfl3_ratio="0.25" /> app:mfl3_ratio="0.25" />
<ImageView <ImageView
android:id="@+id/leave" android:id="@+id/leave"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -54,7 +54,6 @@ import com.yunbao.common.utils.WordUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.http.LiveHttpUtil;
import com.yunbao.common.utils.LiveRoomCheckLivePresenter; import com.yunbao.common.utils.LiveRoomCheckLivePresenter;
import com.yunbao.live.activity.NewLiveActivity;
import com.yunbao.main.R; import com.yunbao.main.R;
import com.yunbao.main.event.RegSuccessEvent; import com.yunbao.main.event.RegSuccessEvent;
import com.yunbao.main.http.MainHttpConsts; import com.yunbao.main.http.MainHttpConsts;

View File

@ -65,6 +65,7 @@ import com.yunbao.common.bean.ConfigBean;
import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.LiveBean; import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.bean.LiveSvgGiftBean; import com.yunbao.common.bean.LiveSvgGiftBean;
import com.yunbao.common.bean.SwTokenModel;
import com.yunbao.common.bean.UpdataListBean; import com.yunbao.common.bean.UpdataListBean;
import com.yunbao.common.bean.UserBean; import com.yunbao.common.bean.UserBean;
import com.yunbao.common.custom.TabButtonGroup; import com.yunbao.common.custom.TabButtonGroup;
@ -85,6 +86,7 @@ import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.LiveHttpConsts; import com.yunbao.common.http.LiveHttpConsts;
import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.http.LiveHttpUtil;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.http.main.MainNetManager; import com.yunbao.common.http.main.MainNetManager;
import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.interfaces.CommonCallback;
import com.yunbao.common.manager.APKManager; import com.yunbao.common.manager.APKManager;
@ -96,6 +98,7 @@ import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.GiftCacheUtil; import com.yunbao.common.utils.GiftCacheUtil;
import com.yunbao.common.utils.GoogleUtils; import com.yunbao.common.utils.GoogleUtils;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.LiveRoomCheckLivePresenter; import com.yunbao.common.utils.LiveRoomCheckLivePresenter;
import com.yunbao.common.utils.LocationUtil; import com.yunbao.common.utils.LocationUtil;
import com.yunbao.common.utils.ProcessResultUtil; import com.yunbao.common.utils.ProcessResultUtil;
@ -537,6 +540,22 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
//获取指导员账号 //获取指导员账号
ConversationIMListManager.get(this).getUserInstructor(this); ConversationIMListManager.get(this).getUserInstructor(this);
checkVersion(); checkVersion();
//获取声网Token
getSwToken();
}
private void getSwToken() {
LiveNetManager.get(mContext).getSwToken(new com.yunbao.common.http.base.HttpCallback<SwTokenModel>() {
@Override
public void onSuccess(SwTokenModel data) {
CommonAppConfig.SWToken = data.getToken();
}
@Override
public void onError(String error) {
}
});
} }
/** /**
@ -809,7 +828,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
} }
/** /**
* 检查版本更新 * 检查版本更新
*/ */