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