优化播放抛错时重新播放
优化滑动直播间时可能出现上一个直播间画面的问题
This commit is contained in:
parent
518e57ee44
commit
3606815a41
@ -11,6 +11,7 @@ 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;
|
||||||
import com.google.android.exoplayer2.MediaItem;
|
import com.google.android.exoplayer2.MediaItem;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
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.AspectRatioFrameLayout;
|
||||||
@ -34,7 +35,7 @@ public class LiveExoPlayerManager {
|
|||||||
private int playBufferIndex = 0;//卡顿计数器
|
private int playBufferIndex = 0;//卡顿计数器
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
private static double log_buffer_time = 0, log_buffer_max_time;
|
private static double log_buffer_time = 0, log_buffer_max_time;
|
||||||
private String url="";
|
private String url = "";
|
||||||
|
|
||||||
public LiveExoPlayerManager(Context mContext) {
|
public LiveExoPlayerManager(Context mContext) {
|
||||||
DefaultLoadControl control = new DefaultLoadControl.Builder()
|
DefaultLoadControl control = new DefaultLoadControl.Builder()
|
||||||
@ -123,7 +124,7 @@ public class LiveExoPlayerManager {
|
|||||||
public void onPlaybackStateChanged(int playbackState) {
|
public void onPlaybackStateChanged(int playbackState) {
|
||||||
Player.Listener.super.onPlaybackStateChanged(playbackState);
|
Player.Listener.super.onPlaybackStateChanged(playbackState);
|
||||||
Log.i(TAG, "onPlaybackStateChanged 1: " + playbackState);
|
Log.i(TAG, "onPlaybackStateChanged 1: " + playbackState);
|
||||||
if (playbackState == Player.STATE_READY) {
|
if (playbackState == Player.STATE_READY && !player1.isPlaying()) {
|
||||||
player2.stop();
|
player2.stop();
|
||||||
player2.clearVideoSurface();
|
player2.clearVideoSurface();
|
||||||
player1.play();
|
player1.play();
|
||||||
@ -177,6 +178,15 @@ public class LiveExoPlayerManager {
|
|||||||
Player.Listener.super.onIsLoadingChanged(isLoading);
|
Player.Listener.super.onIsLoadingChanged(isLoading);
|
||||||
Log.i(TAG, "onIsLoadingChanged: 1 " + isLoading);
|
Log.i(TAG, "onIsLoadingChanged: 1 " + isLoading);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerError(@NonNull PlaybackException error) {
|
||||||
|
Player.Listener.super.onPlayerError(error);
|
||||||
|
error.printStackTrace();
|
||||||
|
String url=LiveExoPlayerManager.this.url;
|
||||||
|
LiveExoPlayerManager.this.url=null;
|
||||||
|
startUrl(url);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
player2.addListener(new Player.Listener() {
|
player2.addListener(new Player.Listener() {
|
||||||
@ -184,7 +194,7 @@ public class LiveExoPlayerManager {
|
|||||||
public void onPlaybackStateChanged(int playbackState) {
|
public void onPlaybackStateChanged(int playbackState) {
|
||||||
Player.Listener.super.onPlaybackStateChanged(playbackState);
|
Player.Listener.super.onPlaybackStateChanged(playbackState);
|
||||||
Log.i(TAG, "onPlaybackStateChanged 2: " + playbackState);
|
Log.i(TAG, "onPlaybackStateChanged 2: " + playbackState);
|
||||||
if (playbackState == Player.STATE_READY) {
|
if (playbackState == Player.STATE_READY && !player2.isPlaying()) {
|
||||||
player1.stop();
|
player1.stop();
|
||||||
player1.clearVideoSurface();
|
player1.clearVideoSurface();
|
||||||
player2.play();
|
player2.play();
|
||||||
@ -235,6 +245,14 @@ public class LiveExoPlayerManager {
|
|||||||
Player.Listener.super.onIsLoadingChanged(isLoading);
|
Player.Listener.super.onIsLoadingChanged(isLoading);
|
||||||
Log.i(TAG, "onIsLoadingChanged: 2 " + isLoading);
|
Log.i(TAG, "onIsLoadingChanged: 2 " + isLoading);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void onPlayerError(@NonNull PlaybackException error) {
|
||||||
|
Player.Listener.super.onPlayerError(error);
|
||||||
|
error.printStackTrace();
|
||||||
|
String url=LiveExoPlayerManager.this.url;
|
||||||
|
LiveExoPlayerManager.this.url=null;
|
||||||
|
startUrl(url);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +262,7 @@ public class LiveExoPlayerManager {
|
|||||||
* @param url 地址
|
* @param url 地址
|
||||||
*/
|
*/
|
||||||
public void startUrl(String url) {
|
public void startUrl(String url) {
|
||||||
if(url.equals(this.url))return;
|
if (url!=null&&url.equals(this.url)) return;
|
||||||
Log.i(TAG, "startUrl: " + url + " > " + mainView.getResizeMode());
|
Log.i(TAG, "startUrl: " + url + " > " + mainView.getResizeMode());
|
||||||
this.url = url;
|
this.url = url;
|
||||||
isSwitchUrl = true;
|
isSwitchUrl = true;
|
||||||
@ -265,8 +283,8 @@ public class LiveExoPlayerManager {
|
|||||||
* @param url 地址
|
* @param url 地址
|
||||||
*/
|
*/
|
||||||
public void switchUrl(String url) {
|
public void switchUrl(String url) {
|
||||||
if(url.equals(this.url))return;
|
if (url!=null&&url.equals(this.url)) return;
|
||||||
Log.i(TAG, "switchUrl: " + url +" src : "+this.url);
|
Log.i(TAG, "switchUrl: " + url + " src : " + this.url);
|
||||||
this.url = url;
|
this.url = url;
|
||||||
playBufferIndex = 0;
|
playBufferIndex = 0;
|
||||||
isSwitchUrl = true;
|
isSwitchUrl = true;
|
||||||
@ -316,7 +334,10 @@ public class LiveExoPlayerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clearFrame() {
|
public void clearFrame() {
|
||||||
//mainView.setKeepContentOnPlayerReset(false);
|
mainView.setKeepContentOnPlayerReset(false);
|
||||||
|
if (mainView.getVideoSurfaceView() != null) {
|
||||||
|
mainView.setPlayer(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -370,6 +370,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearFrame() {
|
||||||
|
super.clearFrame();
|
||||||
|
mPlayer.clearFrame();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void release() {
|
public void release() {
|
||||||
mEnd = true;
|
mEnd = true;
|
||||||
|
@ -97,6 +97,9 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL
|
|||||||
public void switchStreamPk(boolean isPk) {
|
public void switchStreamPk(boolean isPk) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearFrame() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface OnMicCallback {
|
public interface OnMicCallback {
|
||||||
void onMikUpdate();
|
void onMikUpdate();
|
||||||
|
@ -244,12 +244,19 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
|
|||||||
mViewPager.setCanScroll(true);
|
mViewPager.setCanScroll(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
final Runnable loadRunnableGone = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
loading.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk) {
|
public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk) {
|
||||||
isEnterRoom = false;
|
isEnterRoom = false;
|
||||||
openParametersModel = new OpenParametersModel();
|
openParametersModel = new OpenParametersModel();
|
||||||
mContext.runOnUiThread(new Runnable() {
|
mContext.runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.e("ImgLoader1", data.getAvatar());
|
Log.e("ImgLoader1", data.getAvatar());
|
||||||
@ -264,9 +271,11 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
|
|||||||
.setmLiveType(mLiveType)
|
.setmLiveType(mLiveType)
|
||||||
.setmLiveTypeVal(mLiveTypeVal)));
|
.setmLiveTypeVal(mLiveTypeVal)));
|
||||||
loading.setVisibility(View.VISIBLE);
|
loading.setVisibility(View.VISIBLE);
|
||||||
|
loading.setAlpha(0.6f);
|
||||||
ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), ivBg);
|
ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), ivBg);
|
||||||
AnimationDrawable frameAnimation = (AnimationDrawable) ivLoading.getBackground();
|
AnimationDrawable frameAnimation = (AnimationDrawable) ivLoading.getBackground();
|
||||||
frameAnimation.start();
|
frameAnimation.start();
|
||||||
|
liveHandler.removeCallbacks(loadRunnableGone);
|
||||||
if (mLivePlayViewHolder == null) {
|
if (mLivePlayViewHolder == null) {
|
||||||
mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1);
|
mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1);
|
||||||
mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager());
|
mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager());
|
||||||
@ -279,7 +288,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
|
|||||||
mLivePlayViewHolder.setLoadViewListener(new LiveRoomPlayViewHolder.LoadingListener() {
|
mLivePlayViewHolder.setLoadViewListener(new LiveRoomPlayViewHolder.LoadingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPlayer() {
|
public void onPlayer() {
|
||||||
liveHandler.postDelayed(()->loading.setVisibility(View.GONE),200);
|
liveHandler.postDelayed(loadRunnableGone, 350);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mLiveRoomViewHolder.subscribeActivityLifeCycle();
|
mLiveRoomViewHolder.subscribeActivityLifeCycle();
|
||||||
@ -291,7 +300,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
|
|||||||
mLiveLinkMicPresenter.setLiveSdk(mLiveSDK);
|
mLiveLinkMicPresenter.setLiveSdk(mLiveSDK);
|
||||||
mLiveLinkMicAnchorPresenter.setLiveSdk(mLiveSDK);
|
mLiveLinkMicAnchorPresenter.setLiveSdk(mLiveSDK);
|
||||||
}
|
}
|
||||||
if (mLiveRyLinkMicPkPresenter==null){
|
if (mLiveRyLinkMicPkPresenter == null) {
|
||||||
mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null);
|
mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null);
|
||||||
}
|
}
|
||||||
//去除主播离开画面
|
//去除主播离开画面
|
||||||
@ -367,6 +376,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.clearFrame();
|
||||||
int userClarityType = IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, -1);
|
int userClarityType = IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, -1);
|
||||||
int anchorClarityType = data.getClarityType() - 1;
|
int anchorClarityType = data.getClarityType() - 1;
|
||||||
if (userClarityType != anchorClarityType) {
|
if (userClarityType != anchorClarityType) {
|
||||||
@ -596,7 +606,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
|
|||||||
mLiveRoomViewHolder.showPrizePoolLevel(String.valueOf(giftPrizePoolLevel));
|
mLiveRoomViewHolder.showPrizePoolLevel(String.valueOf(giftPrizePoolLevel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
liveHandler.postDelayed(() -> loading.setVisibility(View.GONE), 10_000);
|
liveHandler.postDelayed(loadRunnableGone, 10_000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1794,6 +1804,15 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 幸运100%活动
|
||||||
|
*/
|
||||||
|
public void lucky100(MsgModel model){
|
||||||
|
if (mLiveRoomViewHolder != null) {
|
||||||
|
mLiveRoomViewHolder.lucky100(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void messageBottom() {
|
public void messageBottom() {
|
||||||
if (mLiveRoomViewHolder != null) {
|
if (mLiveRoomViewHolder != null) {
|
||||||
mLiveRoomViewHolder.chatScrollToBottom();
|
mLiveRoomViewHolder.chatScrollToBottom();
|
||||||
|
Loading…
Reference in New Issue
Block a user