add[声望升级-接入美颜]

This commit is contained in:
Martin
2024-04-18 09:47:38 +08:00
parent 0db8eefbe6
commit 583740e866
41 changed files with 3303 additions and 1920 deletions

View File

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

View File

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

View File

@@ -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<RCRTCOtherRoom>() {
@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<RCRTCOtherRoom>() {
@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<RCRTCStream> 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;

View File

@@ -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"));

View File

@@ -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();
}
}
}
/**
* 打开心愿单窗口
*/

View File

@@ -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, "还原916");
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:还原916 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;
}
}

View File

@@ -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<RCRTCRoom>() {
@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<Boolean>() {
@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<RCRTCLiveInfo>() {
@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();
}
}
}