朗读连续3段错误时提示错误并停止朗读

pull/1319/head
gedoor 3 years ago
parent a14b3377c2
commit 9010f1747e
  1. 39
      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.app.PendingIntent
import android.media.MediaPlayer import android.media.MediaPlayer
import io.legado.app.constant.AppLog
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
@ -73,6 +74,16 @@ class HttpReadAloudService : BaseReadAloudService(),
player.stop() player.stop()
} }
private fun playNext() {
readAloudNumber += contentList[nowSpeak].length + 1
if (nowSpeak < contentList.lastIndex) {
nowSpeak++
play()
} else {
nextChapter()
}
}
private fun downloadAudio() { private fun downloadAudio() {
task?.cancel() task?.cancel()
task = execute { task = execute {
@ -234,32 +245,28 @@ class HttpReadAloudService : BaseReadAloudService(),
postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1)
} }
private var errorNo = 0
override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean {
LogUtils.d("mp", "what:$what extra:$extra") LogUtils.d("mp", "what:$what extra:$extra")
if (what == -38 && extra == 0) { if (what == -38 && extra == 0) {
return true return true
} }
launch { AppLog.addLog("朗读错误,($what, $extra)")
delay(100) errorNo++
readAloudNumber += contentList[nowSpeak].length + 1 if (errorNo >= 3) {
if (nowSpeak < contentList.lastIndex) { toastOnUi("朗读连续3次错误, 最后一次错误代码($what, $extra)")
nowSpeak++
play()
} else {
nextChapter()
} }
launch {
delay(500)
playNext()
} }
return true return false
} }
override fun onCompletion(mp: MediaPlayer?) { override fun onCompletion(mp: MediaPlayer?) {
readAloudNumber += contentList[nowSpeak].length + 1 errorNo = 0
if (nowSpeak < contentList.lastIndex) { playNext()
nowSpeak++
play()
} else {
nextChapter()
}
} }
override fun aloudServicePendingIntent(actionStr: String): PendingIntent? { override fun aloudServicePendingIntent(actionStr: String): PendingIntent? {

Loading…
Cancel
Save