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

Commit f29563e

Browse files
author
zhusiliang
committed
fix bug:
1.兼容48khz的音频 2.修复音频错误没有回调 3.修复清除缓存之后,不弹出svga commit info:
1 parent fc2d35e commit f29563e

File tree

7 files changed

+373
-269
lines changed

7 files changed

+373
-269
lines changed

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

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
11
package com.opensource.svgaplayer
22

33
import android.content.Context
4-
import com.opensource.svgaplayer.utils.log.LogUtils
54
import java.io.File
65
import java.net.URL
76
import java.security.MessageDigest
87

9-
/**
10-
* SVGA 缓存管理
11-
*/
12-
object SVGACache {
13-
14-
private const val TAG = "SVGACache"
158

9+
object SVGACache {
1610
enum class Type {
1711
DEFAULT,
1812
FILE
1913
}
2014

2115
private var type: Type = Type.DEFAULT
2216
private var cacheDir: String = "/"
23-
get() {
24-
if (field != "/") {
25-
val dir = File(field)
26-
if (!dir.exists()) {
27-
dir.mkdirs()
28-
}
29-
}
30-
return field
31-
}
3217

3318
fun onCreate(context: Context?) {
3419
onCreate(context, Type.DEFAULT)
@@ -42,52 +27,22 @@ object SVGACache {
4227
this.type = type
4328
}
4429

45-
/**
46-
* 清理缓存
47-
*/
48-
fun clearCache() {
49-
if (!isInitialized()) {
50-
LogUtils.error(TAG, "SVGACache is not init!")
51-
return
52-
}
53-
SVGAParser.threadPoolExecutor.execute {
54-
clearDir(cacheDir)
55-
LogUtils.info(TAG, "Clear svga cache done!")
56-
}
57-
}
58-
59-
// 清除目录下的所有文件
60-
private fun clearDir(path: String) {
61-
try {
62-
val dir = File(path)
63-
dir.takeIf { it.exists() }?.let { parentDir ->
64-
parentDir.listFiles()?.forEach { file ->
65-
if (!file.exists()) {
66-
return@forEach
67-
}
68-
if (file.isDirectory) {
69-
clearDir(file.absolutePath)
70-
}
71-
file.delete()
72-
}
73-
}
74-
} catch (e: Exception) {
75-
LogUtils.error(TAG, "Clear svga cache path: $path fail", e)
76-
}
77-
}
30+
// fun clearCache(context: Context?){
31+
// context ?: return
32+
// cacheDir = "${context.cacheDir.absolutePath}/svga/"
33+
// File(cacheDir).takeIf { it.exists() }?.delete()
34+
// }
7835

7936
fun isInitialized(): Boolean {
80-
return "/" != cacheDir
37+
return "/" != cacheDir&&File(cacheDir).exists()
8138
}
8239

8340
fun isDefaultCache(): Boolean = type == Type.DEFAULT
8441

8542
fun isCached(cacheKey: String): Boolean {
86-
return (if (isDefaultCache()) {
87-
buildCacheDir(cacheKey)
88-
} else {
89-
buildSvgaFile(cacheKey)
90-
}).exists()
43+
return (if (isDefaultCache()) buildCacheDir(cacheKey) else buildSvgaFile(
44+
cacheKey
45+
)).exists()
9146
}
9247

9348
fun buildCacheKey(str: String): String {

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,47 @@ class SVGADrawable(val videoItem: SVGAVideoEntity, val dynamicItem: SVGADynamicE
5757
fun resume() {
5858
videoItem.audioList.forEach { audio ->
5959
audio.playID?.let {
60-
videoItem.soundPool?.resume(it)
60+
if (SVGASoundManager.get().isInit()){
61+
SVGASoundManager.get().resume(it)
62+
}else{
63+
videoItem.soundPool?.resume(it)
64+
}
6165
}
6266
}
6367
}
6468

6569
fun pause() {
6670
videoItem.audioList.forEach { audio ->
6771
audio.playID?.let {
68-
videoItem.soundPool?.pause(it)
72+
if (SVGASoundManager.get().isInit()){
73+
SVGASoundManager.get().pause(it)
74+
}else{
75+
videoItem.soundPool?.pause(it)
76+
}
6977
}
7078
}
7179
}
7280

7381
fun stop() {
7482
videoItem.audioList.forEach { audio ->
7583
audio.playID?.let {
76-
videoItem.soundPool?.stop(it)
84+
if (SVGASoundManager.get().isInit()){
85+
SVGASoundManager.get().stop(it)
86+
}else{
87+
videoItem.soundPool?.stop(it)
88+
}
7789
}
7890
}
7991
}
8092

8193
fun clear() {
8294
videoItem.audioList.forEach { audio ->
8395
audio.playID?.let {
84-
videoItem.soundPool?.stop(it)
96+
if (SVGASoundManager.get().isInit()){
97+
SVGASoundManager.get().stop(it)
98+
}else{
99+
videoItem.soundPool?.stop(it)
100+
}
85101
}
86102
audio.playID = null
87103
}

0 commit comments

Comments
 (0)