update 清晰度切换

This commit is contained in:
zlzw 2022-12-29 15:59:03 +08:00
parent 5db84c1e61
commit 956bef4b90
13 changed files with 229 additions and 47 deletions

View File

@ -28,6 +28,8 @@ public class EnterRoomNewModel extends BaseModel {
private String isUseHotCard = "";//是否使用热度卡
@SerializedName("liveRoomActivity")
private List<LiveRoomActivityModel> liveRoomActivityModels = new ArrayList<>();//活动列表
@SerializedName("clarityType")
private int clarityType;
public List<LiveRoomActivityModel> getLiveRoomActivityModels() {
return liveRoomActivityModels;
@ -109,4 +111,12 @@ public class EnterRoomNewModel extends BaseModel {
this.isUseHotCard = isUseHotCard;
return this;
}
public int getClarityType() {
return clarityType;
}
public void setClarityType(int clarityType) {
this.clarityType = clarityType;
}
}

View File

@ -4,6 +4,8 @@ import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.os.Looper;
import android.text.InputFilter;
import android.text.InputType;
import android.text.Spanned;
@ -68,6 +70,20 @@ public class DialogUitl {
}
return dialog;
}
public static void showToast(Context context,String content,long delayMillis){
Dialog dialog = new Dialog(context, R.style.dialog);
dialog.setContentView(R.layout.dialog_toast);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
if (!TextUtils.isEmpty(content)) {
TextView titleView = (TextView) dialog.findViewById(R.id.text);
if (titleView != null) {
titleView.setText(content);
}
}
dialog.show();
new Handler(Looper.getMainLooper()).postDelayed(dialog::dismiss,delayMillis);
}
public static Dialog loadingDialog(Context context) {

View File

@ -2,13 +2,17 @@ package com.yunbao.common.views;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.lxj.xpopup.core.BottomPopupView;
import com.yunbao.common.R;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
public class LiveClarityCustomPopup extends BottomPopupView implements View.OnClickListener {
@ -17,6 +21,8 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl
private int selectClarity = 1;
private RelativeLayout lineSd, lineHd, lineFhd;
private ImageView iconSd, iconHd, iconFhd;
private ImageView titleSDImg, titleHDImg, titleFHDImg;
private TextView titleSDText, titleHDText, titleFHDText;
private int banSelect;
public int getSelectClarity() {
@ -25,8 +31,12 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl
public LiveClarityCustomPopup(@NonNull Context context, int selectClarity, int banSelect) {
super(context);
this.selectClarity = selectClarity;
this.banSelect = banSelect;
if (selectClarity == -1) {
selectClarity = 0;
}
this.selectClarity = selectClarity;
ToastUtil.show("ban "+banSelect);
}
public LiveClarityCustomPopup(@NonNull Context context, int selectClarity) {
@ -67,6 +77,12 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl
iconSd = findViewById(R.id.icon_sd);
iconHd = findViewById(R.id.icon_hd);
iconFhd = findViewById(R.id.icon_fhd);
titleSDImg = findViewById(R.id.sd);
titleHDImg = findViewById(R.id.hd);
titleFHDImg = findViewById(R.id.fhd);
titleSDText = findViewById(R.id.sd_text);
titleHDText = findViewById(R.id.hd_text);
titleFHDText = findViewById(R.id.fhd_text);
selectClarity(selectClarity);
//流畅
ViewClicksAntiShake.clicksAntiShake(lineSd, () -> {
@ -90,8 +106,14 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl
if (banSelect == BAN_720) {
lineFhd.setEnabled(false);
lineHd.setEnabled(false);
titleHDImg.setImageAlpha(40);
titleFHDImg.setImageAlpha(40);
titleHDText.setAlpha(0.2f);
titleFHDText.setAlpha(0.2f);
} else if (banSelect == BAN_1080) {
lineFhd.setEnabled(false);
titleFHDText.setAlpha(0.2f);
titleFHDImg.setImageAlpha(20);
}
}

View File

@ -41,6 +41,7 @@
android:src="@mipmap/icon_sd" />
<TextView
android:id="@+id/sd_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/sd"
@ -79,6 +80,7 @@
android:src="@mipmap/icon_hd" />
<TextView
android:id="@+id/hd_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/hd"
@ -116,6 +118,7 @@
android:src="@mipmap/icon_fhd" />
<TextView
android:id="@+id/fhd_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/fhd"

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_loading_dialog"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/loading"
android:textColor="@color/white"
android:layout_margin="15dp"
android:textSize="14sp" />
</LinearLayout>

View File

@ -115,7 +115,7 @@ public class FreePkRecyclerAdapter extends RefreshAdapter<RandomPkUserBean> {
}
if (freePkNum == 0 && mDrPkNum == -1) {
ToastUtil.show(R.string.free_pk_num_null);
return;
// return;
}
LiveHttpUtil.getMicList(LiveRyAnchorActivity.mLiveUid, 0, new com.yunbao.common.http.HttpCallback() {

View File

@ -1,12 +1,17 @@
package com.yunbao.live.utils;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.SurfaceView;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.analytics.AnalyticsListener;
import com.google.android.exoplayer2.analytics.PlaybackStats;
import com.google.android.exoplayer2.analytics.PlaybackStatsListener;
import com.google.android.exoplayer2.video.VideoSize;
public class LiveExoPlayerManager {
@ -19,11 +24,66 @@ public class LiveExoPlayerManager {
private Player.Listener listener;
private boolean isSwitchUrl = false;
private String TAG = "播放";
private int playBufferIndex = 0;
private Handler handler;
public LiveExoPlayerManager(Context mContext) {
this.mContext = mContext;
player1 = new ExoPlayer.Builder(mContext).build();
player2 = new ExoPlayer.Builder(mContext).build();
handler = new Handler(Looper.getMainLooper());
setListener();
setAnalyticsListener();
}
public void setListener(Player.Listener listener) {
this.listener = listener;
}
public void setMainView(SurfaceView mainView) {
this.mainView = mainView;
}
private void setAnalyticsListener() {
player1.addAnalyticsListener(new AnalyticsListener() {
@Override
public void onPlaybackStateChanged(
EventTime eventTime, int state) {
Log.d(TAG, "onPlaybackStateChanged(1) called with: eventTime = [" + eventTime + "], state = [" + state + "]");
}
@Override
public void onDroppedVideoFrames(
EventTime eventTime, int droppedFrames, long elapsedMs) {
Log.d(TAG, "onDroppedVideoFrames(1) called with: eventTime = [" + eventTime + "], droppedFrames = [" + droppedFrames + "], elapsedMs = [" + elapsedMs + "]");
}
});
player2.addAnalyticsListener(new AnalyticsListener() {
@Override
public void onPlaybackStateChanged(
EventTime eventTime, int state) {
Log.d(TAG, "onPlaybackStateChanged(2) called with: eventTime = [" + eventTime.totalBufferedDurationMs + "], state = [" + state + "]");
}
@Override
public void onDroppedVideoFrames(
EventTime eventTime, int droppedFrames, long elapsedMs) {
Log.d(TAG, "onDroppedVideoFrames(2) called with: eventTime = [" + eventTime + "], droppedFrames = [" + droppedFrames + "], elapsedMs = [" + elapsedMs + "]");
}
});
}
private Runnable buffRunnable = new Runnable() {
@Override
public void run() {
playBufferIndex = 0;
listener.onPlaybackStateChanged(Player.STATE_BUFFERING);
}
};
private void setListener() {
player1.addListener(new Player.Listener() {
@Override
public void onPlaybackStateChanged(int playbackState) {
@ -34,9 +94,13 @@ public class LiveExoPlayerManager {
player2.setVideoSurface(null);
player1.play();
Log.i(TAG, "切换播放器1");
handler.removeCallbacks(buffRunnable);
playBufferIndex = 0;
} else if (playbackState == Player.STATE_BUFFERING && status == MODEL_PLAY1 && !isSwitchUrl) {
if (listener != null) {
listener.onPlaybackStateChanged(playbackState);
if (playBufferIndex++ == 0) {
handler.postDelayed(buffRunnable, 1000);
}
}
}
}
@ -80,9 +144,13 @@ public class LiveExoPlayerManager {
player1.setVideoSurface(null);
player2.play();
Log.i(TAG, "切换播放器2 " + player2.isPlaying());
handler.removeCallbacks(buffRunnable);
playBufferIndex = 0;
} else if (playbackState == Player.STATE_BUFFERING && status == MODEL_PLAY2 && !isSwitchUrl) {
if (listener != null) {
listener.onPlaybackStateChanged(playbackState);
if (playBufferIndex++ == 0) {
handler.postDelayed(buffRunnable, 1000);
}
}
}
}
@ -117,16 +185,9 @@ public class LiveExoPlayerManager {
});
}
public void setListener(Player.Listener listener) {
this.listener = listener;
}
public void setMainView(SurfaceView mainView) {
this.mainView = mainView;
}
public void startUrl(String url) {
isSwitchUrl = true;
playBufferIndex = 0;
getNowPlayer().setVideoSurfaceView(mainView);
getNowPlayer().setMediaItem(createMediaItem(url));
getNowPlayer().prepare();
@ -134,7 +195,8 @@ public class LiveExoPlayerManager {
}
public void switchUrl(String url) {
Log.i(TAG, "switchUrl: "+url);
Log.i(TAG, "switchUrl: " + url);
playBufferIndex = 0;
isSwitchUrl = true;
getNextPlayer().setMediaItem(createMediaItem(url));
getNextPlayer().prepare();

View File

@ -142,6 +142,11 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder {
}
@Override
public void switchStream(String url, int playModel) {
}
@Override
public void release() {

View File

@ -106,9 +106,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public static Context contexts;
public static FrameLayout ry_view;
private static final int VIDEO_VERTICAL = 1;
private static final int VIDEO_HORIZONTAL = 2;
int videoLandscape = -1; // 视频方向1=竖屏2=横屏
private static final int VIDEO_VERTICAL = 2;
private static final int VIDEO_HORIZONTAL = 1;
int videoLandscape = -1; // 视频方向2=竖屏1=横屏
static int vHeight;//视频高
private TextView debugView;
@ -197,6 +197,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
@Override
public synchronized void setLiveBeanLandscape(int landscape) {
this.landscape = landscape;
this.videoLandscape = landscape;
if (landscape == 2) {
Log.i("收到socket--->", "还原916");
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
@ -395,41 +396,39 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
super.onReceiveSeiMessage(player, payloadType, data);
}
});*/
MediaItem item = createMediaItem(url);
if (mPlayer.isPlaying()) {
ToastUtil.show("set 2 画质="+playModel);
mPlayer.switchUrl(url);
} else {
ToastUtil.show("set 1 画质="+playModel);
mPlayer.startUrl(url);
mPlayer.stop();
}
/* if (mPlayer.isPlaying()) {
MediaSource nextSource = new ProgressiveMediaSource.Factory(new DefaultHttpDataSource.Factory())
.createMediaSource(createMediaItem(url));
MediaSource oldSource = new ProgressiveMediaSource.Factory(new DefaultHttpDataSource.Factory())
.createMediaSource(mPlayer.getCurrentMediaItem());
ClippingMediaSource clippingMediaSource = new ClippingMediaSource(oldSource, 0, 3000, false, true, true);
ConcatenatingMediaSource source = new ConcatenatingMediaSource(clippingMediaSource, nextSource);
mPlayer.addMediaSource(source);
mPlayer.prepare();
mPlayer.setPlayWhenReady(true);
} else {
MediaItem item = createMediaItem(url);
mPlayer.setMediaItem(item);
mPlayer.prepare();
mPlayer.play();
}*/
mPlayer.startUrl(url);
purl = url;
onPrepared();
}
private MediaItem createMediaItem(String url) {
MediaItem mediaItem = MediaItem.fromUri(url);
return mediaItem;
@Override
public void switchStream(String url, int playModel) {
srcUrl = url;
PLAY_MODEL = playModel;
if (playModel != PLAY_MODEL_DEF) {
if (videoLandscape == VIDEO_VERTICAL) {
url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv");
} else if (videoLandscape == VIDEO_HORIZONTAL) {
url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv");
}
}
Log.e("purl121", url);
if (TextUtils.isEmpty(url) || mVideoView == null) {
return;
}
if (TextUtils.isEmpty(url) || mVideoView == null) {
return;
}
mPlayer.switchUrl(url);
purl = url;
}
@Override
public void release() {
mEnd = true;
@ -445,6 +444,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
@Override
public void stopPlay() {
Log.i(TAG, "stopPlay: ");
if (mCover != null) {
mCover.setAlpha(1f);
if (mCover.getVisibility() != View.VISIBLE) {
@ -794,8 +794,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
@Subscribe(threadMode = ThreadMode.MAIN)
public void onOpenDrawer(LiveAudienceEvent event) {
if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO) {
int ban = PLAY_MODEL == PLAY_MODEL_720 ? LiveClarityCustomPopup.BAN_1080 : PLAY_MODEL == PLAY_MODEL_480 ? LiveClarityCustomPopup.BAN_720 : 0;
LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, PLAY_MODEL);
int ban = roomModel.getClarityType() - 1 == PLAY_MODEL_720 ? LiveClarityCustomPopup.BAN_1080 : roomModel.getClarityType() - 1 == PLAY_MODEL_480 ? LiveClarityCustomPopup.BAN_720 : 0;
LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, PLAY_MODEL, ban);
new XPopup.Builder(mContext)
.setPopupCallback(new XPopupCallback() {
@Override
@ -816,7 +816,30 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
@Override
public void onDismiss(BasePopupView popupView) {
int selectClarity = liveClarityCustomPopup.getSelectClarity();
play(srcUrl, selectClarity);
if (selectClarity == PLAY_MODEL) return;
if (selectClarity == 2) {
new DialogUitl.Builder(mContext)
.setTitle("超高清提示")
.setContent("在網速不穩定的情況下,選擇超高清將會有可能導致直播間畫面卡頓,是否確認選擇?")
.setConfrimString("堅持選擇")
.setCancelString("返回")
.setClickCallback(new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
switchStream(srcUrl, selectClarity);
dialog.dismiss();
showToast();
}
}).build().show();
} else {
switchStream(srcUrl, selectClarity);
showToast();
}
}
private void showToast() {
DialogUitl.showToast(mContext, " 設置成功\n" +
"正在為你轉換中", 3000);
}
@Override
@ -1151,6 +1174,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public void onVideoSizeChanged(VideoSize videoSize) {
Player.Listener.super.onVideoSizeChanged(videoSize);
Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height);
ToastUtil.show("分辨率: width = " + videoSize.width + " height = " + videoSize.height);
if (videoSize.height > videoSize.width) {
videoLandscape = VIDEO_VERTICAL;
} else {

View File

@ -318,6 +318,11 @@ public class LivePlayTxViewHolder extends LiveRoomPlayViewHolder implements ITXL
L.e(TAG, "play----url--->" + url);
}
@Override
public void switchStream(String url, int playModel) {
}
@Override
public void stopPlay() {
mChangeToLeft = false;

View File

@ -280,6 +280,11 @@ public class LivePlayTxViewHolder_backup extends LiveRoomPlayViewHolder implemen
L.e(TAG, "play----url--->" + url);
}
@Override
public void switchStream(String url, int playModel) {
}
@Override
public void stopPlay() {
mChangeToLeft = false;

View File

@ -3,6 +3,7 @@ package com.yunbao.live.views;
import android.content.Context;
import android.view.ViewGroup;
import com.yunbao.common.bean.EnterRoomNewModel;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.views.AbsViewHolder;
import com.yunbao.live.interfaces.ILiveLinkMicViewHolder;
@ -23,12 +24,14 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL
public static final String[] videoRatioVertical = new String[]{"_480_640", "_720_1280", "_1080_1920", "_180_180"};
public static final String[] videoFps = new String[]{"_24", "_30"};
OnMicCallback onMicCallback;//连麦回调
public EnterRoomNewModel roomModel;
public LiveRoomPlayViewHolder(Context context, ViewGroup parentView) {
super(context, parentView);
}
public abstract void play(String url, int playModel);
public abstract void switchStream(String url, int playModel);
public abstract void stopPlay();
@ -66,6 +69,11 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL
this.onMicCallback = onMicCallback;
}
public void setLiveEnterRoomNewModel(EnterRoomNewModel data) {
data.setClarityType(2);
this.roomModel = data;
}
public interface OnMicCallback {
void onMikUpdate();

View File

@ -198,7 +198,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
this.mContext = context;
this.mIntent = intent;
liveImDeletUtil = new LiveImDeletUtil();
portraitLiveManager=this;
portraitLiveManager = this;
ininView();
}
@ -329,9 +329,11 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
});
}
public void test(int model) {
mLivePlayViewHolder.play(mLiveBean.getPull(), model);
}
private Runnable sendFIm = new Runnable() {
@Override
public void run() {
@ -357,6 +359,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
}
landscape = data.getLiveInfo().getLandscape();
mLivePlayViewHolder.setLiveBeanLandscape(landscape);
mLivePlayViewHolder.setLiveEnterRoomNewModel(data);
mLivePlayViewHolder.switchStream(mLiveBean.getPull(), data.getClarityType() - 1);
//是否热度卡加成
liveHandler.postDelayed(() -> mLiveRoomViewHolder.getIsHot(data.getIsUseHotCard()), 700);