fix 修改动画
This commit is contained in:
@@ -1,18 +1,12 @@
|
||||
package com.xscm.moduleutil.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.net.Uri;
|
||||
import android.opengl.GLES11Ext;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.LruCache;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
@@ -21,13 +15,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.PathUtils;
|
||||
import com.blankj.utilcode.util.ThreadUtils;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.ui.PlayerView;
|
||||
import com.liulishuo.okdownload.DownloadTask;
|
||||
import com.liulishuo.okdownload.StatusUtil;
|
||||
import com.liulishuo.okdownload.core.cause.EndCause;
|
||||
import com.liulishuo.okdownload.core.cause.ResumeFailedCause;
|
||||
import com.liulishuo.okdownload.core.listener.DownloadListener1;
|
||||
@@ -38,20 +26,12 @@ 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;
|
||||
@@ -73,52 +53,9 @@ import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
|
||||
public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
public class AvatarFrameView extends FrameLayout {
|
||||
private PlaybackManager playbackManager;
|
||||
|
||||
@Override
|
||||
public void onFailed(int i, @Nullable String s) {
|
||||
LogUtils.e("@@@@" + "onFailed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onVideoConfigReady(@NonNull AnimConfig animConfig) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoStart() {
|
||||
LogUtils.e("@@@@" + "onVideoStart");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoRender(int i, @Nullable AnimConfig animConfig) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoComplete() {
|
||||
// if (mType == 1) {
|
||||
// mBinding.playView.startPlay(mFile); // 循环播放
|
||||
// } else {
|
||||
// isPlaying = false;
|
||||
// playNextFromQueue(); // 播放下一项
|
||||
// }
|
||||
// if (isDestroyed) return;
|
||||
|
||||
// 确保在主线程中执行
|
||||
// EventBus.getDefault().post(new GiftAvatarBean());
|
||||
LogUtils.e("@@@@" + "EventBus onVideoComplete");
|
||||
// if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
// handleVideoComplete();
|
||||
// } else {
|
||||
// mainHandler.post(() -> {
|
||||
//// if (!isDestroyed) {
|
||||
// handleVideoComplete();
|
||||
//// }
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
private void handleVideoComplete() {
|
||||
// if (isDestroyed) return;
|
||||
|
||||
@@ -172,11 +109,6 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoDestroy() {
|
||||
|
||||
}
|
||||
|
||||
public enum RenderType {SVGA, MP4}
|
||||
|
||||
private RenderType renderType;
|
||||
@@ -239,10 +171,10 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
playbackManager = new PlaybackManager(mainHandler);
|
||||
|
||||
// 获取 MP4PlaybackCallback 单例实例并设置引用
|
||||
MP4PlaybackCallback callback = MP4PlaybackCallback.getInstance();
|
||||
callback.setAvatarFrameView(this);
|
||||
// MP4PlaybackCallback callback = MP4PlaybackCallback.getInstance();
|
||||
// callback.setAvatarFrameView(this);
|
||||
// 设置播放完成监听
|
||||
mBinding.playView.setAnimListener(callback);
|
||||
// mBinding.playView.setAnimListener(callback);
|
||||
|
||||
// if (mBinding != null) {
|
||||
// mBinding.playView.setAnimListener(this);
|
||||
@@ -327,7 +259,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
}
|
||||
|
||||
// 添加统一的播放完成处理方法
|
||||
private void onPlaybackComplete() {
|
||||
public void onPlaybackComplete() {
|
||||
mainHandler.post(() -> {
|
||||
if (isDestroyed) return;
|
||||
|
||||
@@ -338,9 +270,9 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
isPlaying = false;
|
||||
|
||||
// 内存清理检查
|
||||
if (playQueue.size() % 5 == 0) {
|
||||
performLightMemoryCleanup();
|
||||
}
|
||||
// if (playQueue.size() % 5 == 0) {
|
||||
// performLightMemoryCleanup();
|
||||
// }
|
||||
// 继续处理队列中的下一个项目
|
||||
playNextFromQueue();
|
||||
});
|
||||
@@ -381,6 +313,10 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPlaying(){
|
||||
return mBinding.playView.isRunning();
|
||||
}
|
||||
// 在 AvatarFrameView 类中添加以下代码
|
||||
|
||||
private static final int MAX_CONCURRENT_PROCESSING = 3; // 同时处理的最大动画数
|
||||
@@ -401,11 +337,11 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
// return;
|
||||
// }
|
||||
// 检查特效是否开启
|
||||
if (SpUtil.getOpenEffect() != 1) {
|
||||
// 特效关闭时清空队列并停止播放
|
||||
clearQueue();
|
||||
return;
|
||||
}
|
||||
// if (SpUtil.getOpenEffect() != 1) {
|
||||
// // 特效关闭时清空队列并停止播放
|
||||
// clearQueue();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 添加到播放队列
|
||||
playQueue.add(new PlayItem(url, type2));
|
||||
@@ -1408,66 +1344,9 @@ public class AvatarFrameView extends FrameLayout 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(AvatarFrameView.TAG, "MP4 playback failed: " + s);
|
||||
if (avatarFrameView != null) {
|
||||
avatarFrameView.onPlaybackComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onVideoConfigReady(@NonNull AnimConfig animConfig) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoStart() {
|
||||
// 播放开始
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoRender(int i, @Nullable AnimConfig animConfig) {
|
||||
// 视频渲染中
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoComplete() {
|
||||
if (avatarFrameView != null) {
|
||||
avatarFrameView.onPlaybackComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoDestroy() {
|
||||
// 视频销毁
|
||||
}
|
||||
public void setAnimListener(IAnimListener mInstance) {
|
||||
mBinding.playView.setAnimListener(mInstance);
|
||||
}
|
||||
|
||||
// 添加统一的播放完成处理方法
|
||||
|
||||
Reference in New Issue
Block a user