update:调整下载策略,如检测到直播播放器卡顿(fps为0)则暂停所有下载所有任务,当fps大于0则认为正常网络而继续下载,从而确保优先播放
This commit is contained in:
@@ -2,7 +2,9 @@ package com.yunbao.live.views;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
@@ -15,11 +17,16 @@ import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.lzy.okserver.OkDownload;
|
||||
import com.lzy.okserver.download.DownloadTask;
|
||||
import com.tencent.live2.V2TXLiveDef;
|
||||
import com.tencent.live2.V2TXLivePlayer;
|
||||
import com.tencent.live2.V2TXLivePlayerObserver;
|
||||
import com.tencent.live2.impl.V2TXLivePlayerImpl;
|
||||
import com.tencent.rtmp.ui.TXCloudVideoView;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.http.CommonHttpConsts;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.http.HttpClient;
|
||||
import com.yunbao.common.utils.DialogUitl;
|
||||
@@ -37,6 +44,7 @@ import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.rongcloud.rtc.api.RCRTCEngine;
|
||||
import cn.rongcloud.rtc.api.RCRTCRemoteUser;
|
||||
@@ -189,7 +197,71 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
if (TextUtils.isEmpty(url) || mVideoView == null) {
|
||||
return;
|
||||
}
|
||||
mPlayer.setCacheParams(1.0f, 5.0f);
|
||||
mPlayer.setObserver(new V2TXLivePlayerObserver() {
|
||||
String TAG = "播放流";
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWarning(V2TXLivePlayer player, int code, String msg, Bundle extraInfo) {
|
||||
super.onWarning(player, code, msg, extraInfo);
|
||||
Log.i(TAG, "onWarning: " + "player = " + player + ", code = " + code + ", msg = " + msg + ", extraInfo = " + extraInfo);
|
||||
if (code == 2105) {
|
||||
// mPlayer.resumeVideo();
|
||||
// mPlayer.resumeAudio();
|
||||
/* mPlayer.stopPlay();
|
||||
mPlayer.startPlay(purl);*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoPlayStatusUpdate(V2TXLivePlayer player, V2TXLiveDef.V2TXLivePlayStatus status, V2TXLiveDef.V2TXLiveStatusChangeReason reason, Bundle extraInfo) {
|
||||
super.onVideoPlayStatusUpdate(player, status, reason, extraInfo);
|
||||
//Log.i(TAG, "onVideoPlayStatusUpdate: " + "player = " + player + ", status = " + status + ", reason = " + reason + ", extraInfo = " + extraInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAudioPlayStatusUpdate(V2TXLivePlayer player, V2TXLiveDef.V2TXLivePlayStatus status, V2TXLiveDef.V2TXLiveStatusChangeReason reason, Bundle extraInfo) {
|
||||
super.onAudioPlayStatusUpdate(player, status, reason, extraInfo);
|
||||
//Log.i(TAG, "onAudioPlayStatusUpdate: " + "player = " + player + ", status = " + status + ", reason = " + reason + ", extraInfo = " + extraInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayoutVolumeUpdate(V2TXLivePlayer player, int volume) {
|
||||
super.onPlayoutVolumeUpdate(player, volume);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatisticsUpdate(V2TXLivePlayer player, V2TXLiveDef.V2TXLivePlayerStatistics statistics) {
|
||||
super.onStatisticsUpdate(player, statistics);
|
||||
if (statistics.fps == 0) {
|
||||
OkDownload.getInstance().pauseAll();
|
||||
} else {
|
||||
OkDownload.getInstance().startAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSnapshotComplete(V2TXLivePlayer player, Bitmap image) {
|
||||
super.onSnapshotComplete(player, image);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderVideoFrame(V2TXLivePlayer player, V2TXLiveDef.V2TXLiveVideoFrame videoFrame) {
|
||||
super.onRenderVideoFrame(player, videoFrame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveSeiMessage(V2TXLivePlayer player, int payloadType, byte[] data) {
|
||||
super.onReceiveSeiMessage(player, payloadType, data);
|
||||
}
|
||||
});
|
||||
mPlayer.setRenderView(mVideoView);
|
||||
purl = url;
|
||||
mPlayer.startPlay(url);
|
||||
@@ -216,7 +288,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
mCover.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
if(mPlayer!=null) {
|
||||
if (mPlayer != null) {
|
||||
mPlayer.stopPlay();
|
||||
}
|
||||
stopPlay2();
|
||||
|
||||
Reference in New Issue
Block a user