From 94651df0389532978f1c4d3a951e2063c1ce77bd Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 18 Oct 2021 16:02:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/HttpReadAloudService.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 64b9d93e3..db5a97951 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -14,6 +14,8 @@ import io.legado.app.model.ReadBook import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.* import kotlinx.coroutines.* +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock import okhttp3.Response import java.io.File import java.io.FileDescriptor @@ -36,6 +38,7 @@ class HttpReadAloudService : BaseReadAloudService(), private var task: Coroutine<*>? = null private var playingIndex = -1 private var playIndexJob: Job? = null + private val mutex = Mutex() override fun onCreate() { super.onCreate() @@ -126,7 +129,9 @@ class HttpReadAloudService : BaseReadAloudService(), source = httpTts, headerMapF = httpTts.getHeaderMap(true) ) - var response = analyzeUrl.getResponseAwait() + var response = mutex.withLock { + analyzeUrl.getResponseAwait() + } ensureActive() httpTts.loginCheckJs?.takeIf { checkJs -> checkJs.isNotBlank()