调整观众端选择分辨率

This commit is contained in:
zlzw 2023-01-08 14:21:52 +08:00
parent 65efa88d4a
commit a1f07b8c20
6 changed files with 33 additions and 11 deletions

View File

@ -49,6 +49,11 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl
selectClarity = 0; selectClarity = 0;
} }
this.isUser = isUser; this.isUser = isUser;
if (banSelect == BAN_720) {
selectClarity = 0;
} else if (banSelect == BAN_1080 && selectClarity == 3) {
selectClarity = 2;
}
this.selectClarity = selectClarity; this.selectClarity = selectClarity;
} }

View File

@ -1,7 +1,5 @@
package com.yunbao.live.utils; package com.yunbao.live.utils;
import static com.google.android.exoplayer2.C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -12,6 +10,7 @@ import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.analytics.AnalyticsListener; 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.ui.StyledPlayerView;
import com.google.android.exoplayer2.video.VideoSize; import com.google.android.exoplayer2.video.VideoSize;
@ -52,6 +51,10 @@ public class LiveExoPlayerManager {
this.mainView = mainView; this.mainView = mainView;
this.mainView.setKeepContentOnPlayerReset(true); this.mainView.setKeepContentOnPlayerReset(true);
} }
public void setViewResizeMode(boolean isPhone){
mainView.setResizeMode(isPhone?AspectRatioFrameLayout.RESIZE_MODE_ZOOM:AspectRatioFrameLayout.RESIZE_MODE_FIT);
mainView.requestLayout();
}
private void setAnalyticsListener() { private void setAnalyticsListener() {
player1.addAnalyticsListener(new AnalyticsListener() { player1.addAnalyticsListener(new AnalyticsListener() {
@ -135,6 +138,7 @@ public class LiveExoPlayerManager {
@Override @Override
public void onVideoSizeChanged(VideoSize videoSize) { public void onVideoSizeChanged(VideoSize videoSize) {
Player.Listener.super.onVideoSizeChanged(videoSize); Player.Listener.super.onVideoSizeChanged(videoSize);
setViewResizeMode(videoSize.height>videoSize.width);
Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height); Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height);
if (listener != null) { if (listener != null) {
listener.onVideoSizeChanged(videoSize); listener.onVideoSizeChanged(videoSize);
@ -187,6 +191,7 @@ public class LiveExoPlayerManager {
@Override @Override
public void onVideoSizeChanged(VideoSize videoSize) { public void onVideoSizeChanged(VideoSize videoSize) {
Player.Listener.super.onVideoSizeChanged(videoSize); Player.Listener.super.onVideoSizeChanged(videoSize);
setViewResizeMode(videoSize.height>videoSize.width);
if (listener != null) { if (listener != null) {
listener.onVideoSizeChanged(videoSize); listener.onVideoSizeChanged(videoSize);
} }
@ -206,7 +211,7 @@ public class LiveExoPlayerManager {
* @param url 地址 * @param url 地址
*/ */
public void startUrl(String url) { public void startUrl(String url) {
Log.i(TAG, "startUrl: "+url); Log.i(TAG, "startUrl: "+url+" > "+mainView.getResizeMode());
isSwitchUrl = true; isSwitchUrl = true;
playBufferIndex = 0; playBufferIndex = 0;
//getNowPlayer().setVideoSurfaceView(mainView); //getNowPlayer().setVideoSurfaceView(mainView);

View File

@ -192,8 +192,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
@Override @Override
public synchronized void setLiveBeanLandscape(int landscape) { public synchronized void setLiveBeanLandscape(int landscape) {
// landscape=1;
Log.i(TAG, "setLiveBeanLandscape: " + landscape);
this.landscape = landscape; this.landscape = landscape;
this.videoLandscape = landscape; this.videoLandscape = landscape;
mPlayer.setViewResizeMode(landscape==VIDEO_VERTICAL);
if (landscape == 2) { if (landscape == 2) {
Log.i("收到socket--->", "还原916"); Log.i("收到socket--->", "还原916");
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
@ -267,12 +270,16 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public void play(String url, int playModel) { public void play(String url, int playModel) {
srcUrl = url; srcUrl = url;
PLAY_MODEL = playModel; PLAY_MODEL = playModel;
Log.i(TAG, "play" + " url:" + url + " playModel: " + playModel + " landscape: " + videoLandscape);
if (playModel != PLAY_MODEL_DEF) { if (playModel != PLAY_MODEL_DEF) {
if (videoLandscape == VIDEO_VERTICAL) { mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL);
if (landscape == VIDEO_VERTICAL) {
url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv");
} else if (videoLandscape == VIDEO_HORIZONTAL) { } else if (landscape == VIDEO_HORIZONTAL) {
url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv");
} }
} else {
mPlayer.setViewResizeMode(false);
} }
Log.e("purl121", url); Log.e("purl121", url);
@ -295,12 +302,16 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public void switchStream(String url, int playModel) { public void switchStream(String url, int playModel) {
srcUrl = url; srcUrl = url;
PLAY_MODEL = playModel; PLAY_MODEL = playModel;
Log.i(TAG, "switchStream: " + " url:" + url + " playModel: " + playModel + " landscape: " + landscape + " videoLandscape = " + videoLandscape);
if (playModel != PLAY_MODEL_DEF) { if (playModel != PLAY_MODEL_DEF) {
if (videoLandscape == VIDEO_VERTICAL) { mPlayer.setViewResizeMode(landscape == VIDEO_VERTICAL);
if (landscape == VIDEO_VERTICAL) {
url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv");
} else if (videoLandscape == VIDEO_HORIZONTAL) { } else if (landscape == VIDEO_HORIZONTAL) {
url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv");
} }
} else {
mPlayer.setViewResizeMode(false);
} }
Log.e("purl121", url); Log.e("purl121", url);
@ -348,6 +359,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public void stopPlay2() { public void stopPlay2() {
} }
@Override @Override
public void setViewUP(int i) { public void setViewUP(int i) {
if (mVideoView == null) return; if (mVideoView == null) return;
@ -692,7 +704,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
break; break;
} }
LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, PLAY_MODEL, ban,true); LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, PLAY_MODEL, ban, true);
new XPopup.Builder(mContext) new XPopup.Builder(mContext)
.setPopupCallback(new XPopupCallback() { .setPopupCallback(new XPopupCallback() {
@Override @Override

View File

@ -20,7 +20,7 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL
public static final int PLAY_MODEL_1080 = 2; public static final int PLAY_MODEL_1080 = 2;
public static int PLAY_MODEL = PLAY_MODEL_DEF; public static int PLAY_MODEL = PLAY_MODEL_DEF;
public static final String[] videoRatioHorizontal = new String[]{"_848_480", "_1280_720", "_1920_1080"}; public static final String[] videoRatioHorizontal = new String[]{"_640_480", "_960_720", "_1440_1080"};
public static final String[] videoRatioVertical = new String[]{"_480_848", "_720_1280", "_1080_1920"}; public static final String[] videoRatioVertical = new String[]{"_480_848", "_720_1280", "_1080_1920"};
public static final String[] videoFps = new String[]{"_24", "_30"}; public static final String[] videoFps = new String[]{"_24", "_30"};
OnMicCallback onMicCallback;//连麦回调 OnMicCallback onMicCallback;//连麦回调

View File

@ -299,6 +299,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
mask.setVisibility(View.VISIBLE); mask.setVisibility(View.VISIBLE);
mLivePlayViewHolder.setLiveBean(mLiveBean); mLivePlayViewHolder.setLiveBean(mLiveBean);
mLivePlayViewHolder.setCover(mLiveBean.getAvatar()); mLivePlayViewHolder.setCover(mLiveBean.getAvatar());
mLivePlayViewHolder.setLiveBeanLandscape(mLiveBean.getLandscape());
mLivePlayViewHolder.play(mLiveBean.getPull(), LiveRoomPlayViewHolder.PLAY_MODEL_720); mLivePlayViewHolder.play(mLiveBean.getPull(), LiveRoomPlayViewHolder.PLAY_MODEL_720);
mLivePlayViewHolder.setOnMicCallback(new LiveRoomPlayViewHolder.OnMicCallback() { mLivePlayViewHolder.setOnMicCallback(new LiveRoomPlayViewHolder.OnMicCallback() {
@Override @Override
@ -357,7 +358,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
landscape = data.getLiveInfo().getLandscape(); landscape = data.getLiveInfo().getLandscape();
mLivePlayViewHolder.setLiveBeanLandscape(landscape); mLivePlayViewHolder.setLiveBeanLandscape(landscape);
mLivePlayViewHolder.setLiveEnterRoomNewModel(data); mLivePlayViewHolder.setLiveEnterRoomNewModel(data);
//mLivePlayViewHolder.switchStream(mLiveBean.getPull(), (data.getClarityType() - 1) == 2 ? 1 : (data.getClarityType() - 1)); mLivePlayViewHolder.switchStream(mLiveBean.getPull(), (data.getClarityType() - 1) == 2 ? 1 : (data.getClarityType() - 1));
//是否热度卡加成 //是否热度卡加成
liveHandler.postDelayed(() -> mLiveRoomViewHolder.getIsHot(data.getIsUseHotCard()), 700); liveHandler.postDelayed(() -> mLiveRoomViewHolder.getIsHot(data.getIsUseHotCard()), 700);

View File

@ -11,7 +11,6 @@
android:id="@+id/video_view" android:id="@+id/video_view"
android:layout_width="match_parent" android:layout_width="match_parent"
app:surface_type="texture_view" app:surface_type="texture_view"
app:resize_mode="zoom"
app:use_controller="false" app:use_controller="false"
android:layout_height="match_parent" /> android:layout_height="match_parent" />