From 101dcbde839757940db393d8a0845665c2e0811a Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 11:35:24 +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 --- .../legado/app/service/BaseReadAloudService.kt | 2 +- .../legado/app/service/HttpReadAloudService.kt | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 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 45915fd1d..74a5980f9 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -40,7 +40,7 @@ abstract class BaseReadAloudService : BaseService(), } } - private val handler = Handler() + val handler = Handler() private lateinit var audioManager: AudioManager private var mFocusRequest: AudioFocusRequest? = null private var broadcastReceiver: BroadcastReceiver? = null 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 8dc5c3927..7cbfb0b50 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -8,7 +8,10 @@ import io.legado.app.help.IntentHelp import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.api.HttpPostApi import io.legado.app.service.help.ReadBook -import io.legado.app.utils.* +import io.legado.app.utils.FileUtils +import io.legado.app.utils.getPrefInt +import io.legado.app.utils.getPrefString +import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Job import kotlinx.coroutines.isActive @@ -94,6 +97,7 @@ class HttpReadAloudService : BaseReadAloudService(), mediaPlayer.reset() mediaPlayer.setDataSource(fd) mediaPlayer.prepareAsync() + postEvent(Bus.TTS_START, readAloudNumber + 1) } catch (e: Exception) { e.printStackTrace() } @@ -182,11 +186,19 @@ class HttpReadAloudService : BaseReadAloudService(), } override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { + handler.postDelayed({ + readAloudNumber += contentList[nowSpeak].length + 1 + if (nowSpeak < contentList.lastIndex) { + nowSpeak++ + play() + } else { + nextChapter() + } + }, 1000) return true } override fun onCompletion(mp: MediaPlayer?) { - LogUtils.d("播放完成", contentList[nowSpeak]) readAloudNumber += contentList[nowSpeak].length + 1 if (nowSpeak < contentList.lastIndex) { nowSpeak++