新增下麦后100毫秒后检测播放器是否在播放,如果未播放则强制播放purl
This commit is contained in:
parent
8e7de87c6b
commit
6ca8fb0c29
@ -254,6 +254,25 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On
|
||||
mSetting.setOnClickListener(this);
|
||||
mHonorLayout.setOnClickListener(v -> forwardHomePage());
|
||||
|
||||
//用户名片连点三次粉丝弹出视频debug窗
|
||||
/* mFansVal.setOnClickListener(new View.OnClickListener() {
|
||||
long time=0;
|
||||
int index=0;
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(time==0){
|
||||
time=System.currentTimeMillis();
|
||||
}
|
||||
index++;
|
||||
if(System.currentTimeMillis()-time<1000&&index==3){
|
||||
EventBus.getDefault().post("Debug");
|
||||
}else if(System.currentTimeMillis()-time>1000){
|
||||
index=0;
|
||||
time=0;
|
||||
}
|
||||
}
|
||||
});*/
|
||||
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
|
@ -3,9 +3,11 @@ package com.yunbao.live.views;
|
||||
import static com.lzy.okgo.utils.HttpUtils.runOnUiThread;
|
||||
import static cn.rongcloud.rtc.core.RendererCommon.ScalingType.SCALE_ASPECT_FILL;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -19,8 +21,10 @@ import android.view.ViewParent;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.lzf.easyfloat.EasyFloat;
|
||||
import com.lzy.okserver.OkDownload;
|
||||
import com.lzy.okserver.download.DownloadTask;
|
||||
import com.tencent.live2.V2TXLiveDef;
|
||||
@ -39,13 +43,17 @@ import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.common.utils.WordUtil;
|
||||
import com.yunbao.live.R;
|
||||
import com.yunbao.live.activity.LiveActivity;
|
||||
import com.yunbao.live.activity.LiveAudienceActivity;
|
||||
|
||||
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 java.util.Map;
|
||||
|
||||
import cn.rongcloud.rtc.api.RCRTCEngine;
|
||||
@ -57,6 +65,7 @@ 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;
|
||||
@ -66,6 +75,7 @@ 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.RTCErrorCode;
|
||||
|
||||
@ -92,11 +102,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
public V2TXLivePlayer mPlayer;
|
||||
public static FrameLayout ry_view;
|
||||
|
||||
private static final int VIDEO_VERTICAL=1;
|
||||
private static final int VIDEO_HORIZONTAL=2;
|
||||
private static final int VIDEO_VERTICAL = 1;
|
||||
private static final int VIDEO_HORIZONTAL = 2;
|
||||
int videoLandscape; // 视频方向,1=竖屏,2=横屏
|
||||
|
||||
static int vHeight;//视频高
|
||||
private TextView debugView;
|
||||
|
||||
|
||||
//0未申请1申请中2连麦中
|
||||
@ -143,6 +154,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
mPkContainer.requestLayout();
|
||||
mPlayer = new V2TXLivePlayerImpl(mContext);
|
||||
mPlayer.setRenderView(mVideoView);
|
||||
|
||||
debugView = new TextView(mContext);
|
||||
debugView.setBackgroundColor(Color.WHITE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -228,7 +243,14 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
*/
|
||||
@Override
|
||||
public void resumePlay() {
|
||||
|
||||
if (mPlayer.isPlaying() != 1) {
|
||||
new Handler(Looper.getMainLooper())
|
||||
.postDelayed(() -> {
|
||||
mPlayer.stopPlay();
|
||||
int val = mPlayer.startPlay(purl);
|
||||
// ToastUtil.show("强制播放" + val);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -256,6 +278,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
public void onError(V2TXLivePlayer player, int code, String msg, Bundle extraInfo) {
|
||||
super.onError(player, code, msg, extraInfo);
|
||||
Log.i(TAG, "onError: player = " + player + ", code = " + code + ", msg = " + msg + ", extraInfo = " + extraInfo);
|
||||
debugView.setText("播放出错code=" + code + " msg=" + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -268,6 +291,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
mPlayer.stopPlay();
|
||||
mPlayer.startPlay(purl);
|
||||
}
|
||||
debugView.setText("播放警告code=" + code + " msg=" + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -323,6 +347,14 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
buffer.append("|");
|
||||
}
|
||||
hideCover();
|
||||
String debugText = "视频码率:" + statistics.videoBitrate + "\n" +
|
||||
"音频码率:" + statistics.audioBitrate + "\n" +
|
||||
"FPS:" + statistics.fps + "\n" +
|
||||
"CPU:" + statistics.appCpu + "\n" +
|
||||
"分辨率:" + statistics.height + "x" + statistics.width + "\n" +
|
||||
"播放状态:" + mPlayer.isPlaying() + "\n" +
|
||||
"当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n";
|
||||
debugView.setText(debugText);
|
||||
Log.i(TAG, "onStatisticsUpdate: " + JSON.toJSONString(statistics) + " |当前下载数 : " + OkDownload.getInstance().getTaskMap().size() + buffer);
|
||||
if (statistics.height > statistics.width) {
|
||||
videoLandscape = VIDEO_VERTICAL;
|
||||
@ -413,10 +445,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
return;
|
||||
}
|
||||
int height;
|
||||
if(videoLandscape==VIDEO_VERTICAL){
|
||||
height= ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
}else{
|
||||
height=DpUtil.dp2px(285);
|
||||
if (videoLandscape == VIDEO_VERTICAL) {
|
||||
height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
} else {
|
||||
height = DpUtil.dp2px(285);
|
||||
}
|
||||
if (landscape == 2) {
|
||||
Log.i("收到socket--->", "还原9:16");
|
||||
@ -443,7 +475,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
|
||||
params.height = height;
|
||||
params.topMargin = 0;
|
||||
if(videoLandscape==VIDEO_HORIZONTAL){
|
||||
if (videoLandscape == VIDEO_HORIZONTAL) {
|
||||
params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
|
||||
}
|
||||
params.addRule(RelativeLayout.ALIGN_TOP);
|
||||
@ -454,13 +486,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
params1.height = height;
|
||||
params1.topMargin = 0;
|
||||
params1.addRule(RelativeLayout.ALIGN_TOP);
|
||||
if(videoLandscape==VIDEO_HORIZONTAL){
|
||||
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.height = height;
|
||||
params2.topMargin = DpUtil.dp2px(120);
|
||||
mCover.setLayoutParams(params2);
|
||||
mCover.requestLayout();
|
||||
@ -627,7 +659,17 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
.setClickCallback(new DialogUitl.SimpleCallback() {
|
||||
@Override
|
||||
public void onConfirmClick(Dialog dialog, String content) {
|
||||
UsertoRY();
|
||||
LiveAudienceActivity.mProcessResultUtil.requestPermissions(new String[]{
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.RECORD_AUDIO
|
||||
}, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UsertoRY();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
builder.build().show();
|
||||
@ -667,6 +709,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
rcrtcRoom = null;
|
||||
MicStatusManager.getInstance().clear();
|
||||
ToastUtil.show("已成功退出語音連麥");
|
||||
resumePlay();
|
||||
if (onMicCallback != null) {
|
||||
onMicCallback.onMikUpdate();
|
||||
}
|
||||
@ -694,6 +737,16 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if ("Debug".equals(str)) {
|
||||
if (EasyFloat.isShow("Debug")) {
|
||||
EasyFloat.dismiss("Debug");
|
||||
return;
|
||||
}
|
||||
EasyFloat.with(mContext)
|
||||
.setDragEnable(true)
|
||||
.setTag("Debug")
|
||||
.setLayout(debugView)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
@ -895,6 +948,20 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
//如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示
|
||||
RCRTCVideoView remoteView = new RCRTCVideoView(contexts);
|
||||
((RCRTCVideoInputStream) stream).setVideoView(remoteView);
|
||||
((RCRTCVideoInputStream) stream).setVideoFrameListener(new IRCRTCVideoInputFrameListener() {
|
||||
@Override
|
||||
public void onFrame(RCRTCRemoteVideoFrame videoFrame) {
|
||||
String debugText = "视频类型:" + 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";
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
debugView.setText(debugText);
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
//todo 本demo只演示添加1个远端用户的视图
|
||||
ry_view.removeAllViews();
|
||||
remoteView.setScalingType(SCALE_ASPECT_FILL);
|
||||
|
Loading…
Reference in New Issue
Block a user