Effect 模块是动画效果播放框架,支持多种动画格式的播放和管理,包括 SVGA、VAP、Lottie 等动画格式,提供统一的动画播放接口。
interface EffectPlayer {
fun loadAnimation(source: AnimationSource)
fun play()
fun pause()
fun stop()
fun setLoop(loop: Boolean)
fun setSpeed(speed: Float)
fun setAnimationListener(listener: AnimationListener)
}
interface AnimationListener {
fun onAnimationStart()
fun onAnimationEnd()
fun onAnimationCancel()
fun onAnimationRepeat()
}
// 创建动画播放器
val effectPlayer = EffectPlayer.create(context, effectView)
// 设置监听器
effectPlayer.setAnimationListener(object : AnimationListener {
override fun onAnimationStart() {
// 动画开始
}
override fun onAnimationEnd() {
// 动画结束
hideEffectView()
}
})
// 加载并播放动画
effectPlayer.loadAnimation(AnimationSource.fromAssets("gift_animation.svga"))
effectPlayer.setLoop(false)
effectPlayer.play()
// 动态替换内容
val dynamicItem = DynamicItem()
dynamicItem.setText("username", "张三")
dynamicItem.setImage("avatar", avatarBitmap)
effectPlayer.setDynamicItem(dynamicItem)
<com.adealink.frame.effect.EffectView
android:id="@+id/effect_view"
android:layout_width="match_parent"
android:layout_height="200dp"
app:effect_auto_play="true"
app:effect_loop="false"
app:effect_source="@raw/animation" />
// 预加载动画
EffectPreloader.preload(listOf(
"gift1.svga",
"gift2.svga",
"entrance.vap"
))
// 内存管理
effectPlayer.setMemoryStrategy(MemoryStrategy.LOW_MEMORY)
// 缓存配置
val cacheConfig = CacheConfig.Builder()
.maxCacheSize(50 * 1024 * 1024) // 50MB
.maxCacheCount(100)
.build()
implementation "com.wenext.android:frame-effect:6.0.0"