feat: 周星 闪屏 优化

This commit is contained in:
eggmanQQQ
2024-12-31 10:37:14 +08:00
parent a5fd7bfd8d
commit b45eac2580
2 changed files with 57 additions and 30 deletions

View File

@@ -381,6 +381,7 @@ class EffectView : FrameLayout {
private fun loadSvga(videoItem: SVGAVideoEntity?) {
"EffectView loadSvga() ".doLog()
try {
var mSvgaImageIndex = 0;
if (videoItem == null) {
"EffectView loadSvga() Exception videoItem=null".doLog()
playCallBack(false)
@@ -417,7 +418,13 @@ class EffectView : FrameLayout {
dynamicEntity,
imgUrl,
key
)
) { resource ->
mSvgaImageIndex ++;
dynamicEntity.setDynamicImage(resource,key)
if (mSvgaImageIndex == mImgUrlMap?.count()) {
playSvga(svgaView, videoItem, dynamicEntity)
}
}
}
}
}
@@ -446,13 +453,12 @@ class EffectView : FrameLayout {
}
}
val drawable = SVGADrawable(videoItem, dynamicEntity)
svgaView.post {
svgaView.setImageDrawable(drawable)
svgaView.stepToFrame(0, true)
playCallBack(true)
"EffectView loadSvga() start".doLog()
if (mImgUrlMap?.isNotEmpty() == true) {
// 有图片, 等待下载完毕再播放svga
} else {
playSvga(svgaView, videoItem, dynamicEntity)
}
} catch (e: Exception) {
"EffectView loadSvga() Exception = ${e?.message}".doLog()
playCallBack(false)
@@ -468,7 +474,6 @@ class EffectView : FrameLayout {
mCallBack?.onPlay(isSuccess,type)
}
private fun split(bitmap: Bitmap?): List<Drawable> {
"EffectView split() ".doLog()
val pieces: MutableList<Drawable> = ArrayList()
@@ -501,13 +506,12 @@ class EffectView : FrameLayout {
return pieces
}
private fun addDynamicImage(
view: View,
dynamicEntity: SVGADynamicEntity,
url: String?,
forKey: String?
forKey: String?,
imageCallBack : (resource: Bitmap)->Unit
) {
if (TextUtils.isEmpty(url) || TextUtils.isEmpty(forKey)) {
LogUtils.d("AnimLoadUtil drawEffect addDynamicImage: url or forKey is null or empty")
@@ -524,12 +528,7 @@ class EffectView : FrameLayout {
target: Target<Bitmap?>,
isFirstResource: Boolean
): Boolean {
view.post {
dynamicEntity.setDynamicImage(
BitmapFactory.decodeResource(view.resources, R.drawable.default_avatar),
forKey!!
)
}
imageCallBack(BitmapFactory.decodeResource(view.resources, R.drawable.default_avatar))
return false
}
@@ -540,11 +539,8 @@ class EffectView : FrameLayout {
dataSource: DataSource,
isFirstResource: Boolean
): Boolean {
view.post {
dynamicEntity.setDynamicImage(
resource!!,
forKey!!
)
if (resource != null) {
imageCallBack(resource)
}
return false
}
@@ -552,6 +548,15 @@ class EffectView : FrameLayout {
.submit()
}
private fun playSvga(svgaView:SVGAView,videoItem: SVGAVideoEntity,dynamicEntity: SVGADynamicEntity) {
val drawable = SVGADrawable(videoItem, dynamicEntity)
svgaView.post {
svgaView.setImageDrawable(drawable)
svgaView.stepToFrame(0, true)
playCallBack(true)
"EffectView loadSvga() start".doLog()
}
}
public interface CallBack{
fun onPlay(isSuccess: Boolean,type: Int? = -1)

View File

@@ -1,5 +1,7 @@
package com.chwl.core.home.bean;
import com.chwl.library.common.util.OtherExtKt;
import java.io.Serializable;
import java.util.HashMap;
@@ -33,22 +35,42 @@ public class FillVo implements Serializable {
public HashMap<String, String> getImgMap() {
HashMap<String, String> map = new HashMap<>();
map.put(Key.STAR_AVATAR,this.avatar);
map.put(Key.GIFT_PIC,this.picUrl);
if (OtherExtKt.isVerify(this.avatar)) {
map.put(Key.STAR_AVATAR,this.avatar);
}
if (OtherExtKt.isVerify(this.picUrl)) {
map.put(Key.GIFT_PIC,this.picUrl);
}
if (OtherExtKt.isVerify(this.avatar)) {
map.put(Key.CP_AVATAR,this.avatar);
}
if (OtherExtKt.isVerify(this.loverAvatar)) {
map.put(Key.CP_LOVER_AVATAR,this.loverAvatar);
}
map.put(Key.CP_AVATAR,this.avatar);
map.put(Key.CP_LOVER_AVATAR,this.loverAvatar);
return map;
}
public HashMap<String, String> getTextMap() {
HashMap<String, String> map = new HashMap<>();
map.put(Key.STAR_ID, String.valueOf(this.erbanNo));
map.put(Key.GIFT_NAME,this.giftName);
if (this.erbanNo > 0) {
map.put(Key.STAR_ID, String.valueOf(this.erbanNo));
}
map.put(Key.CP_ID, String.valueOf(this.erbanNo));
map.put(Key.CP_LOVER_ID, String.valueOf(this.loverErbanNo));
if (OtherExtKt.isVerify(this.giftName)) {
map.put(Key.GIFT_NAME,this.giftName);
}
if (this.erbanNo > 0) {
map.put(Key.CP_ID, String.valueOf(this.erbanNo));
}
if (this.loverErbanNo > 0) {
map.put(Key.CP_LOVER_ID, String.valueOf(this.loverErbanNo));
}
return map;
}