pull/48/head
kunfei 5 years ago
parent 9d1b46b591
commit efdb0f7744
  1. 20
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -58,6 +58,7 @@ class AudioPlayService : BaseService(),
private var position = 0 private var position = 0
private val dsRunnable: Runnable = Runnable { doDs() } private val dsRunnable: Runnable = Runnable { doDs() }
private var mpRunnable: Runnable = Runnable { upPlayProgress() } private var mpRunnable: Runnable = Runnable { upPlayProgress() }
private var bookChapter: BookChapter? = null
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
@ -165,11 +166,16 @@ class AudioPlayService : BaseService(),
*/ */
override fun onPrepared(mp: MediaPlayer?) { override fun onPrepared(mp: MediaPlayer?) {
if (pause) return if (pause) return
mp?.start() mp?.let {
mp?.seekTo(position) mp.start()
postEvent(Bus.AUDIO_SIZE, mp?.duration) mp.seekTo(position)
handler.removeCallbacks(mpRunnable) postEvent(Bus.AUDIO_SIZE, mp.duration)
handler.post(mpRunnable) bookChapter?.let {
it.end = mp.duration.toLong()
}
handler.removeCallbacks(mpRunnable)
handler.post(mpRunnable)
}
} }
/** /**
@ -231,8 +237,11 @@ class AudioPlayService : BaseService(),
launch(IO) { launch(IO) {
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter ->
if (index == AudioPlay.durChapterIndex) { if (index == AudioPlay.durChapterIndex) {
bookChapter = chapter
subtitle = chapter.title subtitle = chapter.title
postEvent(Bus.AUDIO_SUB_TITLE, subtitle) postEvent(Bus.AUDIO_SUB_TITLE, subtitle)
postEvent(Bus.AUDIO_SIZE, chapter.end?.toInt() ?: 0)
postEvent(Bus.AUDIO_PROGRESS, position)
} }
BookHelp.getContent(book, chapter)?.let { BookHelp.getContent(book, chapter)?.let {
contentLoadFinish(chapter, it) contentLoadFinish(chapter, it)
@ -285,6 +294,7 @@ class AudioPlayService : BaseService(),
subtitle = chapter.title subtitle = chapter.title
url = content url = content
play() play()
loadContent(AudioPlay.durChapterIndex + 1)
} }
} }

Loading…
Cancel
Save