update 清晰度切换
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -142,6 +142,11 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchStream(String url, int playModel) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
|
||||
@@ -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--->", "还原9:16");
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
|
||||
@@ -395,40 +396,38 @@ 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() {
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user