|
|
@ -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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
AppLog.addLog("朗读错误,($what, $extra)") |
|
|
|
|
|
|
|
errorNo++ |
|
|
|
|
|
|
|
if (errorNo >= 3) { |
|
|
|
|
|
|
|
toastOnUi("朗读连续3次错误, 最后一次错误代码($what, $extra)") |
|
|
|
|
|
|
|
} |
|
|
|
launch { |
|
|
|
launch { |
|
|
|
delay(100) |
|
|
|
delay(500) |
|
|
|
readAloudNumber += contentList[nowSpeak].length + 1 |
|
|
|
playNext() |
|
|
|
if (nowSpeak < contentList.lastIndex) { |
|
|
|
|
|
|
|
nowSpeak++ |
|
|
|
|
|
|
|
play() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
nextChapter() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
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? { |
|
|
|