朗读用exoPlayer

pull/1660/head
kunfei 3 years ago
parent a3424402d4
commit 628f2d22f0
  1. 14
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt

@ -43,7 +43,6 @@ class HttpReadAloudService : BaseReadAloudService(),
}
private val cacheFiles = hashSetOf<String>()
private var task: Coroutine<*>? = null
private var playingIndex = -1
private var playIndexJob: Job? = null
private val mutex = Mutex()
@ -58,12 +57,8 @@ class HttpReadAloudService : BaseReadAloudService(),
exoPlayer.release()
}
override fun newReadAloud(play: Boolean) {
playingIndex = -1
super.newReadAloud(play)
}
override fun play() {
exoPlayer.stop()
if (contentList.isEmpty()) {
AppLog.putDebug("朗读列表为空")
ReadBook.readAloud()
@ -213,7 +208,7 @@ class HttpReadAloudService : BaseReadAloudService(),
@Synchronized
private fun playAudio(file: File) {
if (playingIndex != nowSpeak && requestFocus()) {
if (requestFocus()) {
launch {
kotlin.runCatching {
val mediaItem = MediaItem.fromUri(Uri.fromFile(file))
@ -288,14 +283,10 @@ class HttpReadAloudService : BaseReadAloudService(),
override fun resumeReadAloud() {
super.resumeReadAloud()
kotlin.runCatching {
if (playingIndex == -1) {
play()
} else {
exoPlayer.play()
upPlayPos()
}
}
}
private fun upPlayPos() {
playIndexJob?.cancel()
@ -328,7 +319,6 @@ class HttpReadAloudService : BaseReadAloudService(),
override fun upSpeechRate(reset: Boolean) {
task?.cancel()
exoPlayer.stop()
playingIndex = -1
downloadAudio()
}

Loading…
Cancel
Save