1303 lines
53 KiB
Java
1303 lines
53 KiB
Java
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.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.CommonAppConfig;
|
||
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 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;
|
||
import io.agora.beautyapi.faceunity.agora.SWAuManager;
|
||
|
||
public class LivePlayRyViewHolder 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;
|
||
|
||
public int getLandscape() {
|
||
return landscape;
|
||
}
|
||
|
||
public LivePlayRyViewHolder(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_ksy;
|
||
}
|
||
|
||
@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);
|
||
}
|
||
|
||
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));
|
||
}
|
||
|
||
@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);
|
||
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 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;
|
||
}
|
||
|
||
/**
|
||
* 播放开始
|
||
*/
|
||
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();
|
||
}
|
||
|
||
|
||
@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");
|
||
}
|
||
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<Integer>() {
|
||
@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) {
|
||
//将当前主播画面换个画布展示
|
||
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();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 把观众转换成主播
|
||
*/
|
||
public List<RCRTCInputStream> 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<RCRTCRoom>() {
|
||
|
||
|
||
@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<RCRTCInputStream> 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<RCRTCInputStream> streams) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onUserJoined(RCRTCRemoteUser remoteUser) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onUserLeft(RCRTCRemoteUser remoteUser) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onUserOffline(RCRTCRemoteUser remoteUser) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onPublishLiveStreams(List<RCRTCInputStream> streams) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onUnpublishLiveStreams(List<RCRTCInputStream> streams) {
|
||
|
||
}
|
||
};
|
||
|
||
|
||
public List<RCRTCInputStream> userinputStreamList1 = new ArrayList<>();
|
||
public List<RCRTCInputStream> 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<RCRTCOutputStream> 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<RCRTCLiveInfo>() {
|
||
/**
|
||
* 当切换失败且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);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
}
|