diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index b18fec509..12e2cee93 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/06/03** * zh-TW translation by david082321 +* 修复音频播放时播放速度调节会再下一章失效的bug **2020/05/31** * 更新到android studio 4.0 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 986e7c4ed..0efe85374 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -63,6 +63,7 @@ class AudioPlayService : BaseService(), private val dsRunnable: Runnable = Runnable { doDs() } private var mpRunnable: Runnable = Runnable { upPlayProgress() } private var bookChapter: BookChapter? = null + private var playSpeed: Float = 1f override fun onCreate() { super.onCreate() @@ -95,7 +96,12 @@ class AudioPlayService : BaseService(), IntentAction.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f)) IntentAction.addTimer -> addTimer() IntentAction.setTimer -> setTimer(intent.getIntExtra("minute", 0)) - IntentAction.adjustProgress -> adjustProgress(intent.getIntExtra("position", position)) + IntentAction.adjustProgress -> adjustProgress( + intent.getIntExtra( + "position", + position + ) + ) else -> stopSelf() } } @@ -174,12 +180,12 @@ class AudioPlayService : BaseService(), private fun upSpeed(adjust: Float) { kotlin.runCatching { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - with(mediaPlayer) { - if (isPlaying) { - playbackParams = playbackParams.apply { speed += adjust } - } - postEvent(EventBus.AUDIO_SPEED, playbackParams.speed) + playSpeed += adjust + if (mediaPlayer.isPlaying) { + mediaPlayer.playbackParams = + mediaPlayer.playbackParams.apply { speed = playSpeed } } + postEvent(EventBus.AUDIO_SPEED, playSpeed) } } } @@ -189,7 +195,11 @@ class AudioPlayService : BaseService(), */ override fun onPrepared(mp: MediaPlayer?) { if (pause) return - mediaPlayer.start() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + mediaPlayer.playbackParams = mediaPlayer.playbackParams.apply { speed = playSpeed } + } else { + mediaPlayer.start() + } mediaPlayer.seekTo(position) postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration) bookChapter?.let {