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