cpview 播放添加延迟2秒

This commit is contained in:
2025-12-04 23:11:11 +08:00
parent 532f85e9e2
commit 99dbd3d321

View File

@@ -1,5 +1,6 @@
package com.xscm.moduleutil.utils.roomview;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.AsyncTask;
import android.text.TextUtils;
@@ -41,8 +42,13 @@ import java.util.List;
import java.util.Queue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
@@ -172,7 +178,6 @@ public class RoomCPView extends FrameLayout {
avatarContainer1.setVisibility(View.VISIBLE);
// 启动头像上下浮动动画
// startAvatarFloatAnimation();
});
@@ -299,14 +304,14 @@ public class RoomCPView extends FrameLayout {
}
/**
* CP特效进来
*
* @param room_head1 头像1
* @param room_head2 头像2
* @param room_name1 名称1
* @param room_name2 名称2
* @param mp4Path MP4动画文件路径
* @param mp4Path MP4动画文件路径
*/
public void displayEffectView(String room_head1, String room_head2, String room_name1, String room_name2, String mp4Path) {
// 确保视图已初始化
@@ -330,6 +335,7 @@ public class RoomCPView extends FrameLayout {
}
queue.execute(new Runnable() {
@SuppressLint("CheckResult")
@Override
public void run() {
// 如果mp4Path不存在return
@@ -355,8 +361,14 @@ public class RoomCPView extends FrameLayout {
// 如果没有在加载则开始加载
if (!isLoadEffect) {
// 更改加载状态标记
isLoadEffect = true;
loadStartAnimation();
Observable.timer(2000, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
isLoadEffect = true;
loadStartAnimation();
}
});
}
} finally {
// 解锁
@@ -367,8 +379,6 @@ public class RoomCPView extends FrameLayout {
}
/**
* 原始的动画方法,现在只被内部调用
*/
@@ -378,7 +388,8 @@ public class RoomCPView extends FrameLayout {
fadeIn.setDuration(500);
fadeIn.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
@@ -388,7 +399,8 @@ public class RoomCPView extends FrameLayout {
fadeOut.setDuration(500);
fadeOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
@@ -398,14 +410,16 @@ public class RoomCPView extends FrameLayout {
}
@Override
public void onAnimationRepeat(Animation animation) {}
public void onAnimationRepeat(Animation animation) {
}
});
startAnimation(fadeOut);
}, 1000);
}
@Override
public void onAnimationRepeat(Animation animation) {}
public void onAnimationRepeat(Animation animation) {
}
});
startAnimation(fadeIn);
}
@@ -471,7 +485,8 @@ public class RoomCPView extends FrameLayout {
/**
* 处理MP4文件如果是网络URL则下载到本地
* @param path 文件路径或URL
*
* @param path 文件路径或URL
* @param callback 下载回调
*/
private void handleMP4File(String path, DownloadCallback callback) {
@@ -489,7 +504,8 @@ public class RoomCPView extends FrameLayout {
/**
* 下载文件到本地
* @param url 下载URL
*
* @param url 下载URL
* @param callback 下载回调
*/
private void downloadFile(String url, DownloadCallback callback) {
@@ -623,11 +639,13 @@ public class RoomCPView extends FrameLayout {
*/
private interface DownloadCallback {
void onSuccess(String localPath);
void onError(String error);
}
/**
* 获取文件扩展名
*
* @param url 文件URL
* @return 文件扩展名
*/
@@ -713,7 +731,8 @@ public class RoomCPView extends FrameLayout {
}
@Override
public void onAnimationRepeat(Animation animation) {}
public void onAnimationRepeat(Animation animation) {
}
});
avatarsParentContainer.startAnimation(bottomUpAnimation);
}
@@ -765,6 +784,7 @@ public class RoomCPView extends FrameLayout {
/**
* 开启或关闭特效视图
*
* @param isShow 是否显示
*/
public void openOrCloseEffectViewWith(boolean isShow) {
@@ -779,9 +799,10 @@ public class RoomCPView extends FrameLayout {
/**
* 下载并播放动画
* @param context 上下文
*
* @param context 上下文
* @param playImage 动画URL
* @param callback 下载回调
* @param callback 下载回调
*/
public void downloadAndPlay(Context context, String playImage, DownloadCallback callback) {
String fileName = playImage.substring(playImage.lastIndexOf("/"));