diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index 38f782615..17cad91ef 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.kt @@ -17,4 +17,5 @@ object Bus { const val AUDIO_STATE = "audioState" const val AUDIO_PROGRESS = "audioProgress" const val AUDIO_SIZE = "audioSize" + const val AUDIO_SPEED = "audioSpeed" } \ No newline at end of file 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 c153d260d..b46647f28 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -88,7 +88,7 @@ class AudioPlayService : BaseService(), Action.resume -> resume() Action.prev -> moveToPrev() Action.next -> moveToNext() - Action.adjustSpeed -> upSpeed() + Action.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f)) Action.moveTo -> moveTo(intent.getIntExtra("index", AudioPlay.durChapterIndex)) Action.addTimer -> addTimer() Action.setTimer -> setTimer(intent.getIntExtra("minute", 0)) @@ -145,7 +145,6 @@ class AudioPlayService : BaseService(), pause = false mediaPlayer.start() mediaPlayer.seekTo(position) - upSpeed() handler.removeCallbacks(mpRunnable) handler.postDelayed(mpRunnable, 1000) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) @@ -162,12 +161,14 @@ class AudioPlayService : BaseService(), } } - private fun upSpeed() { + private fun upSpeed(adjust: Float) { kotlin.runCatching { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (mediaPlayer.isPlaying) { - mediaPlayer.playbackParams = - mediaPlayer.playbackParams.setSpeed(AudioPlay.speed) + with(mediaPlayer) { + if (isPlaying) { + playbackParams = playbackParams.apply { speed += adjust } + } + postEvent(Bus.AUDIO_SPEED, playbackParams.speed) } } } @@ -181,7 +182,6 @@ class AudioPlayService : BaseService(), mp?.let { mp.start() mp.seekTo(position) - upSpeed() postEvent(Bus.AUDIO_SIZE, mp.duration) bookChapter?.let { it.end = mp.duration.toLong() 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 ae0007e21..98e62606d 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 @@ -18,7 +18,6 @@ object AudioPlay { var chapterSize = 0 var durChapterIndex = 0 var durPageIndex = 0 - var speed: Float = 1f var webBook: WebBook? = null val loadingChapters = arrayListOf() diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index f3fd0034f..0114629b8 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -46,7 +46,6 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a } private fun initView() { - tv_speed.text = AudioPlay.speed.toString() fab_play_stop.onClick { playButton() } @@ -180,6 +179,9 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a if (!adjustProgress) player_progress.progress = it tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") } + observeEventSticky(Bus.AUDIO_SPEED) { + tv_speed.text = String.format("%.1f", it) + } } } \ No newline at end of file