From 82340213106fc434c22179dade5c3134b0c50cec Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 6 Jan 2021 10:46:23 +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 --- .../app/service/HttpReadAloudService.kt | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) 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 ac1a5c4a6..a91771e66 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,7 @@ import io.legado.app.utils.FileUtils import io.legado.app.utils.LogUtils import io.legado.app.utils.MD5Utils import io.legado.app.utils.postEvent +import kotlinx.coroutines.ensureActive import kotlinx.coroutines.isActive import org.jetbrains.anko.collections.forEachWithIndex import java.io.File @@ -103,18 +104,15 @@ class HttpReadAloudService : BaseReadAloudService(), speakText = item, speakSpeed = AppConfig.ttsSpeechRate ).getByteArray().let { bytes -> - if (isActive) { - val file = getSpeakFileAsMd5(fileName) - //val file = getSpeakFile(index) - file.writeBytes(bytes) - removeSpeakCacheFile(fileName) - if (index == nowSpeak) { - @Suppress("BlockingMethodInNonBlockingContext") - val fis = FileInputStream(file) - playAudio(fis.fd) - } - } else { - removeSpeakCacheFile(fileName) + ensureActive() + val file = getSpeakFileAsMd5(fileName) + //val file = getSpeakFile(index) + file.writeBytes(bytes) + removeSpeakCacheFile(fileName) + if (index == nowSpeak) { + @Suppress("BlockingMethodInNonBlockingContext") + val fis = FileInputStream(file) + playAudio(fis.fd) } } } catch (e: SocketTimeoutException) {