pull/42/head
kunfei 5 years ago
parent 0c67447779
commit 3d21e636dd
  1. 3
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  2. 10
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt

@ -101,7 +101,8 @@ abstract class BaseReadAloudService : BaseService(),
return super.onStartCommand(intent, flags, startId)
}
private fun newReadAloud(dataKey: String?, play: Boolean) {
@CallSuper
open fun newReadAloud(dataKey: String?, play: Boolean) {
dataKey?.let {
textChapter = IntentDataHelp.getData(dataKey) as? TextChapter
textChapter?.let { textChapter ->

@ -11,6 +11,7 @@ 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.launch
import org.jetbrains.anko.toast
import java.io.File
@ -25,6 +26,7 @@ class HttpReadAloudService : BaseReadAloudService(),
private val mediaPlayer = MediaPlayer()
private lateinit var ttsFolder: String
private var job: Job? = null
private var playingIndex = -1
override fun onCreate() {
@ -57,6 +59,12 @@ class HttpReadAloudService : BaseReadAloudService(),
)
}
override fun newReadAloud(dataKey: String?, play: Boolean) {
mediaPlayer.reset()
job?.cancel()
super.newReadAloud(dataKey, play)
}
override fun play() {
if (contentList.isEmpty()) return
if (nowSpeak == 0) {
@ -70,7 +78,7 @@ class HttpReadAloudService : BaseReadAloudService(),
}
private fun downloadAudio() {
launch(IO) {
job = launch(IO) {
FileHelp.deleteFile(ttsFolder)
for (index in 0 until contentList.size) {
val bytes = HttpHelper.getByteRetrofit("http://tts.baidu.com")

Loading…
Cancel
Save