Giter VIP home page Giter VIP logo

svgaplayer-android's Introduction

Archived

本仓库已经停止维护,你仍然继续阅读源码及创建分叉,但本仓库不会继续更新,也不会回答任何 issue。

This repo has stopped maintenance, you can still continue to read the source code and create forks, but this repo will not continue to be updated, nor will it answer any issues.

SVGAPlayer

简体中文

支持本项目

  1. 轻点 GitHub Star,让更多人看到该项目。

Introduce

SVGAPlayer is a light-weight animation renderer. You use tools to export svga file from Adobe Animate CC or Adobe After Effects, and then use SVGAPlayer to render animation on mobile application.

SVGAPlayer-Android render animation natively via Android Canvas Library, brings you a high-performance, low-cost animation experience.

If wonder more information, go to this website.

Usage

Here introduce SVGAPlayer-Android usage. Wonder exporting usage? Click here.

Install Via Gradle

We host aar file on JitPack, your need to add JitPack.io repo build.gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Then, add dependency to app build.gradle.

compile 'com.github.yyued:SVGAPlayer-Android:latest'

Static Parser Support

Perser#shareParser should be init(context) in Application or other Activity. Otherwise it will report an error: Log.e("SVGAParser", "在配置 SVGAParser context 前, 无法解析 SVGA 文件。")

Matte Support

Head on over to Dynamic · Matte Layer

Proguard-rules

-keep class com.squareup.wire.** { *; }
-keep class com.opensource.svgaplayer.proto.** { *; }

Locate files

SVGAPlayer could load svga file from Android assets directory or remote server.

Using XML

You may use layout.xml to add a SVGAImageView.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.opensource.svgaplayer.SVGAImageView
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        app:source="posche.svga"
        app:autoPlay="true"
        android:background="#000" />

</RelativeLayout>

The following attributes is allowable:

source: String

The svga file path, provide a path relative to Android assets directory, or provide a http url.

autoPlay: Boolean

Defaults to true.

After animation parsed, plays animation automatically.

loopCount: Int

Defaults to 0.

How many times should animation loops. 0 means Infinity Loop.

clearsAfterStop: Boolean

Defaults to false.When the animation is finished, whether to clear the canvas and the internal data of SVGAVideoEntity. It is no longer recommended. Developers can control resource release through clearAfterDetached, or manually control resource release through SVGAVideoEntity#clear

clearsAfterDetached: Boolean

Defaults to false.Clears canvas and the internal data of SVGAVideoEntity after SVGAImageView detached.

fillMode: String

Defaults to Forward. Could be Forward, Backward, Clear.

Forward means animation will pause on last frame after finished.

Backward means animation will pause on first frame after finished.

Clear after the animation is played, all the canvas content is cleared, but it is only the canvas and does not involve the internal data of SVGAVideoEntity.

Using code

You may use code to add SVGAImageView either.

Create a SVGAImageView instance.

SVGAImageView imageView = new SVGAImageView(this);

Declare a static Parser instance.

parser = SVGAParser.shareParser()

Init parser instance

You should initialize the parser instance with context before usage.

SVGAParser.shareParser().init(this);

Otherwise it will report an error: Log.e("SVGAParser", "在配置 SVGAParser context 前, 无法解析 SVGA 文件。")

You can also create SVGAParser instance by yourself.

Create a SVGAParser instance, parse from assets like this.

parser = new SVGAParser(this);
// The third parameter is a default parameter, which is null by default. If this method is set, the audio parsing and playback will not be processed internally. The audio File instance will be sent back to the developer through PlayCallback, and the developer will control the audio playback and playback. stop
parser.decodeFromAssets("posche.svga", object : SVGAParser.ParseCompletion {
    // ...
}, object : SVGAParser.PlayCallback {
    // The default is null, can not be set
})

Create a SVGAParser instance, parse from remote server like this.

parser = new SVGAParser(this);
// The third parameter is a default parameter, which is null by default. If this method is set, the audio parsing and playback will not be processed internally. The audio File instance will be sent back to the developer through PlayCallback, and the developer will control the audio playback and playback. stop
parser.decodeFromURL(new URL("https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"), new SVGAParser.ParseCompletion() {
    // ...
}, object : SVGAParser.PlayCallback {
    // The default is null, can not be set
})

