pull/508/head
gedoor 4 years ago
parent 63b48b620a
commit f3ef37edff
  1. 13
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  2. 11
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt

@ -122,8 +122,8 @@ class AudioPlayService : BaseService(),
upNotification()
if (requestFocus()) {
try {
AudioPlay.status = Status.PLAY
postEvent(EventBus.AUDIO_STATE, Status.PLAY)
AudioPlay.status = Status.STOP
postEvent(EventBus.AUDIO_STATE, Status.STOP)
mediaPlayer.reset()
val analyzeUrl =
AnalyzeUrl(url, headerMapF = AudioPlay.headers(), useWebView = true)
@ -197,13 +197,14 @@ class AudioPlayService : BaseService(),
/**
* 加载完成
*/
override fun onPrepared(mp: MediaPlayer?) {
if (pause) return
override fun onPrepared(mp: MediaPlayer) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mediaPlayer.playbackParams = mediaPlayer.playbackParams.apply { speed = playSpeed }
} else {
mediaPlayer.start()
}
AudioPlay.status = Status.PLAY
postEvent(EventBus.AUDIO_STATE, Status.PLAY)
mediaPlayer.seekTo(position)
postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration)
bookChapter?.let {
@ -216,7 +217,7 @@ class AudioPlayService : BaseService(),
/**
* 播放出错
*/
override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean {
override fun onError(mp: MediaPlayer, what: Int, extra: Int): Boolean {
if (!mediaPlayer.isPlaying) {
AudioPlay.status = Status.STOP
postEvent(EventBus.AUDIO_STATE, Status.STOP)
@ -228,7 +229,7 @@ class AudioPlayService : BaseService(),
/**
* 播放结束
*/
override fun onCompletion(mp: MediaPlayer?) {
override fun onCompletion(mp: MediaPlayer) {
handler.removeCallbacks(mpRunnable)
AudioPlay.next(this)
}

@ -80,9 +80,6 @@ object AudioPlay {
fun skipTo(context: Context, index: Int) {
Coroutine.async {
book?.let { book ->
val isPlay = !AudioPlayService.pause
pause(context)
status = Status.STOP
durChapterIndex = index
durPageIndex = 0
book.durChapterIndex = durChapterIndex
@ -91,12 +88,10 @@ object AudioPlay {
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->
postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title)
}
if (isPlay) {
play(context)
}
}
}
}
fun prev(context: Context) {
Coroutine.async {
@ -104,7 +99,6 @@ object AudioPlay {
if (book.durChapterIndex <= 0) {
return@let
}
pause(context)
durChapterIndex--
durPageIndex = 0
book.durChapterIndex = durChapterIndex
@ -113,12 +107,10 @@ object AudioPlay {
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->
postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title)
}
if (AudioPlayService.isRun) {
play(context)
}
}
}
}
fun next(context: Context) {
Coroutine.async {
@ -126,7 +118,6 @@ object AudioPlay {
if (book.durChapterIndex >= book.totalChapterNum) {
return@let
}
pause(context)
durChapterIndex++
durPageIndex = 0
book.durChapterIndex = durChapterIndex
@ -135,12 +126,10 @@ object AudioPlay {
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->
postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title)
}
if (AudioPlayService.isRun) {
play(context)
}
}
}
}
fun saveRead() {
Coroutine.async {

Loading…
Cancel
Save