From 0361ed8b18304709b33c2ca48a3f8b3ef8e1a52d Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 12 Sep 2019 09:14:03 +0800 Subject: [PATCH] up --- .../java/io/legado/app/service/BaseReadAloudService.kt | 3 +-- .../java/io/legado/app/service/HttpReadAloudService.kt | 7 ++----- .../main/java/io/legado/app/service/TTSReadAloudService.kt | 2 ++ .../legado/app/ui/readbook/config/ReadAloudConfigDialog.kt | 6 ++++++ 4 files changed, 11 insertions(+), 7 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 c4a0f23e4..e3cee17be 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -39,7 +39,7 @@ abstract class BaseReadAloudService : BaseService(), private lateinit var mFocusRequest: AudioFocusRequest private var broadcastReceiver: BroadcastReceiver? = null private var mediaSessionCompat: MediaSessionCompat? = null - private var pause = false + var pause = false var title: String = "" private var subtitle: String = "" val contentList = arrayListOf() @@ -203,7 +203,6 @@ abstract class BaseReadAloudService : BaseService(), * @return 音频焦点 */ fun requestFocus(): Boolean { - MediaHelp.playSilentSound(this) val request: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { audioManager.requestAudioFocus(mFocusRequest) } else { 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 9d086e5c6..7c40d15aa 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -8,8 +8,6 @@ import io.legado.app.constant.Bus import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefString import io.legado.app.utils.postEvent -import kotlinx.coroutines.launch -import org.jetbrains.anko.toast class HttpReadAloudService : BaseReadAloudService(), MediaPlayer.OnPreparedListener, @@ -57,7 +55,6 @@ class HttpReadAloudService : BaseReadAloudService(), } override fun upSpeechRate(reset: Boolean) { - mediaPlayer.stop() play() } @@ -81,6 +78,7 @@ class HttpReadAloudService : BaseReadAloudService(), override fun onPrepared(mp: MediaPlayer?) { super.play() + if (pause) return mp?.start() textChapter?.let { if (readAloudNumber + 1 > it.getReadLength(pageIndex + 1)) { @@ -92,8 +90,7 @@ class HttpReadAloudService : BaseReadAloudService(), } override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { - launch { toast("播放出错") } - return false + return true } override fun onCompletion(mp: MediaPlayer?) { 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 1b9078371..0909d16fa 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -10,6 +10,7 @@ import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.constant.Bus import io.legado.app.help.IntentHelp +import io.legado.app.help.MediaHelp import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefInt import io.legado.app.utils.postEvent @@ -68,6 +69,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener return } if (requestFocus()) { + MediaHelp.playSilentSound(this) super.play() for (i in nowSpeak until contentList.size) { if (i == 0) { diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt index 40661d5f4..74ec5b18c 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt @@ -95,6 +95,12 @@ class ReadAloudConfigDialog : DialogFragment() { ReadAloud.stop(requireContext()) ReadAloud.aloudClass = ReadAloud.getReadAloudClass() } + "ttsSpeechPer" -> { + if (BaseReadAloudService.isRun) { + ReadAloud.stop(requireContext()) + postEvent(Bus.READ_ALOUD_BUTTON, true) + } + } } }