Create a SVGADrawable instance then set to SVGAImageView, play it as you want.

parser = new SVGAParser(this);
parser.decodeFromURL(..., new SVGAParser.ParseCompletion() {
    @Override
    public void onComplete(@NotNull SVGAVideoEntity videoItem) {
        SVGADrawable drawable = new SVGADrawable(videoItem);
        imageView.setImageDrawable(drawable);
        imageView.startAnimation();
    }
    @Override
    public void onError() {

    }
});

Cache

SVGAParser will not manage any cache, you need to setup cacher by yourself.

Setup HttpResponseCache

SVGAParser depends on URLConnection, URLConnection uses HttpResponseCache to cache things.

Add codes to Application.java:onCreate to setup cacher.

val cacheDir = File(context.applicationContext.cacheDir, "http")
HttpResponseCache.install(cacheDir, 1024 * 1024 * 128)

SVGALogger

Updated the internal log output, which can be managed and controlled through SVGALogger. It is not activated by default. Developers can also implement the ILogger interface to capture and collect logs externally to facilitate troubleshooting Set whether the log is enabled through the setLogEnabled method Inject a custom ILogger implementation class through the injectSVGALoggerImp method

// By default, SVGA will not output any log, so you need to manually set it to true
SVGALogger.setLogEnabled(true)

// If you want to collect the output log of SVGA, you can obtain it in the following way
SVGALogger.injectSVGALoggerImp(object: ILogger {
// Implement related interfaces to receive log
})

SVGASoundManager

Added SVGASoundManager to control SVGA audio, you need to manually call the init method to initialize, otherwise follow the default audio loading logic. In addition, through SVGASoundManager#setVolume, you can control the volume of SVGA playback. The range is [0f, 1f]. By default, the volume of all SVGA playbacks is controlled. And this method can set a second default parameter: SVGAVideoEntity, which means that only the current SVGA volume is controlled, and the volume of other SVGAs remains unchanged.

// Initialize the audio manager for easy management of audio playback
// If it is not initialized, the audio will be loaded in the original way by default
SVGASoundManager.init()

// Release audio resources
SVGASoundManager.release()

/**
* Set the volume level, entity is null by default
* When entity is null, it controls the volume of all audio loaded through SVGASoundManager, which includes the currently playing audio and subsequent loaded audio
* When entity is not null, only the SVGA audio volume of the instance is controlled, and the others are not affected
* 
* @param volume The value range is [0f, 1f]
* @param entity That is, the instance of SVGAParser callback
*/
SVGASoundManager.setVolume(volume, entity)

Features

Here are many feature samples.

APIs

Head on over to https://github.com/yyued/SVGAPlayer-Android/wiki/APIs

CHANGELOG

Head on over to CHANGELOG

Credits

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

svgaplayer-android's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svgaplayer-android's Issues

HttpResponseCache问题

我按照文章所说的设置了Cache,但是svga文件并没有缓存下来,是什么情况?

Attribute "loopCount" has already been defined

Attention

  • Do not ask any usage question, issue board is a issue board, accept library bugs only.
  • If you are facing any usage problem, read the README again.

Issue Template

