From efdb0f7744a4210f7e890b8242a19a487630b2bb Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 9 Nov 2019 17:01:20 +0800 Subject: [PATCH] up --- .../io/legado/app/service/AudioPlayService.kt | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index 7e2d36be9..1572dfc99 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -58,6 +58,7 @@ class AudioPlayService : BaseService(), private var position = 0 private val dsRunnable: Runnable = Runnable { doDs() } private var mpRunnable: Runnable = Runnable { upPlayProgress() } + private var bookChapter: BookChapter? = null override fun onCreate() { super.onCreate() @@ -165,11 +166,16 @@ class AudioPlayService : BaseService(), */ override fun onPrepared(mp: MediaPlayer?) { if (pause) return - mp?.start() - mp?.seekTo(position) - postEvent(Bus.AUDIO_SIZE, mp?.duration) - handler.removeCallbacks(mpRunnable) - handler.post(mpRunnable) + mp?.let { + mp.start() + mp.seekTo(position) + postEvent(Bus.AUDIO_SIZE, mp.duration) + bookChapter?.let { + it.end = mp.duration.toLong() + } + handler.removeCallbacks(mpRunnable) + handler.post(mpRunnable) + } } /** @@ -231,8 +237,11 @@ class AudioPlayService : BaseService(), launch(IO) { App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> if (index == AudioPlay.durChapterIndex) { + bookChapter = chapter subtitle = chapter.title postEvent(Bus.AUDIO_SUB_TITLE, subtitle) + postEvent(Bus.AUDIO_SIZE, chapter.end?.toInt() ?: 0) + postEvent(Bus.AUDIO_PROGRESS, position) } BookHelp.getContent(book, chapter)?.let { contentLoadFinish(chapter, it) @@ -285,6 +294,7 @@ class AudioPlayService : BaseService(), subtitle = chapter.title url = content play() + loadContent(AudioPlay.durChapterIndex + 1) } }