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++