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

@ -157,7 +157,6 @@ 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 {
@ -178,19 +177,13 @@ 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
mediaPlayer.start() mediaPlayer.start()
if (!isM3U8()) { mediaPlayer.seekTo(position)
mediaPlayer.seekTo(position)
}
postEvent(Bus.AUDIO_SIZE, mediaPlayer.duration) postEvent(Bus.AUDIO_SIZE, mediaPlayer.duration)
bookChapter?.let { bookChapter?.let {
it.end = mediaPlayer.duration.toLong() it.end = mediaPlayer.duration.toLong()
@ -203,10 +196,10 @@ class AudioPlayService : BaseService(),
* 播放出错 * 播放出错
*/ */
override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean {
AudioPlay.status = Status.STOP if (!mediaPlayer.isPlaying) {
postEvent(Bus.AUDIO_STATE, Status.STOP) AudioPlay.status = Status.STOP
launch { postEvent(Bus.AUDIO_STATE, Status.STOP)
toast("error: $what $extra $url") launch { toast("error: $what $extra $url") }
} }
return true return true
} }

Loading…
Cancel
Save