pull/1581/head
kunfei 3 years ago
parent b89495c87d
commit 35dfa58f9d
  1. 8
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  2. 25
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  3. 6
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt

@ -156,12 +156,8 @@ abstract class BaseReadAloudService : BaseService(),
@CallSuper @CallSuper
open fun resumeReadAloud() { open fun resumeReadAloud() {
pause = false pause = false
if (contentList.isEmpty()) { upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
ReadBook.readAloud() postEvent(EventBus.ALOUD_STATE, Status.PLAY)
} else {
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
postEvent(EventBus.ALOUD_STATE, Status.PLAY)
}
} }
abstract fun upSpeechRate(reset: Boolean = false) abstract fun upSpeechRate(reset: Boolean = false)

@ -63,18 +63,21 @@ class HttpReadAloudService : BaseReadAloudService(),
} }
override fun play() { override fun play() {
if (contentList.isEmpty()) return if (contentList.isEmpty()) {
ReadAloud.httpTTS?.let { ReadBook.readAloud()
val fileName = } else {
md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), contentList[nowSpeak]) ReadAloud.httpTTS?.let {
if (nowSpeak == 0) { val fileName =
downloadAudio() md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), contentList[nowSpeak])
} else { if (nowSpeak == 0) {
val file = getSpeakFileAsMd5(fileName)
if (file.exists()) {
playAudio(FileInputStream(file).fd)
} else {
downloadAudio() downloadAudio()
} else {
val file = getSpeakFileAsMd5(fileName)
if (file.exists()) {
playAudio(FileInputStream(file).fd)
} else {
downloadAudio()
}
} }
} }
} }

@ -65,7 +65,11 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
@Synchronized @Synchronized
override fun play() { override fun play() {
if (contentList.isNotEmpty() && ttsInitFinish && requestFocus()) { if (!ttsInitFinish) return
if (!requestFocus()) return
if (contentList.isEmpty()) {
ReadBook.readAloud()
} else {
super.play() super.play()
execute { execute {
MediaHelp.playSilentSound(this@TTSReadAloudService) MediaHelp.playSilentSound(this@TTSReadAloudService)

Loading…
Cancel
Save