直播间内存优化稳定到0.7G左右

This commit is contained in:
zlzw 2022-10-31 16:41:28 +08:00
parent 50f83939cc
commit 7e169e882d
4 changed files with 65 additions and 52 deletions

View File

@ -27,6 +27,6 @@ ext {
// true表示谷歌支付 false
isGooglePlay : true,
//
isUploadLog : true
isUploadLog : false
]
}

View File

@ -196,7 +196,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public void play(String url) {
Log.e("purl121", url);
if (TextUtils.isEmpty(url) || mVideoView == null || true) {
if (TextUtils.isEmpty(url) || mVideoView == null) {
return;
}
@ -207,7 +207,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
//mPlayer.setCacheParams(1.0f, 5.0f);
if(mPlayer.isPlaying()){
mPlayer.stop();
mPlayer.release();
}
purl = url;
MediaItem item = MediaItem.fromUri(url);
@ -240,7 +239,6 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
}
if (mPlayer != null) {
mPlayer.stop();
mPlayer.release();
}
stopPlay2();
}

View File

@ -1051,7 +1051,11 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
}
});
}
public void clearChat(){
if(mLiveChatAdapter!=null){
mLiveChatAdapter.clear();
}
}
public synchronized void showStart(StarChallengeStatusModel data) {
boolean upData = false;
if (mBannerList2 != null && mBannerList2.size() == 0) {

View File

@ -11,6 +11,7 @@ import android.content.Intent;
import android.content.res.Configuration;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@ -220,7 +221,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
liveBack = mRootContainer.findViewById(R.id.live_back);
mask = mRootContainer.findViewById(R.id.mask);
}
private static boolean test=true;
@Override
public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk) {
openParametersModel = new OpenParametersModel();
@ -238,7 +239,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
.setParametersModel(openParametersModel
.setmLiveType(mLiveType)
.setmLiveTypeVal(mLiveTypeVal)));
if (mLivePlayViewHolder == null) {
if (mLivePlayViewHolder == null && test) {
test=false;
mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, mIntent.getIntExtra("landscape", 0));
mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager());
mLiveAudienceViewHolder = new LiveAudienceViewHolder(mContext, mContainer);
@ -251,27 +253,30 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
mLiveAudienceViewHolder.addToParent();
mLiveRoomViewHolder.addToParent();
mLiveAudienceViewHolder.subscribeActivityLifeCycle();
mSocketRyClient = new SocketRyClient(mLiveBean.getUid(), PortraitLiveManager.this);
}
if(true) {
//直播间背景
ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), liveBack, 400, 600);
//ImageLoadUtils.loadUrlToBlur(mContext,mLiveBean.getAvatar(),400,600,liveBack);
mask.setVisibility(View.VISIBLE);
mLivePlayViewHolder.setCover(data.getThumb());
mLivePlayViewHolder.play(data.getPull());
mLiveRoomViewHolder.clearChat();
mLiveRoomViewHolder.setAvatar(data.getAvatar());
mLiveRoomViewHolder.setAnchorLevel(data.getLevelAnchor());
mLiveRoomViewHolder.setName(data.getUserNiceName());
mLiveRoomViewHolder.setRoomNum(data.getLiangNameTip());
mLiveRoomViewHolder.setTitle(data.getTitle());
//直播间背景
ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), liveBack, 400, 600);
//ImageLoadUtils.loadUrlToBlur(mContext,mLiveBean.getAvatar(),400,600,liveBack);
mask.setVisibility(View.VISIBLE);
mLivePlayViewHolder.setCover(data.getThumb());
mLivePlayViewHolder.play(data.getPull());
mLiveRoomViewHolder.setAvatar(data.getAvatar());
mLiveRoomViewHolder.setAnchorLevel(data.getLevelAnchor());
mLiveRoomViewHolder.setName(data.getUserNiceName());
mLiveRoomViewHolder.setRoomNum(data.getLiangNameTip());
mLiveRoomViewHolder.setTitle(data.getTitle());
mLiveRyLinkMicPkPresenter.setLiveUid(data.getUid(), "");
mLiveRyLinkMicPkPresenter.setLiveUid(data.getUid(), "");
mLiveRoomViewHolder.setLiveUid(data.getUid());
mLiveRoomViewHolder.setLiveUid(data.getUid());
mSocketRyClient = new SocketRyClient(mLiveBean.getUid(), PortraitLiveManager.this);
if (mLiveLinkMicPresenter != null) {
mLiveLinkMicPresenter.setSocketClient(mSocketClient);
mSocketRyClient = new SocketRyClient(mLiveBean.getUid(), PortraitLiveManager.this);
if (mLiveLinkMicPresenter != null) {
mLiveLinkMicPresenter.setSocketClient(mSocketClient);
}
}
//心愿单
LiveHttpUtil.getWishList(mLiveBean.getUid(), new HttpCallback() {
@ -299,8 +304,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
}
});
enterRoom();
mLiveRoomViewHolder.initHourRankList();
mLiveRoomViewHolder.showLiveRoomActivityBanner();
if(true) {
mLiveRoomViewHolder.initHourRankList();
mLiveRoomViewHolder.showLiveRoomActivityBanner();
}
}
});
@ -316,43 +323,20 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
IMLoginManager.get(mContext).setisNewUserOne(false);
//子线程执行退出操作
exitLiveRoom();
if (mLiveAudienceViewHolder != null) {
mLiveAudienceViewHolder.removeFromParent();
mLiveAudienceViewHolder.removeCallbacks();
mLiveAudienceViewHolder.release();
}
mLiveAudienceViewHolder = null;
//断开socket
if (mSocketRyClient != null) {
mSocketRyClient.disConnect();
mSocketRyClient = null;
}
mSocketRyClient = null;
//结束播放
if (mLivePlayViewHolder != null) {
mLivePlayViewHolder.removeFromParent();
mLivePlayViewHolder.stopPlay();
mLivePlayViewHolder.release();
}
mLivePlayViewHolder = null;
if (mSocketClient != null) {
mSocketClient.disConnect();
mSocketClient = null;
}
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.removeFromParent();
mLiveRoomViewHolder.clearData();
mLiveRoomViewHolder.countDownTimerTrickery = null;
mLiveRoomViewHolder = null;
}
if (mLiveEndViewHolder != null) {
mLiveEndViewHolder.removeFromParent();
mLiveEndViewHolder.release();
mLiveEndViewHolder = null;
}
if (mLiveLinkMicPresenter != null) {
mLiveLinkMicPresenter.clearData();
mLiveLinkMicPresenter.release();
@ -367,6 +351,33 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
}
if (isQuit) {
isQuitF = true;
if (mLiveAudienceViewHolder != null) {
mLiveAudienceViewHolder.removeFromParent();
mLiveAudienceViewHolder.removeCallbacks();
mLiveAudienceViewHolder.release();
}
//结束播放
if (mLivePlayViewHolder != null) {
mLivePlayViewHolder.removeFromParent();
mLivePlayViewHolder.stopPlay();
mLivePlayViewHolder.release();
}
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.removeFromParent();
mLiveRoomViewHolder.clearData();
mLiveRoomViewHolder.countDownTimerTrickery = null;
}
if (mLiveEndViewHolder != null) {
mLiveEndViewHolder.removeFromParent();
mLiveEndViewHolder.release();
}
mLiveAudienceViewHolder = null;
mLivePlayViewHolder = null;
mLiveRoomViewHolder = null;
mLiveEndViewHolder = null;
mLiveLinkMicPresenter=null;
mLiveLinkMicAnchorPresenter=null;
mLiveRyLinkMicPkPresenter=null;
if (PermissionUtils.checkPermission(mContext)) {
LiveFloatView.getInstance()
.cacheLiveData(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal)