From 35dfa58f9d372a71b688916d0d7f9b49201605bc Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Feb 2022 16:30:13 +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/BaseReadAloudService.kt | 8 ++---- .../app/service/HttpReadAloudService.kt | 25 +++++++++++-------- .../legado/app/service/TTSReadAloudService.kt | 6 ++++- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 46adde993..81a2235b5 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -156,12 +156,8 @@ abstract class BaseReadAloudService : BaseService(), @CallSuper open fun resumeReadAloud() { pause = false - if (contentList.isEmpty()) { - ReadBook.readAloud() - } else { - upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) - postEvent(EventBus.ALOUD_STATE, Status.PLAY) - } + upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) + postEvent(EventBus.ALOUD_STATE, Status.PLAY) } abstract fun upSpeechRate(reset: Boolean = false) 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 79f073b3b..260a482e1 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -63,18 +63,21 @@ class HttpReadAloudService : BaseReadAloudService(), } override fun play() { - if (contentList.isEmpty()) return - ReadAloud.httpTTS?.let { - val fileName = - md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), contentList[nowSpeak]) - if (nowSpeak == 0) { - downloadAudio() - } else { - val file = getSpeakFileAsMd5(fileName) - if (file.exists()) { - playAudio(FileInputStream(file).fd) - } else { + if (contentList.isEmpty()) { + ReadBook.readAloud() + } else { + ReadAloud.httpTTS?.let { + val fileName = + md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), contentList[nowSpeak]) + if (nowSpeak == 0) { downloadAudio() + } else { + val file = getSpeakFileAsMd5(fileName) + if (file.exists()) { + playAudio(FileInputStream(file).fd) + } else { + downloadAudio() + } } } } diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 24db5db4d..9eef5c2b1 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -65,7 +65,11 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener @Synchronized override fun play() { - if (contentList.isNotEmpty() && ttsInitFinish && requestFocus()) { + if (!ttsInitFinish) return + if (!requestFocus()) return + if (contentList.isEmpty()) { + ReadBook.readAloud() + } else { super.play() execute { MediaHelp.playSilentSound(this@TTSReadAloudService)