修复PK时画面异常问题(分辨率未切到4:3)
优化播放器加载速度2
This commit is contained in:
parent
27bd65d3da
commit
182e46799a
@ -6,6 +6,7 @@ import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.DefaultLoadControl;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
@ -13,6 +14,9 @@ import com.google.android.exoplayer2.analytics.AnalyticsListener;
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||
import com.google.android.exoplayer2.ui.StyledPlayerView;
|
||||
import com.google.android.exoplayer2.video.VideoSize;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 直播间播放器管理器
|
||||
@ -30,13 +34,23 @@ public class LiveExoPlayerManager {
|
||||
private String TAG = "播放器";
|
||||
private int playBufferIndex = 0;//卡顿计数器
|
||||
private Handler handler;
|
||||
private static double log_buffer_time = 0, log_buffer_max_time;
|
||||
|
||||
public LiveExoPlayerManager(Context mContext) {
|
||||
this.mContext = mContext;
|
||||
player1 = new ExoPlayer.Builder(mContext).build();
|
||||
player2 = new ExoPlayer.Builder(mContext).build();
|
||||
DefaultLoadControl control = new DefaultLoadControl.Builder()
|
||||
.setPrioritizeTimeOverSizeThresholds(true)
|
||||
.setBackBuffer(15_000, true)
|
||||
.setBufferDurationsMs(100,
|
||||
15_000,
|
||||
50,
|
||||
100)
|
||||
.build();
|
||||
player1 = new ExoPlayer.Builder(mContext).setLoadControl(control).build();
|
||||
player2 = new ExoPlayer.Builder(mContext).setLoadControl(control).build();
|
||||
player1.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
|
||||
player2.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
|
||||
|
||||
handler = new Handler(Looper.getMainLooper());
|
||||
setListener();
|
||||
setAnalyticsListener();
|
||||
@ -51,7 +65,9 @@ public class LiveExoPlayerManager {
|
||||
this.mainView = mainView;
|
||||
this.mainView.setKeepContentOnPlayerReset(true);
|
||||
}
|
||||
|
||||
public void setViewResizeMode(boolean isPhone) {
|
||||
Log.i(TAG, "setViewResizeMode: "+isPhone);
|
||||
mainView.setResizeMode(isPhone ? AspectRatioFrameLayout.RESIZE_MODE_ZOOM : AspectRatioFrameLayout.RESIZE_MODE_FIT);
|
||||
mainView.requestLayout();
|
||||
}
|
||||
@ -126,6 +142,14 @@ public class LiveExoPlayerManager {
|
||||
if (isPlaying) {
|
||||
Log.i(TAG, "onIsPlayingChanged1: 播放了");
|
||||
//player1.setVideoSurfaceView(mainView);
|
||||
if (log_buffer_time != -1) {
|
||||
double tmp = (System.currentTimeMillis() - log_buffer_time) / 1000;
|
||||
if (tmp > log_buffer_max_time) {
|
||||
log_buffer_max_time = tmp;
|
||||
}
|
||||
ToastUtil.show(String.format(Locale.CHINA, "从加载到播放 = %.3f,最大耗时 = %.3f", tmp, log_buffer_max_time));
|
||||
log_buffer_time = -1;
|
||||
}
|
||||
mainView.setPlayer(player1);
|
||||
status = MODEL_PLAY1;
|
||||
isSwitchUrl = false;
|
||||
@ -180,6 +204,12 @@ public class LiveExoPlayerManager {
|
||||
Log.i(TAG, "onIsPlayingChanged2: 播放了");
|
||||
//player2.setVideoSurfaceView(mainView);
|
||||
mainView.setPlayer(player2);
|
||||
double tmp = (System.currentTimeMillis() - log_buffer_time) / 1000;
|
||||
if (tmp > log_buffer_max_time) {
|
||||
log_buffer_max_time = tmp;
|
||||
}
|
||||
ToastUtil.show(String.format(Locale.CHINA, "从加载到播放 = %.3f,最大耗时 = %.3f", tmp, log_buffer_max_time));
|
||||
log_buffer_time = -1;
|
||||
status = MODEL_PLAY2;
|
||||
isSwitchUrl = false;
|
||||
if (listener != null) {
|
||||
@ -214,6 +244,7 @@ public class LiveExoPlayerManager {
|
||||
Log.i(TAG, "startUrl: " + url + " > " + mainView.getResizeMode());
|
||||
isSwitchUrl = true;
|
||||
playBufferIndex = 0;
|
||||
log_buffer_time = System.currentTimeMillis();
|
||||
//getNowPlayer().setVideoSurfaceView(mainView);
|
||||
mainView.setPlayer(getNowPlayer());
|
||||
getNowPlayer().setMediaItem(createMediaItem(url));
|
||||
@ -230,6 +261,7 @@ public class LiveExoPlayerManager {
|
||||
Log.i(TAG, "switchUrl: " + url);
|
||||
playBufferIndex = 0;
|
||||
isSwitchUrl = true;
|
||||
log_buffer_time = System.currentTimeMillis();
|
||||
getNextPlayer().setMediaItem(createMediaItem(url));
|
||||
getNextPlayer().prepare();
|
||||
}
|
||||
|
@ -391,6 +391,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
} else {
|
||||
height = DpUtil.dp2px(285);
|
||||
}
|
||||
mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL);
|
||||
if (landscape == 2) {
|
||||
Log.i("收到socket--->", "还原9:16");
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
|
||||
@ -441,6 +442,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
@Override
|
||||
public void setPkview() {
|
||||
Log.i("收到socket--->", "变成16:9");
|
||||
String url=srcUrl;
|
||||
url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv");
|
||||
mPlayer.setViewResizeMode(false);
|
||||
mPlayer.switchUrl(url);
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
|
||||
params.height = vHeight;
|
||||
params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
|
||||
@ -455,12 +460,22 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
||||
|
||||
if (landscape == 2) {
|
||||
Log.i("收到socket--->", "还原9:16");
|
||||
String url=srcUrl;
|
||||
url = url.replace(".flv", videoRatioVertical[PLAY_MODEL] + videoFps[0] + ".flv");
|
||||
mPlayer.setViewResizeMode(true);
|
||||
mPlayer.switchUrl(url);
|
||||
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
|
||||
params.height = RelativeLayout.LayoutParams.MATCH_PARENT;
|
||||
params.topMargin = 0;
|
||||
mVideoView.requestLayout();
|
||||
|
||||
} else {
|
||||
String url=srcUrl;
|
||||
url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv");
|
||||
mPlayer.setViewResizeMode(false);
|
||||
mPlayer.switchUrl(url);
|
||||
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
|
||||
params.height = vHeight;
|
||||
params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
|
||||
|
@ -586,7 +586,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
|
||||
mLiveRoomViewHolder.showPrizePoolLevel(String.valueOf(giftPrizePoolLevel));
|
||||
}
|
||||
}
|
||||
//liveHandler.postDelayed(() -> loading.setVisibility(View.GONE), 700);
|
||||
liveHandler.postDelayed(() -> loading.setVisibility(View.GONE), 5_000);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user