Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 8506240

Browse files
committed
fix: Add finalize method to release some resources.
1 parent 16c3f61 commit 8506240

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

library/src/main/java/com/opensource/svgaplayer/SVGAParser.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class SVGAParser(private val context: Context) {
8585
private var threadPoolBlockingQueue = LinkedBlockingQueue<Runnable>()
8686
private var threadPoolExecutor = ThreadPoolExecutor(3, 10, 60000, TimeUnit.MILLISECONDS, this.threadPoolBlockingQueue)
8787

88+
fun finalize() {
89+
threadPoolExecutor.shutdown()
90+
}
91+
8892
fun decodeFromAssets(name: String, callback: ParseCompletion) {
8993
try {
9094
context.assets.open(name)?.let {
@@ -127,9 +131,9 @@ class SVGAParser(private val context: Context) {
127131
else {
128132
inflate(bytes)?.let {
129133
val videoItem = SVGAVideoEntity(MovieEntity.ADAPTER.decode(it), File(cacheKey))
130-
videoItem.prepare {
134+
// videoItem.prepare {
131135
this.invokeCompleteCallback(videoItem, callback)
132-
}
136+
// }
133137
}
134138
}
135139
}

library/src/main/java/com/opensource/svgaplayer/SVGAVideoEntity.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ private val options = BitmapFactory.Options()
2222
*/
2323
class SVGAVideoEntity {
2424

25+
fun finalize() {
26+
this.soundPool?.release()
27+
this.soundPool = null
28+
this.images.forEach { it.value.recycle() }
29+
this.images.clear()
30+
}
31+
2532
var antiAlias = true
2633

2734
var videoSize = SVGARect(0.0, 0.0, 0.0, 0.0)

0 commit comments

Comments
 (0)