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 1c6d215bd..74799c8e5 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.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) } diff --git a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt index 35e6a4d1c..e591343a8 100644 --- a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt @@ -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,9 +88,7 @@ object AudioPlay { App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter -> postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title) } - if (isPlay) { - play(context) - } + play(context) } } } @@ -104,7 +99,6 @@ object AudioPlay { if (book.durChapterIndex <= 0) { return@let } - pause(context) durChapterIndex-- durPageIndex = 0 book.durChapterIndex = durChapterIndex @@ -113,9 +107,7 @@ object AudioPlay { App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter -> postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title) } - if (AudioPlayService.isRun) { - play(context) - } + play(context) } } } @@ -126,7 +118,6 @@ object AudioPlay { if (book.durChapterIndex >= book.totalChapterNum) { return@let } - pause(context) durChapterIndex++ durPageIndex = 0 book.durChapterIndex = durChapterIndex @@ -135,9 +126,7 @@ object AudioPlay { App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter -> postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title) } - if (AudioPlayService.isRun) { - play(context) - } + play(context) } } }