修复通过【为你推荐】方式进入直播间会有上个直播间残留画面的问题

This commit is contained in:
zlzw 2023-01-15 09:56:51 +08:00
parent 543336af99
commit 911869ed9f
3 changed files with 56 additions and 10 deletions

View File

@ -4,6 +4,8 @@ import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
@ -25,8 +27,8 @@ import com.google.android.exoplayer2.video.VideoSize;
public class LiveExoPlayerManager {
private final int MODEL_PLAY1 = 0;//当前主播放器
private final int MODEL_PLAY2 = 1;//当前子播放器
private final ExoPlayer player1;
private final ExoPlayer player2;
private ExoPlayer player1;
private ExoPlayer player2;
private StyledPlayerView mainView;//渲染视图
private int status = MODEL_PLAY1;
private Player.Listener listener;
@ -324,14 +326,19 @@ public class LiveExoPlayerManager {
* 是否正在播放
*/
public boolean isPlaying() {
return getNowPlayer().isPlaying();
if (getNowPlayer() != null) {
return getNowPlayer().isPlaying();
}
return false;
}
/**
* 停止播放
*/
public void stop() {
getNowPlayer().stop();
if (getNowPlayer() != null) {
getNowPlayer().stop();
}
clearUrl();
}
@ -344,8 +351,12 @@ public class LiveExoPlayerManager {
public void replay() {
Log.i(TAG, "replay: 重载播放");
getNowPlayer().stop();
getNextPlayer().stop();
if (getNowPlayer() != null) {
getNowPlayer().stop();
}
if (getNextPlayer() != null) {
getNextPlayer().stop();
}
String tmp = url;
url = null;
startUrl(tmp);
@ -363,8 +374,23 @@ public class LiveExoPlayerManager {
*/
public void release() {
Log.i(TAG, "release: 释放播放器");
player1.release();
player2.release();
if (player1 != null) {
player1.clearVideoSurface();
player1.release();
}
if (player2 != null) {
player2.clearVideoSurface();
player2.release();
}
player1 = null;
player2 = null;
mainView.setKeepContentOnPlayerReset(false);
mainView.setPlayer(null);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mainView.getLayoutParams();
layoutParams.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
mainView.setLayoutParams(layoutParams);
mainView.removeAllViews();
mainView.requestLayout();
handler.removeCallbacks(buffRunnable);
}

View File

@ -103,8 +103,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
private boolean mPausedPlay;//是否被动暂停了播放
public int landscape; //1h 2s
public static Context contexts;
public static FrameLayout ry_view;
public Context contexts;
public FrameLayout ry_view;
private static final int VIDEO_VERTICAL = 2;
private static final int VIDEO_HORIZONTAL = 1;
@ -138,6 +138,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
@Override
public void init() {
Log.i(TAG, "init: 初始化播放器ViewHolder");
EventBus.getDefault().register(this);
Bus.getOn(this);
mRoot = (ViewGroup) findViewById(R.id.root);
@ -376,6 +377,24 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public void clearFrame() {
super.clearFrame();
mPlayer.clearFrame();
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
params.addRule(RelativeLayout.ALIGN_TOP);
mVideoView.setLayoutParams(params);
mVideoView.requestLayout();
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) ry_view.getLayoutParams();
params1.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params1.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
params1.addRule(RelativeLayout.ALIGN_TOP);
ry_view.setLayoutParams(params1);
ry_view.requestLayout();
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCover.getLayoutParams();
params2.height = DpUtil.dp2px(270);
params2.topMargin = DpUtil.dp2px(120);
mCover.setLayoutParams(params2);
mCover.requestLayout();
}
@Override

View File

@ -314,6 +314,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), liveBack, 400, 600);
mask.setVisibility(View.VISIBLE);
mLivePlayViewHolder.clearFrame();
mLivePlayViewHolder.setLiveBean(mLiveBean);
mLivePlayViewHolder.setCover(mLiveBean.getAvatar());
mLivePlayViewHolder.setLiveBeanLandscape(mLiveBean.getLandscape());