优化麦圈,泄漏处理

This commit is contained in:
2025-12-24 18:33:06 +08:00
parent 342cfd347c
commit 84fb05044a
11 changed files with 168 additions and 197 deletions

View File

@@ -262,99 +262,16 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
AgoraManager.getInstance().addSoundLevelListener(new SoundLevelUpdateListener() {
@Override
public void onRemoteSoundLevelUpdate(String userId, int soundLevel) {
if (mIvRipple == null)
return;
if (mIvRipple == null) return;
if (!userId.equals(pitBean.getUser_id())) return;
if (userId.equals(pitBean.getUser_id())) {
if (soundLevel == 0) {
mIvRipple.pauseAnimation();
CommonAppContext.getInstance().onlineMap.put(pitBean.getUser_id(), 1);
mIvRipple.setVisibility(INVISIBLE);
} else {
mIvRipple.setVisibility(VISIBLE);
mIvRipple.post(() -> {
if (!mIvRipple.isAnimating()) {
if (pitBean.getMic_cycle() != null && !pitBean.getMic_cycle().isEmpty()) {
if (mParser != null) {
mIvRipple.startAnimation();
} else {
mParser = new SVGAParser(getContext());
try {
mParser.decodeFromURL(new URL(pitBean.getMic_cycle()), new SVGAParser.ParseCompletion() {
@Override
public void onError() {
}
@Override
public void onComplete(@NotNull SVGAVideoEntity svgaVideoEntity) {
if (mIvRipple == null)
return;
SVGADrawable drawable = new SVGADrawable(svgaVideoEntity);
mIvRipple.setImageDrawable(drawable);
mIvRipple.startAnimation();
}
});
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
} else {
mIvRipple.startAnimation();
}
CommonAppContext.getInstance().onlineMap.put(pitBean.getUser_id(), 1);
iv_on_line.setVisibility(GONE);
}
});
}
}
boolean nowSpeaking = soundLevel > 0;
updateSpeakingState(nowSpeaking);
}
@Override
public void onLocalSoundLevelUpdate(int volume) {
if (mIvRipple == null)
return;
if (volume == 0) {
mIvRipple.setVisibility(GONE);
} else {
mIvRipple.setVisibility(VISIBLE);
if (!mIvRipple.isAnimating()) {
if (pitBean.getMic_cycle()!=null && !pitBean.getMic_cycle().isEmpty()) {
if (mParser != null) {
mIvRipple.startAnimation();
} else {
mParser = new SVGAParser(getContext());
try {
mParser.decodeFromURL(new URL(pitBean.getMic_cycle()), new SVGAParser.ParseCompletion() {
@Override
public void onError() {
}
@Override
public void onComplete(@NotNull SVGAVideoEntity svgaVideoEntity) {
if (mIvRipple == null)
return;
SVGADrawable drawable = new SVGADrawable(svgaVideoEntity);
mIvRipple.setImageDrawable(drawable);
mIvRipple.startAnimation();
}
});
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}else {
mIvRipple.startAnimation();
}
CommonAppContext.getInstance().onlineMap.put(pitBean.getUser_id(), 1);
iv_on_line.setVisibility(GONE);
}
}
}
@Override
@@ -379,6 +296,59 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
}
private boolean isSpeaking = false;
private void updateSpeakingState(boolean nowSpeaking) {
// 1⃣ 状态未变化,直接丢弃(核心)
if (nowSpeaking == isSpeaking) return;
isSpeaking = nowSpeaking;
if (!nowSpeaking) {
// 静音状态
mIvRipple.pauseAnimation();
mIvRipple.setVisibility(INVISIBLE);
return;
}
// 2⃣ 开始说话(只触发一次)
mIvRipple.setVisibility(VISIBLE);
iv_on_line.setVisibility(GONE);
CommonAppContext.getInstance().onlineMap.put(pitBean.getUser_id(), 1);
if (!mIvRipple.isAnimating()) {
startRippleAnimation();
}
}
private void startRippleAnimation() {
if (mParser != null) {
mIvRipple.startAnimation();
return;
}
if (pitBean.getMic_cycle() == null || pitBean.getMic_cycle().isEmpty()) {
mIvRipple.startAnimation();
return;
}
try {
mParser = new SVGAParser(getContext());
mParser.decodeFromURL(new URL(pitBean.getMic_cycle()),
new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@NotNull SVGAVideoEntity svgaVideoEntity) {
if (mIvRipple == null) return;
mIvRipple.setImageDrawable(new SVGADrawable(svgaVideoEntity));
mIvRipple.startAnimation();
}
@Override
public void onError() {}
});
} catch (MalformedURLException ignored) {}
}
public void setCharm(String charm) {
mCharmView.setSex(pitBean.getSex(), pitBean.getUser_id(), charm, false);
}