Issue Description(What's your problem)

How To Reappear(How to reappear the issue)

Any Attachment(Provide a sample about your issue)

------ 中文分割线 ------

注意

  • 不要在 Issue 板块提问使用问题,Issue 板块只接受 Bug 反馈。
  • 如果遇到使用上的问题,仔细阅读 README。

Issue 模板

请尽量使用英文提交 Issue

请确切回答:问题的描述、重现方式、附件(提供一个 Demo 以重现问题)

URL parse cache

参数为url进行解析时 如果本地没有缓存 会 走http 请求 请求回来后 会根据:
if (bytes.size > 4 && bytes[0].toInt() == 80 && bytes[1].toInt() == 75 && bytes[2].toInt() == 3 && bytes[3].toInt() == 4)
判断是否进行本地缓存,bytes这里的前几个自己是哪里定义的?为什么我的sbga里面前几个字节不满足缓存要求?导致不能使用缓存的代码,请问怎么才能解决。
感谢解答

耗内存问题。

我在使用这个sdk的时候时候,发现很耗内存,在一个viewpager上加载svga控件,发现很卡,之后调试发现,一个svga控件加载一个svga文件就消耗了40m内存,这个怎么优化?

内存泄漏问题

在多次播放的时候会偶发性出现内存泄漏(OOM)问题。这个现在有优化吗?

声音效果

这个动画执行的过程中可以伴随声音嘛?

能否支持在开始播放后再替换 SVGADynamicEntity ?

可能开始播放时,有些要替换到动画中的 Bitmap 还没准备好,希望可以先用默认的播,Bitmap准备好了再替换。我准备先修改源码支持这个需求,但是想问下 SVGA 只提供在生成 SVGADrawable 的时候传入动态Bitmap 而没有提供播放时动态设置,是有考虑到什么坑吗?以后会考虑支持吗?

加载assets 目录下svga感觉有点慢

如题,我在assets 目录下放置了两个svga文件,大小是200 - 300 左右,设置了两个按钮用来加载这两个动画,点击按钮加载的时候,或者切换的是,能感觉到明显的延迟,请问这个情况是否正常

大佬你好,请问属性clearsAfterStop会不会清楚设置的HttpResponseCache的缓存啊,:)

Attention

  • Do not ask any usage question, issue board is a issue board, accept library bugs only.
  • If you are facing any usage problem, read the README again.

Issue Template

Issue Description(What's your problem)

How To Reappear(How to reappear the issue)

Any Attachment(Provide a sample about your issue)

------ 中文分割线 ------

注意

  • 不要在 Issue 板块提问使用问题,Issue 板块只接受 Bug 反馈。
  • 如果遇到使用上的问题,仔细阅读 README。

Issue 模板

请尽量使用英文提交 Issue

请确切回答:问题的描述、重现方式、附件(提供一个 Demo 以重现问题)

oom

java.lang.OutOfMemoryError: Failed to allocate a 3089802 byte allocation with 2504048 free bytes and 2MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:537)
at com.opensource.svgaplayer.SVGAVideoEntity.resetImages(SVGAVideoEntity.kt:88)
at com.opensource.svgaplayer.SVGAVideoEntity.(SVGAVideoEntity.kt:57)
at com.opensource.svgaplayer.SVGAParser.parse(SVGAParser.kt:175)
at com.opensource.svgaplayer.SVGAParser.access$parse(SVGAParser.kt:25)
at com.opensource.svgaplayer.SVGAParser$parse$5.run(SVGAParser.kt:104)
at java.lang.Thread.run(Thread.java:760)

onComplete 回调前,已经remove 掉了SVGAImageView

Process: com.aipai.cloud, PID: 29992
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.Handler.post(java.lang.Runnable)' on a null object reference
at com.opensource.svgaplayer.SVGAImageView$loadAttrs$$inlined$let$lambda$1$2.onComplete(SVGAImageView.kt:130)
at com.opensource.svgaplayer.SVGAParser$parse$7$$special$$inlined$synchronized$lambda$1$1.run(SVGAParser.kt:142)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)

估计是我在发起一个SVGAParser 任务,但是在onComplete完成前,我已经把这个SVGAImageView 从父布局中remove 掉了导致的

Crash when play animation

E/MtaSDK: java.lang.OutOfMemoryError: Failed to allocate a 4002012 byte allocation with 2277808 free bytes and 2MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:533)
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:556)
at com.opensource.svgaplayer.SVGAVideoEntity.resetImages(SVGAVideoEntity.kt:80)
at com.opensource.svgaplayer.SVGAVideoEntity.(SVGAVideoEntity.kt:54)
at com.opensource.svgaplayer.SVGAParser.parse(SVGAParser.kt:169)
at com.opensource.svgaplayer.SVGAParser.access$parse(SVGAParser.kt:23)
at com.opensource.svgaplayer.SVGAParser$parse$5.run(SVGAParser.kt:96)
at java.lang.Thread.run(Thread.java:761)

