调整视频播放器3

This commit is contained in:
zlzw 2023-01-09 13:26:32 +08:00
parent eaae58db31
commit bacf4fd32f
3 changed files with 23 additions and 9 deletions

View File

@ -78,6 +78,7 @@ public class DialogUitl {
if (!TextUtils.isEmpty(content)) { if (!TextUtils.isEmpty(content)) {
TextView titleView = (TextView) dialog.findViewById(R.id.text); TextView titleView = (TextView) dialog.findViewById(R.id.text);
if (titleView != null) { if (titleView != null) {
titleView.setGravity(Gravity.CENTER);
titleView.setText(content); titleView.setText(content);
} }
} }

View File

@ -5,6 +5,8 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultLoadControl; import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
@ -15,8 +17,6 @@ import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.StyledPlayerView; import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.google.android.exoplayer2.video.VideoSize; import com.google.android.exoplayer2.video.VideoSize;
import androidx.annotation.NonNull;
/** /**
* 直播间播放器管理器 * 直播间播放器管理器
* 通过预加载子播放器来实现无缝切换分辨率功能 * 通过预加载子播放器来实现无缝切换分辨率功能
@ -65,7 +65,7 @@ public class LiveExoPlayerManager {
} }
public void setViewResizeMode(boolean isPhone) { public void setViewResizeMode(boolean isPhone) {
Log.i(TAG, "setViewResizeMode: "+isPhone); Log.i(TAG, "setViewResizeMode: " + isPhone);
mainView.setResizeMode(isPhone ? AspectRatioFrameLayout.RESIZE_MODE_ZOOM : AspectRatioFrameLayout.RESIZE_MODE_FIT); mainView.setResizeMode(isPhone ? AspectRatioFrameLayout.RESIZE_MODE_ZOOM : AspectRatioFrameLayout.RESIZE_MODE_FIT);
mainView.requestLayout(); mainView.requestLayout();
} }
@ -262,6 +262,7 @@ public class LiveExoPlayerManager {
playBufferIndex = 0; playBufferIndex = 0;
isSwitchUrl = true; isSwitchUrl = true;
log_buffer_time = System.currentTimeMillis(); log_buffer_time = System.currentTimeMillis();
mainView.setKeepContentOnPlayerReset(true);
getNextPlayer().setMediaItem(createMediaItem(url)); getNextPlayer().setMediaItem(createMediaItem(url));
getNextPlayer().prepare(); getNextPlayer().prepare();
} }
@ -305,6 +306,10 @@ public class LiveExoPlayerManager {
getNowPlayer().play(); getNowPlayer().play();
} }
public void clearFrame() {
//mainView.setKeepContentOnPlayerReset(false);
}
/** /**
* 释放播放器 * 释放播放器
*/ */

View File

@ -30,6 +30,7 @@ import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.interfaces.XPopupCallback; import com.lxj.xpopup.interfaces.XPopupCallback;
import com.lzf.easyfloat.EasyFloat; import com.lzf.easyfloat.EasyFloat;
import com.lzy.okserver.OkDownload; import com.lzy.okserver.OkDownload;
import com.yunbao.common.bean.EnterRoomNewModel;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.HttpClient; import com.yunbao.common.http.HttpClient;
import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMLoginManager;
@ -239,6 +240,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
} }
} }
@Override
public void setLiveEnterRoomNewModel(EnterRoomNewModel data) {
super.setLiveEnterRoomNewModel(data);
mPlayer.clearFrame();
}
/** /**
* 暂停播放 * 暂停播放
*/ */
@ -390,7 +397,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
if (videoLandscape == VIDEO_VERTICAL) { if (videoLandscape == VIDEO_VERTICAL) {
height = ViewGroup.LayoutParams.MATCH_PARENT; height = ViewGroup.LayoutParams.MATCH_PARENT;
} else { } else {
height = DpUtil.dp2px(285); height = ViewGroup.LayoutParams.WRAP_CONTENT;
} }
mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL); mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL);
if (landscape == 2) { if (landscape == 2) {
@ -444,7 +451,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public void setPkview() { public void setPkview() {
Log.i("收到socket--->", "变成169"); Log.i("收到socket--->", "变成169");
String url = srcUrl; String url = srcUrl;
if(PLAY_MODEL!=-1) { if (PLAY_MODEL != -1) {
url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv");
} }
mPlayer.setViewResizeMode(false); mPlayer.setViewResizeMode(false);
@ -477,7 +484,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
} else { } else {
String url = srcUrl; String url = srcUrl;
if(PLAY_MODEL!=-1) { if (PLAY_MODEL != -1) {
url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv"); url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL] + videoFps[0] + ".flv");
} }
mPlayer.setViewResizeMode(false); mPlayer.setViewResizeMode(false);
@ -727,7 +734,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
} }
LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext,
IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL), IMLoginManager.get(mContext).getInt(PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR),
ban, ban,
true); true);
new XPopup.Builder(mContext) new XPopup.Builder(mContext)
@ -750,7 +757,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
@Override @Override
public void onDismiss(BasePopupView popupView) { public void onDismiss(BasePopupView popupView) {
int selectClarity = liveClarityCustomPopup.getSelectClarity(); int selectClarity = liveClarityCustomPopup.getSelectClarity();
if (selectClarity == PLAY_MODEL) return; if (selectClarity == PLAY_MODEL || selectClarity == IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, PLAY_MODEL_ANCHOR))
return;
if (selectClarity == PLAY_MODEL_ANCHOR) { if (selectClarity == PLAY_MODEL_ANCHOR) {
switchStream(srcUrl, PLAY_MODEL_DEF); switchStream(srcUrl, PLAY_MODEL_DEF);
setAudiencePlayModel(selectClarity); setAudiencePlayModel(selectClarity);
@ -762,7 +770,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
} }
private void showToast() { private void showToast() {
DialogUitl.showToast(mContext, " 設置成功\n" + DialogUitl.showToast(mContext, "設置成功\n" +
"正在為你轉換中", 3000); "正在為你轉換中", 3000);
} }