pull/84/head
kunfei 5 years ago
parent 07aac1e0a9
commit 101dcbde83
  1. 2
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  2. 16
      app/src/main/java/io/legado/app/service/HttpReadAloudService.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

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

Loading…
Cancel
Save