内存泄露问题

跑 demo 的时候在simpleactivity 展示 svga 文件,但是activity 关闭后内存并没有释放,调用 System.gc() 也无效.

kingset.svga这个文件旋转问题

还有一个是alarm.svga这个文件旋转会偏移.请问怎么解决.我试了其他素材旋转没有问题.
刚开始以为是canvas画的时候问题,我在canvas上加了旋转角度也不对..我在考虑是否是素材有问题?

动态文本和图像

按照文档添加动态文本和图像没效果,是对SVGA动画有要求吗?

能否增加一个是否正在播放动画。

这个方法对我们项目很重要。希望作者能考虑下。因为动画是否正常结束,能否回调finish监听,开发者无法知道。错误情况下队列无法判断是否进行下个动画。

library 格式问题

library中大部分使用 kotlin 写的出于什么考虑? 会有 java 版本吗

小米手机动画结束时,屏幕会有全屏空白闪动

红米note 4x手机,当loops=1,动画结束时,会有个全屏的空白页面从右边进入,然后消失
经多次测试后,补充:
有问题时,SVGAImageView的宽高都是match_parent,当我给定一个具体值后不在出现空白页

请问有java版的库吗?

注意

Issue 模板

sorry for issue request,I need to add Android Source Code, but add svgplayer-kotlin.jar and org.jetbrains.kotlin:kotlin-stdlib-jre7.jar,build error.

So could you provide svgplayer-java.jar (JAVA Version)for me ?

严格模式抓到资源未回收的提示

E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'end' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:180)
at java.util.zip.Inflater.(Inflater.java:104)
at java.util.zip.Inflater.(Inflater.java:111)
at com.opensource.svgaplayer.SVGAParser.inflate(SVGAParser.kt:265)
at com.opensource.svgaplayer.SVGAParser.parse(SVGAParser.kt:174)
at com.opensource.svgaplayer.SVGAParser$pars

会支持交互吗?

动态添加的文字和图片支持交互(点击、触摸等事件)吗?如果没有,有支持的计划吗?

内存溢出

直接使用该框架播放svg动画时,多次播放动画 会出现内存溢出
Failed to allocate a 1325462 byte allocation with 541118 free bytes and 528KB until OOM
com.opensource.svgaplayer.SVGAVideoEntity.resetImages(SVGAVideoEntity.kt:84)

svga too large

on SAMSUNG note3,5.0:
W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (6242x495, max=4096x4096)

背景可以透明吗?

我设置了透明背景(backgroud="0x00000000")但是无效,显示的动画背景还是黑色的,会遮住底下的所有控件。请问是否还需要设置其他属性?

UI设计需要注意什么

Pony大大您好,最近接触到这个库觉得非常棒,很好改善了UI和猿猿的亲(si)密(bi)关系~ 希望大大能指教一下AE导出动画内存占用过大的问题,例如需要注意的地方是哪些等等,毕竟猿猿看到UI的头发都快挠没了也十分心(kai)疼(xin)。

帧图片做成的SVGA是不是占用内存会很大?

你好,设计做了个用帧图片做成的SVGA,用项目提供的示例载入,发现内存竟从30+M一路涨到300M,是设计制作的方法不对,还是本来就会占用较大的内存?YY有在低端手机上做过测试吗?有没有因此多了很多OOM?谢谢!

为什么在加载内存比较大的图片时会内存溢出

1 dalvik.system.VMRuntime.newNonMovableArray(Native Method)

2 android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
3 android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:526)
4 android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:549)
5 com.opensource.svgaplayer.SVGAVideoEntity.resetImages(SVGAVideoEntity.kt:80)
6 com.opensource.svgaplayer.SVGAVideoEntity.(SVGAVideoEntity.kt:54)
7 com.opensource.svgaplayer.SVGAParser.parse(SVGAParser.kt:169)
8 com.opensource.svgaplayer.SVGAParser.access$parse(SVGAParser.kt:23)
9 com.opensource.svgaplayer.SVGAParser$parse$5.run(SVGAParser.kt:96)
10 java.lang.Thread.run(Thread.java:818)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.