安卓SVGA使用Glide在线播放只播放1次监听播放完成

1,739 阅读1分钟
SVGAGlidePlugin demo 动态加载view播放失败。

网上寻找了好久,都没有比较好的方案。自己折腾出来了。

希望这篇文章,可以拯救你的时间。

一、引入库

    // SVGAPlayer
    implementation 'com.github.yyued:SVGAPlayer-Android:2.6.1'
    
    // Glide 
    implementation "com.github.bumptech.glide:glide:4.13.2"
    kapt "com.github.bumptech.glide:compiler:4.13.2"
    
    // integration for them
    implementation 'com.github.YvesCheung:SVGAGlidePlugin:4.13.2'

动态加载View,播放,控制播放次数,监听播放完成

var animationView: SVGAImageView? = null

---------

animationView = SVGAImageView(this)
        animationView!!.setBackgroundColor(Color.GRAY)
        binding.flFull.addView(animationView)

------------


var myurl ="https://xxxxxxx.svga"
animationView!!.loops = 1
animationView!!.callback = object : SVGACallback {
    override fun onFinished() {
        showToast("播放完成")
        // 播放完成移除View
        binding.flFull.removeView(animationView)
    }
    override fun onPause() {
    }
    override fun onRepeat() {
    }
    override fun onStep(frame: Int, percentage: Double) {
    }
}
Glide.with(this).load(myurl).into(animationView!!)


动态布局

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <FrameLayout
        android:id="@+id/flFull"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</layout>

尽情享受它吧,点个赞,知道吗

没有账号给我注册一个!


最后,记得混淆