优化已经在多人PK时不再切换默认流分辨率

This commit is contained in:
zlzw 2023-01-10 15:35:15 +08:00
parent 872245c9c9
commit 518e57ee44
2 changed files with 19 additions and 10 deletions

View File

@ -34,7 +34,7 @@ public class LiveExoPlayerManager {
private int playBufferIndex = 0;//卡顿计数器 private int playBufferIndex = 0;//卡顿计数器
private final Handler handler; private final Handler handler;
private static double log_buffer_time = 0, log_buffer_max_time; private static double log_buffer_time = 0, log_buffer_max_time;
private String url; private String url="";
public LiveExoPlayerManager(Context mContext) { public LiveExoPlayerManager(Context mContext) {
DefaultLoadControl control = new DefaultLoadControl.Builder() DefaultLoadControl control = new DefaultLoadControl.Builder()
@ -71,6 +71,10 @@ public class LiveExoPlayerManager {
mainView.requestLayout(); mainView.requestLayout();
} }
public boolean isViewResizeModeToPhone() {
return mainView.getResizeMode() == AspectRatioFrameLayout.RESIZE_MODE_ZOOM;
}
private void setAnalyticsListener() { private void setAnalyticsListener() {
player1.addAnalyticsListener(new AnalyticsListener() { player1.addAnalyticsListener(new AnalyticsListener() {
@Override @Override
@ -240,6 +244,7 @@ public class LiveExoPlayerManager {
* @param url 地址 * @param url 地址
*/ */
public void startUrl(String url) { public void startUrl(String url) {
if(url.equals(this.url))return;
Log.i(TAG, "startUrl: " + url + " > " + mainView.getResizeMode()); Log.i(TAG, "startUrl: " + url + " > " + mainView.getResizeMode());
this.url = url; this.url = url;
isSwitchUrl = true; isSwitchUrl = true;
@ -260,7 +265,8 @@ public class LiveExoPlayerManager {
* @param url 地址 * @param url 地址
*/ */
public void switchUrl(String url) { public void switchUrl(String url) {
Log.i(TAG, "switchUrl: " + url); if(url.equals(this.url))return;
Log.i(TAG, "switchUrl: " + url +" src : "+this.url);
this.url = url; this.url = url;
playBufferIndex = 0; playBufferIndex = 0;
isSwitchUrl = true; isSwitchUrl = true;
@ -322,8 +328,8 @@ public class LiveExoPlayerManager {
} }
public String getUrl() { public String getUrl() {
if(url==null){ if (url == null) {
url=""; url = "";
} }
return url; return url;
} }

View File

@ -283,9 +283,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) { if (playModel != PLAY_MODEL_DEF && !url.contains(videoFps[0] + ".flv")) {
mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL);
if (landscape == VIDEO_VERTICAL && !isPk) { if (landscape == VIDEO_VERTICAL && !isPk) {
waitNextUrl = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv");
} else if (landscape == VIDEO_HORIZONTAL || isPk) { } else if (landscape == VIDEO_HORIZONTAL || isPk) {
waitNextUrl = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv");
} }
} else if (!url.contains(videoFps[0] + ".flv")) { } else if (!url.contains(videoFps[0] + ".flv")) {
mPlayer.setViewResizeMode(false); mPlayer.setViewResizeMode(false);
@ -342,9 +342,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
@Override @Override
public void switchStreamPk(boolean isPk) { public void switchStreamPk(boolean isPk) {
super.switchStreamPk(isPk); super.switchStreamPk(isPk);
Log.i(TAG, "switchStreamPk: isPk1" + isPk + " tmp = " + !tmpPk + " isPk2" + this.isPk); Log.i(TAG, "switchStreamPk: isPk1" + isPk + " tmp = " + !tmpPk + " isPk2 = " + this.isPk);
if(this.isPk&&tmpPk)return;
if (isPk && !tmpPk || this.isPk) { if (isPk && !tmpPk || this.isPk) {
tmpPk = true;
mPlayer.setViewResizeMode(false); mPlayer.setViewResizeMode(false);
String url; String url;
if (PLAY_MODEL != -1) { if (PLAY_MODEL != -1) {
@ -352,8 +352,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
} else { } else {
url = srcUrl.replace(".flv", videoRatioHorizontal[1] + videoFps[0] + ".flv"); url = srcUrl.replace(".flv", videoRatioHorizontal[1] + videoFps[0] + ".flv");
} }
waitNextUrl = url; if (!tmpPk) {
waitNextUrl = url;
}
mPlayer.switchUrl(srcUrl); mPlayer.switchUrl(srcUrl);
tmpPk = true;
} else if (!isPk) { } else if (!isPk) {
tmpPk = false; tmpPk = false;
if (landscape == VIDEO_VERTICAL && PLAY_MODEL != -1) { if (landscape == VIDEO_VERTICAL && PLAY_MODEL != -1) {
@ -1158,7 +1161,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
Player.Listener.super.onIsPlayingChanged(isPlaying); Player.Listener.super.onIsPlayingChanged(isPlaying);
if (isPlaying) { if (isPlaying) {
hideCover(); hideCover();
Log.i(TAG, "onIsPlayingChanged: 开始播放 | waitNextUrl = "+waitNextUrl); Log.i(TAG, "onIsPlayingChanged: 开始播放 | waitNextUrl = " + waitNextUrl);
OkDownload.getInstance().startAll(); OkDownload.getInstance().startAll();
if (loadingListener != null) { if (loadingListener != null) {
loadingListener.onPlayer(); loadingListener.onPlayer();