pull/1814/head
kunfei 3 years ago
parent e99459e2e7
commit 8bdb3042da
  1. 11
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt

@ -43,6 +43,7 @@ class HttpReadAloudService : BaseReadAloudService(),
private val cacheFiles = hashSetOf<String>() private val cacheFiles = hashSetOf<String>()
private var downloadTask: Coroutine<*>? = null private var downloadTask: Coroutine<*>? = null
private var playIndexJob: Job? = null private var playIndexJob: Job? = null
private var downloadTaskIsActive = false
private var downloadErrorNo: Int = 0 private var downloadErrorNo: Int = 0
private var playErrorNo = 0 private var playErrorNo = 0
@ -103,7 +104,12 @@ class HttpReadAloudService : BaseReadAloudService(),
} }
private fun downloadAudio() { private fun downloadAudio() {
launch {
downloadTask?.cancel() downloadTask?.cancel()
while (downloadTaskIsActive) {
//在线tts大部分只能单线程,等待上次访问结束
delay(100)
}
downloadTask = execute { downloadTask = execute {
clearSpeakCache() clearSpeakCache()
removeCacheFile() removeCacheFile()
@ -202,6 +208,11 @@ class HttpReadAloudService : BaseReadAloudService(),
} }
} }
} }
}.onStart {
downloadTaskIsActive = true
}.onFinally {
downloadTaskIsActive = false
}
} }
} }

Loading…
Cancel
Save