1.修改播放礼物特效代码

2:修改从房间进入其他页面出现不能回到房间的问题
This commit is contained in:
2025-09-12 09:08:14 +08:00
parent 1157e8a545
commit 748912d3d1
19 changed files with 1056 additions and 367 deletions

View File

@@ -91,6 +91,23 @@ public class CommonAppContext extends MultiDexApplication {
private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
private ScheduledExecutorService scheduledExecutorServiceRoom = null;
private MqttConnect mqttConnect=null;
// 添加后台状态标记
private boolean wasInBackground = false;
public void onAppBackground() {
wasInBackground = true;
}
public void onAppForeground() {
wasInBackground = false;
}
public boolean wasInBackground() {
return wasInBackground;
}
@Override
public void onCreate() {
super.onCreate();

View File

@@ -24,4 +24,5 @@ public class GiftBean {
private int count;
private String user_id;
private int num;
private boolean is_paly =false;
}

View File

@@ -158,11 +158,11 @@ public class EMMessageInfo implements MultiItemEntity {
case QXRoomMessageTypeRoomDress:
case QXRoomMessageTypeRoomOnline:
case QXRoomMessageTypeRoomOPK:
case QXRoomMessageTypeRoomOMh:
case QXRoomMessageTypeRoomFriendPartDidChanged:
case QXRoomMessageTypeSeatDidChanged:
case QXRoomMessageTypehm:
return 1;
case QXRoomMessageTypeRoomOMh:
case QXRoomMessageTypeGift:
return 3;
case 1:

View File

@@ -322,7 +322,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
isDrawing = true;
// init(2);
startType = 2;
MvpPre.drawGiftList(giftBagId, userIds, roomId, "10",heart_id);
MvpPre.drawGiftList(giftBagId, userIds, roomId, "6",heart_id);
} else {
com.hjq.toast.ToastUtils.show("正在抽奖中...");
@@ -332,7 +332,7 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
isDrawing = true;
// init(3);
startType = 3;
MvpPre.drawGiftList(giftBagId, userIds, roomId, "100",heart_id);
MvpPre.drawGiftList(giftBagId, userIds, roomId, "9",heart_id);
} else {
com.hjq.toast.ToastUtils.show("正在抽奖中...");
}
@@ -390,16 +390,16 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
if (icon > 0 && box_price > 0) {
if (type == 10) {
updateBackground(mBinding.mirroeSky.llOne, icon > box_price, drawableX, drawableW);
updateBackground(mBinding.mirroeSky.llTen, icon > box_price * 10, drawableX, drawableW);
updateBackground(mBinding.mirroeSky.llHundred, icon > box_price * 100, drawableX, drawableW);
updateBackground(mBinding.mirroeSky.llTen, icon > box_price * 6, drawableX, drawableW);
updateBackground(mBinding.mirroeSky.llHundred, icon > box_price * 9, drawableX, drawableW);
} else if (type == 11) {
updateBackground(mBinding.cityTime.llOne, icon > box_price, drawableX, drawableW);
updateBackground(mBinding.cityTime.llTen, icon > box_price * 10, drawableX, drawableW);
updateBackground(mBinding.cityTime.llHundred, icon > box_price * 100, drawableX, drawableW);
updateBackground(mBinding.cityTime.llTen, icon > box_price * 6, drawableX, drawableW);
updateBackground(mBinding.cityTime.llHundred, icon > box_price * 9, drawableX, drawableW);
} else if (type == 12) {
updateBackground(mBinding.pinnacleTime.llOne, icon > box_price, drawableX, drawableW);
updateBackground(mBinding.pinnacleTime.llTen, icon > box_price * 10, drawableX, drawableW);
updateBackground(mBinding.pinnacleTime.llHundred, icon > box_price * 100, drawableX, drawableW);
updateBackground(mBinding.pinnacleTime.llTen, icon > box_price * 6, drawableX, drawableW);
updateBackground(mBinding.pinnacleTime.llHundred, icon > box_price * 9, drawableX, drawableW);
} else {
// 兜底处理:未知 type 时全部设为不可点击 + 默认背景
setAllBackgroundToDefault(drawableW);
@@ -725,17 +725,17 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
private void upTitle(int boxPrice) {
if (type == 10) {
mBinding.mirroeSky.oneTitle.setText(boxPrice + "币一次");
mBinding.mirroeSky.tenTitle.setText((boxPrice * 10) + "");
mBinding.mirroeSky.hundredTitle.setText((boxPrice * 100) + "");
mBinding.mirroeSky.tenTitle.setText((boxPrice * 6) + "");
mBinding.mirroeSky.hundredTitle.setText((boxPrice * 9) + "");
} else if (type == 11) {
mBinding.cityTime.oneTitle.setText(boxPrice + "币一次");
mBinding.cityTime.tenTitle.setText((boxPrice * 10) + "");
mBinding.cityTime.hundredTitle.setText((boxPrice * 100) + "");
mBinding.cityTime.tenTitle.setText((boxPrice * 6) + "");
mBinding.cityTime.hundredTitle.setText((boxPrice * 9) + "");
} else if (type == 12) {
mBinding.pinnacleTime.oneTitle.setText(boxPrice + "币一次");
mBinding.pinnacleTime.tenTitle.setText((boxPrice * 10) + "");
mBinding.pinnacleTime.hundredTitle.setText((boxPrice * 100) + "");
mBinding.pinnacleTime.tenTitle.setText((boxPrice * 6) + "");
mBinding.pinnacleTime.hundredTitle.setText((boxPrice * 9) + "");
}
}

View File

@@ -38,19 +38,24 @@ import com.opensource.svgaplayer.SVGADynamicEntity;
import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity;
import com.tencent.imsdk.v2.V2TIMSimpleMsgListener;
import com.tencent.qgame.animplayer.AnimConfig;
import com.tencent.qgame.animplayer.inter.IAnimListener;
import com.tencent.qgame.animplayer.inter.IFetchResource;
import com.xscm.moduleutil.R;
import com.xscm.moduleutil.bean.GiftAvatarBean;
import com.xscm.moduleutil.databinding.RoomViewSvgaAnimBinding;
import com.xscm.moduleutil.utils.Md5Utils;
import com.xscm.moduleutil.utils.MemoryOptimizationUtils;
import com.xscm.moduleutil.utils.SpUtil;
import com.xscm.moduleutil.utils.logger.Logger;
import org.greenrobot.eventbus.EventBus;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.util.HashMap;
@@ -73,7 +78,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
@Override
public void onFailed(int i, @Nullable String s) {
LogUtils.e("@@@@" + "onFailed");
}
@Override
@@ -83,12 +88,11 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
@Override
public void onVideoStart() {
LogUtils.e("@@@@" + "onVideoStart");
}
@Override
public void onVideoRender(int i, @Nullable AnimConfig animConfig) {
}
@Override
@@ -102,15 +106,17 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
// if (isDestroyed) return;
// 确保在主线程中执行
if (Looper.myLooper() == Looper.getMainLooper()) {
handleVideoComplete();
} else {
mainHandler.post(() -> {
// if (!isDestroyed) {
handleVideoComplete();
// }
});
}
// EventBus.getDefault().post(new GiftAvatarBean());
LogUtils.e("@@@@" + "EventBus onVideoComplete");
// if (Looper.myLooper() == Looper.getMainLooper()) {
// handleVideoComplete();
// } else {
// mainHandler.post(() -> {
//// if (!isDestroyed) {
// handleVideoComplete();
//// }
// });
// }
}
private void handleVideoComplete() {
@@ -209,6 +215,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
super(context, attrs, defStyleAttr);
mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.room_view_svga_anim, this, true);
initViews();
}
private void initViews() {
@@ -231,9 +238,49 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
// 初始化播放管理器
playbackManager = new PlaybackManager(mainHandler);
if (mBinding != null) {
mBinding.playView.setAnimListener(this);
}
// 获取 MP4PlaybackCallback 单例实例并设置引用
MP4PlaybackCallback callback = MP4PlaybackCallback.getInstance();
callback.setAvatarFrameView(this);
// 设置播放完成监听
mBinding.playView.setAnimListener(callback);
// if (mBinding != null) {
// mBinding.playView.setAnimListener(this);
// }
// MP4PlaybackCallback = new IAnimListener() {
// @Override
// public boolean onVideoConfigReady(@NonNull AnimConfig animConfig) {
// return false;
// }
//
// @Override
// public void onVideoStart() {
//
// }
//
// @Override
// public void onVideoRender(int i, @Nullable AnimConfig animConfig) {
//
// }
//
// @Override
// public void onVideoComplete() {
// onPlaybackComplete();
// }
//
// @Override
// public void onVideoDestroy() {
//
// }
//
// @Override
// public void onFailed(int i, @Nullable String s) {
// onPlaybackComplete();
// }
// };
// // 设置播放完成监听
// mBinding.playView.setAnimListener(MP4PlaybackCallback);
}
private String getFileExtension(String url) {
@@ -264,11 +311,6 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
return;
}
// 关键:即使 isPlaying 为 true也要检查实际播放状态
// if (isPlaying && isActuallyPlaying()) {
// Logger.d("AvatarFrameView", "Already playing, skip");
// return;
// }
PlayItem item = playQueue.poll();
if (item != null) {
// 通知开始播放
@@ -278,42 +320,12 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
// 处理播放项目
processPlayItem(item);
// isPlaying = true;
// Logger.d("AvatarFrameView", "Playing item, remaining queue size: " + playQueue.size());
// RenderType type = null;
// String ext = getFileExtension(item.url);
// if ("svga".equalsIgnoreCase(ext)) {
// type = RenderType.SVGA;
// } else if ("mp4".equalsIgnoreCase(ext)) {
// type = RenderType.MP4;
// }
//
// if (type == null) {
// isPlaying = false;
// playNextFromQueue(); // 跳过无效项
// return;
// }
//
// clearPrevious();
// renderType = type;
// mType = item.type;
//
// switch (type) {
// case SVGA:
// mBinding.playView.stopPlay();
// mBinding.playView.setVisibility(View.GONE);
// loadSVGA(item.url);
// break;
// case MP4:
// mBinding.playView.setVisibility(View.VISIBLE);
// downloadAndPlayMp4(item.url);
// break;
// }
} else {
isPlaying = false;
Logger.d("AvatarFrameView", "Queue is empty, stop playing");
}
}
// 添加统一的播放完成处理方法
private void onPlaybackComplete() {
mainHandler.post(() -> {
@@ -329,7 +341,6 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
if (playQueue.size() % 5 == 0) {
performLightMemoryCleanup();
}
// 继续处理队列中的下一个项目
playNextFromQueue();
});
@@ -400,10 +411,10 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
playQueue.add(new PlayItem(url, type2));
Logger.d("AvatarFrameView", "Added to queue, queue size: " + playQueue.size() + ", url: " + url);
if (type2==3){
if (type2 == 3) {
// playNextFromQueue();
loadSVGA(url);
}else {
} else {
// 如果当前没有在播放,则开始播放
if (!isPlaying || !isActuallyPlaying()) {
@@ -492,14 +503,17 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
boolean isTxk = false;
private void downloadAndPlayMp4(String url) {
public void downloadAndPlayMp4(String url) {
// 提取文件名
String fileName = url.substring(url.lastIndexOf("/"));
String filePath = getContext().getCacheDir().getAbsolutePath() + fileName;
LogUtils.e("@@@@@filePath: " + filePath.toString());
File file = new File(filePath);
if (!file.exists()) {
LogUtils.e("无缓存");
// 使用OkHttp进行下载
OkHttpClient client = new OkHttpClient();
@@ -514,25 +528,43 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
onPlaybackComplete();
}
// 更简单的优化版本
@Override
public void onResponse(Call call, Response response) throws IOException {
LogUtils.d("@@@@", "onResponse" + Thread.currentThread().getName());
if (response.isSuccessful()) {
// 保存文件到缓存目录
try (ResponseBody responseBody = response.body()) {
if (responseBody != null) {
// 在后台线程处理文件保存
String fileName = url.substring(url.lastIndexOf("/"));
String filePath = getContext().getCacheDir().getAbsolutePath() + fileName;
File downloadedFile = new File(filePath);
FileOutputStream fos = new FileOutputStream(downloadedFile);
fos.write(responseBody.bytes());
fos.close();
isTxk = true;
// 在主线程中播放动画
mainHandler.post(() -> {
playMp4File(downloadedFile);
// if (isTxk) {
// mBinding.playView.setLoop(1);
// }
mBinding.playView.startPlay(downloadedFile);
});
// 使用流式传输避免大文件卡顿
try (InputStream inputStream = responseBody.byteStream();
FileOutputStream fos = new FileOutputStream(downloadedFile)) {
// 定义缓冲区大小8KB
byte[] buffer = new byte[1024 * 1024];
int bytesRead;
// 流式读取并写入文件
while ((bytesRead = inputStream.read(buffer)) != -1) {
fos.write(buffer, 0, bytesRead);
}
fos.flush();
isTxk = true;
mainHandler.post(() -> {
LogUtils.d("@@@@Thread", Thread.currentThread().getName());
playMp4File(file);
});
} catch (IOException e) {
LogUtils.e("MP4文件保存失败: " + e.getMessage());
}
} else {
mainHandler.post(() -> onPlaybackComplete());
}
@@ -540,7 +572,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
LogUtils.e("MP4文件保存失败: " + e.getMessage());
mainHandler.post(() -> onPlaybackComplete());
}
}else {
} else {
LogUtils.e("MP4下载响应失败");
mainHandler.post(() -> onPlaybackComplete());
}
@@ -561,9 +593,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
private void playMp4File(File file) {
try {
if (mBinding != null && file != null && file.exists()) {
// 设置播放完成监听
mBinding.playView.setAnimListener(new MP4PlaybackCallback());
// mBinding.playView.setAnimListener(new MP4PlaybackCallback());
// 设置循环次数根据mType决定
if (mType == 1) {
mBinding.playView.setLoop(0); // 无限循环
@@ -766,7 +796,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
}
});
// 设置循环次数
if (mType == 1|| mType == 3) {
if (mType == 1 || mType == 3) {
svgaSurface.setLoops(0); // 无限循环
} else {
svgaSurface.setLoops(1); // 播放一次
@@ -819,7 +849,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
}
});
// 设置循环次数
if (mType == 1|| mType == 3) {
if (mType == 1 || mType == 3) {
svgaSurface.setLoops(0); // 无限循环
} else {
svgaSurface.setLoops(1); // 播放一次
@@ -1233,6 +1263,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
// 清理当前正在播放的内容
clearPrevious();
}
// 在类成员变量中添加
private static final int PLAYBACK_TIMEOUT = 10000; // 10秒超时
private Map<String, Long> playbackStartTimeMap = new HashMap<>();
@@ -1375,12 +1406,40 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
}
// 在 AvatarFrameView 类中添加以下代码
// MP4播放完成监听器
private class MP4PlaybackCallback implements IAnimListener {
// private IAnimListener MP4PlaybackCallback;
// 在 AvatarFrameView 类的成员变量区域添加单例实例
private static volatile MP4PlaybackCallback sInstance;
private static class MP4PlaybackCallback implements IAnimListener {
private AvatarFrameView avatarFrameView;
private MP4PlaybackCallback() {
// 私有构造函数
}
// 获取单例实例的方法
public static MP4PlaybackCallback getInstance() {
if (sInstance == null) {
synchronized (MP4PlaybackCallback.class) {
if (sInstance == null) {
sInstance = new MP4PlaybackCallback();
}
}
}
return sInstance;
}
// 设置外部引用的方法
public void setAvatarFrameView(AvatarFrameView view) {
this.avatarFrameView = view;
}
@Override
public void onFailed(int i, @Nullable String s) {
LogUtils.e(TAG, "MP4 playback failed: " + s);
onPlaybackComplete();
LogUtils.e(AvatarFrameView.TAG, "MP4 playback failed: " + s);
if (avatarFrameView != null) {
avatarFrameView.onPlaybackComplete();
}
}
@Override
@@ -1400,7 +1459,9 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
@Override
public void onVideoComplete() {
onPlaybackComplete();
if (avatarFrameView != null) {
avatarFrameView.onPlaybackComplete();
}
}
@Override

View File

@@ -15,6 +15,7 @@ import com.opensource.svgaplayer.SVGAImageView;
import com.xscm.moduleutil.R;
import com.xscm.moduleutil.base.RoomRollModel;
import com.xscm.moduleutil.bean.FaceBean;
import com.xscm.moduleutil.bean.RoomMessageEvent;
import com.xscm.moduleutil.bean.UserOnlineStatusBean;
import com.xscm.moduleutil.bean.room.ClosePhone;
import com.xscm.moduleutil.bean.room.RoomClearCardiacAllModel;
@@ -272,7 +273,7 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
public void userJoined(int userId, int elapsd) {
if (pitBean != null && pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0")) {
if (pitBean.getUser_id().equals(userId + "")) {
iv_on_line.setVisibility(GONE);
// iv_on_line.setVisibility(GONE);
}
}
}
@@ -295,6 +296,19 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void subscribeMessages(RoomMessageEvent roomMessageEvent) {
if(roomMessageEvent.getMsgType()==1058){
if (roomMessageEvent.getText().getUser_id().equals(pitBean.getUser_id())){
if (roomMessageEvent.getText().getType()==1){
iv_on_line.setVisibility(GONE);
}else {
iv_on_line.setVisibility(VISIBLE);
}
}
}
}
/**
* 开始倒计时

View File

@@ -65,7 +65,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_3"
android:gravity="center"
android:text="抽次"
android:text="抽次"
android:textSize="@dimen/sp_12" />
<TextView
@@ -94,7 +94,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_3"
android:gravity="center"
android:text="抽次"
android:text="抽次"
android:textSize="@dimen/sp_12" />
<TextView

View File

@@ -68,7 +68,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_3"
android:gravity="center"
android:text="抽次"
android:text="抽次"
android:textSize="@dimen/sp_12" />
<TextView
@@ -97,7 +97,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_3"
android:gravity="center"
android:text="抽次"
android:text="抽次"
android:textSize="@dimen/sp_12" />
<TextView

View File

@@ -65,7 +65,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_3"
android:gravity="center"
android:text="抽次"
android:text="抽次"
android:textSize="@dimen/sp_12" />
<TextView
@@ -94,7 +94,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_3"
android:gravity="center"
android:text="抽次"
android:text="抽次"
android:textSize="@dimen/sp_12" />
<TextView