diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 52161d925..d69abfe2d 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -297,14 +297,12 @@ object ReadBook : CoroutineScope by MainScope() { fun recycleRecorders(beforeIndex: Int, afterIndex: Int) { executor.execute { - val textChapter = curTextChapter - if (textChapter != null) { - if (afterIndex > beforeIndex) { - textChapter.getPage(afterIndex - 2)?.recycleRecorders() - } - if (afterIndex < beforeIndex) { - textChapter.getPage(afterIndex + 3)?.recycleRecorders() - } + val textChapter = curTextChapter ?: return@execute + if (afterIndex > beforeIndex) { + textChapter.getPage(afterIndex - 2)?.recycleRecorders() + } + if (afterIndex < beforeIndex) { + textChapter.getPage(afterIndex + 3)?.recycleRecorders() } } } diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 3334a976c..9d6756a84 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -314,8 +314,8 @@ class HttpReadAloudService : BaseReadAloudService(), pageIndex++ if (pageIndex < textChapter.pageSize) { ReadBook.moveToNextPage() + upTtsProgress(readAloudNumber + i.toInt()) } - upTtsProgress(readAloudNumber + i.toInt()) } delay(sleep) } @@ -360,6 +360,9 @@ class HttpReadAloudService : BaseReadAloudService(), override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) { if (reason == Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED) return + if (reason == Player.MEDIA_ITEM_TRANSITION_REASON_AUTO) { + playErrorNo = 0 + } updateNextPos() upPlayPos() } @@ -371,13 +374,19 @@ class HttpReadAloudService : BaseReadAloudService(), if (playErrorNo >= 5) { toastOnUi("朗读连续5次错误, 最后一次错误代码(${error.localizedMessage})") AppLog.put("朗读连续5次错误, 最后一次错误代码(${error.localizedMessage})", error) - ReadAloud.pause(this) + pauseReadAloud() } else { - updateNextPos() - exoPlayer.seekToNextMediaItem() + deleteCurrentSpeakFile() + downloadAndPlayAudios() } } + private fun deleteCurrentSpeakFile() { + val mediaItem = exoPlayer.currentMediaItem ?: return + val filePath = mediaItem.localConfiguration!!.uri.path!! + File(filePath).delete() + } + override fun aloudServicePendingIntent(actionStr: String): PendingIntent? { return servicePendingIntent(actionStr) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 07877065f..1e7295cbb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -194,7 +194,7 @@ data class TextPage( for (index in textLines.indices) { val textLine = textLines[index] val lineLength = textLine.text.length + if (textLine.isParagraphEnd) 1 else 0 - if (aloudSpanStart > lineStart && aloudSpanStart < lineStart + lineLength) { + if (aloudSpanStart >= lineStart && aloudSpanStart < lineStart + lineLength) { for (i in index - 1 downTo 0) { if (textLines[i].isParagraphEnd) { break