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

Commit

Permalink
fix: Add finalize method to release some resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
PonyCui committed Jan 21, 2019
1 parent 16c3f61 commit 8506240
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions library/src/main/java/com/opensource/svgaplayer/SVGAParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class SVGAParser(private val context: Context) {
private var threadPoolBlockingQueue = LinkedBlockingQueue<Runnable>()
private var threadPoolExecutor = ThreadPoolExecutor(3, 10, 60000, TimeUnit.MILLISECONDS, this.threadPoolBlockingQueue)

fun finalize() {
threadPoolExecutor.shutdown()
}

fun decodeFromAssets(name: String, callback: ParseCompletion) {
try {
context.assets.open(name)?.let {
Expand Down Expand Up @@ -127,9 +131,9 @@ class SVGAParser(private val context: Context) {
else {
inflate(bytes)?.let {
val videoItem = SVGAVideoEntity(MovieEntity.ADAPTER.decode(it), File(cacheKey))
videoItem.prepare {
// videoItem.prepare {
this.invokeCompleteCallback(videoItem, callback)
}
// }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ private val options = BitmapFactory.Options()
*/
class SVGAVideoEntity {

fun finalize() {
this.soundPool?.release()
this.soundPool = null
this.images.forEach { it.value.recycle() }
this.images.clear()
}

var antiAlias = true

var videoSize = SVGARect(0.0, 0.0, 0.0, 0.0)
Expand Down

0 comments on commit 8506240

Please sign in to comment.