mirror of
https://github.com/gedoor/legado.git
synced 2024-07-04 23:36:56 +08:00
优化
This commit is contained in:
parent
752999b43b
commit
c562c40689
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<HttpReadAloudService>(actionStr)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user