pull/63/head
kunfei 5 years ago
parent 6506a887b9
commit 8b0d369a94
  1. 17
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -157,6 +157,7 @@ class AudioPlayService : BaseService(),
} }
private fun adjustProgress(position: Int) { private fun adjustProgress(position: Int) {
if (isM3U8()) return
if (mediaPlayer.isPlaying) { if (mediaPlayer.isPlaying) {
mediaPlayer.seekTo(position) mediaPlayer.seekTo(position)
} else { } else {
@ -177,22 +178,26 @@ class AudioPlayService : BaseService(),
} }
} }
private fun isM3U8(): Boolean {
return url.endsWith("m3u8")
}
/** /**
* 加载完成 * 加载完成
*/ */
override fun onPrepared(mp: MediaPlayer?) { override fun onPrepared(mp: MediaPlayer?) {
if (pause) return if (pause) return
mp?.let { mediaPlayer.start()
mp.start() if (!isM3U8()) {
mp.seekTo(position) mediaPlayer.seekTo(position)
postEvent(Bus.AUDIO_SIZE, mp.duration) }
postEvent(Bus.AUDIO_SIZE, mediaPlayer.duration)
bookChapter?.let { bookChapter?.let {
it.end = mp.duration.toLong() it.end = mediaPlayer.duration.toLong()
} }
handler.removeCallbacks(mpRunnable) handler.removeCallbacks(mpRunnable)
handler.post(mpRunnable) handler.post(mpRunnable)
} }
}
/** /**
* 播放出错 * 播放出错

Loading…
Cancel
Save