From 9010f1747edb489b99af3457e2de36f828c24fd9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 13 Sep 2021 21:08:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=97=E8=AF=BB=E8=BF=9E=E7=BB=AD3=E6=AE=B5?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=97=B6=E6=8F=90=E7=A4=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=B9=B6=E5=81=9C=E6=AD=A2=E6=9C=97=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/HttpReadAloudService.kt | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) 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 620566feb..13f4d90c9 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -2,6 +2,7 @@ package io.legado.app.service import android.app.PendingIntent import android.media.MediaPlayer +import io.legado.app.constant.AppLog import io.legado.app.constant.EventBus import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine @@ -73,6 +74,16 @@ class HttpReadAloudService : BaseReadAloudService(), player.stop() } + private fun playNext() { + readAloudNumber += contentList[nowSpeak].length + 1 + if (nowSpeak < contentList.lastIndex) { + nowSpeak++ + play() + } else { + nextChapter() + } + } + private fun downloadAudio() { task?.cancel() task = execute { @@ -234,32 +245,28 @@ class HttpReadAloudService : BaseReadAloudService(), postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) } + private var errorNo = 0 + override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { LogUtils.d("mp", "what:$what extra:$extra") if (what == -38 && extra == 0) { return true } + AppLog.addLog("朗读错误,($what, $extra)") + errorNo++ + if (errorNo >= 3) { + toastOnUi("朗读连续3次错误, 最后一次错误代码($what, $extra)") + } launch { - delay(100) - readAloudNumber += contentList[nowSpeak].length + 1 - if (nowSpeak < contentList.lastIndex) { - nowSpeak++ - play() - } else { - nextChapter() - } + delay(500) + playNext() } - return true + return false } override fun onCompletion(mp: MediaPlayer?) { - readAloudNumber += contentList[nowSpeak].length + 1 - if (nowSpeak < contentList.lastIndex) { - nowSpeak++ - play() - } else { - nextChapter() - } + errorNo = 0 + playNext() } override fun aloudServicePendingIntent(actionStr: String): PendingIntent? {