没来得及组织,直接给出答案吧,GlideWebpDecoder 这个库 亲测可用, 在各版本安卓版本,不同Rom的机型上都能正常播放 webp动图。
最终解决方案:https://github.com/zjupure/GlideWebpDecoder
注意:GlideWebpDecoder 这个库要求 glide 使用 4.2版本。 如果公司项目架构复杂,导致 报 glide annotationProcessor 相关的版本冲突,不知道如何解决的,请加我QQ:347287812
以下是 摸索过程中的一些尝试,最终都没有成功,大家不要走以下的弯路了。
但 fresco 却能 加载 动态webp 图, 请放弃 glide 吧。 用法 如下:
compile 'com.facebook.fresco:animated-webp:1.7.1' compile 'com.facebook.fresco:webpsupport:1.7.1' compile 'com.facebook.fresco:fresco:1.7.1'
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); simpleDraweeView = findViewById(R.id.draweeview); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri("http://asgard.image.mucang.cn/asgard/2017/12/28/10/45ab2f68a13546c1914b61d54160b8ae.webp") .setAutoPlayAnimations(true) .build(); simpleDraweeView.setController(controller); }
网上查资料 发现 都说 glide 支持 加载 webp 格式的图片, 但 使用 'com.github.bumptech.glide:glide:4.4.0' 测试发现 ,直接通过 如下图方式 加载 网络上的webp 是行不通。
猜测原因,应该是 glide 是将图片解析的 过程 以接口的 方式 暴露出来, 对于 那些 冷门的 图片格式, 可能并没有默认的解析实现类, 需要开发者自己去 添加 解析实现类。
Glide.with(this) .load("http://omsproductionimg.yangkeduo.com/images/label/610/GS4X5Ojt5TlVPuAtNGqr2hywByGs2FHN.jpg@120w_1l_50Q.webp") .apply(options).transition(new DrawableTransitionOptions().crossFade(200)) .into(imageView);
这个库也是不能彻底解决 , github地址 : https://github.com/roths/GlideWebpSupport
注意:如果clone这个 demo 发现 不能加载 网络webp,请记得加上 user-permission - INTERNET 网络访问权限 。
原理是 借助 fresco的web库 来 解析 网络流,并且支持动态 webp,代码也需要简单,需要引入
compile "com.facebook.fresco:animated-webp:0.11.0"库 , 并拷贝 4个类, 这4个类的作用 应该是 按 glide 提供的 接口方式 来 实现 网络流的解析,但最核心的 解析层 是使用 fresco的 web扩展库 解析的。 这4个类 仅仅 是包装作用。
在华为 honor 手机上发现 有问题, 安卓 版本是 7.0 , 只能加载 webp静态图,不能加载 webp 动态图.