diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index ad49cb3e0..402827cb4 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -5,7 +5,7 @@ object EventBus { const val RECREATE = "RECREATE" const val UP_BOOK = "sourceDebugLog" const val ALOUD_STATE = "aloud_state" - const val TTS_START = "ttsStart" + const val TTS_PROGRESS = "ttsStart" const val TTS_DS = "ttsDs" const val BATTERY_CHANGED = "batteryChanged" const val TIME_CHANGED = "timeChanged" 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 5d34a345c..2cf46831c 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -96,7 +96,7 @@ class HttpReadAloudService : BaseReadAloudService(), mediaPlayer.setDataSource(fd) mediaPlayer.prepareAsync() playingIndex = nowSpeak - postEvent(EventBus.TTS_START, readAloudNumber + 1) + postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) } catch (e: Exception) { e.printStackTrace() } @@ -190,7 +190,7 @@ class HttpReadAloudService : BaseReadAloudService(), ReadBook.moveToNextPage() } } - postEvent(EventBus.TTS_START, readAloudNumber + 1) + postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) } override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 1b1f40bcc..6fd32219d 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -152,7 +152,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener ReadBook.moveToNextPage() } } - postEvent(EventBus.TTS_START, readAloudNumber + 1) + postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) } override fun onDone(s: String) { @@ -169,7 +169,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) { pageIndex++ ReadBook.moveToNextPage() - postEvent(EventBus.TTS_START, readAloudNumber + start) + postEvent(EventBus.TTS_PROGRESS, readAloudNumber + start) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 9b05b7308..53dd7e605 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -501,17 +501,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override fun observeLiveBus() { super.observeLiveBus() - observeEvent(EventBus.ALOUD_STATE) { - if (it == Status.STOP || it == Status.PAUSE) { - ReadBook.curTextChapter?.let { textChapter -> - val page = textChapter.page(ReadBook.durPageIndex) - if (page != null) { - page.removePageAloudSpan() - page_view.upContent() - } - } - } - } observeEvent(EventBus.TIME_CHANGED) { page_view.upTime() } observeEvent(EventBus.BATTERY_CHANGED) { page_view.upBattery(it) } observeEvent(EventBus.OPEN_CHAPTER) { @@ -537,7 +526,18 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo page_view.upContent() } } - observeEventSticky(EventBus.TTS_START) { chapterStart -> + observeEvent(EventBus.ALOUD_STATE) { + if (it == Status.STOP || it == Status.PAUSE) { + ReadBook.curTextChapter?.let { textChapter -> + val page = textChapter.page(ReadBook.durPageIndex) + if (page != null) { + page.removePageAloudSpan() + page_view.upContent() + } + } + } + } + observeEventSticky(EventBus.TTS_PROGRESS) { chapterStart -> launch(IO) { if (BaseReadAloudService.isPlay()) { ReadBook.curTextChapter?.let { textChapter ->