From f49247998a10182e5e5cbc7467bbcf42b04d81cf Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 24 Nov 2019 19:30:15 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/constant/Action.kt | 1 + .../io/legado/app/service/AudioPlayService.kt | 8 +++++--- .../java/io/legado/app/service/help/AudioPlay.kt | 8 ++++++++ .../io/legado/app/ui/audio/AudioPlayActivity.kt | 15 +++++++++++++-- app/src/main/res/layout/activity_audio_play.xml | 2 +- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/Action.kt b/app/src/main/java/io/legado/app/constant/Action.kt index 7af394608..297b38714 100644 --- a/app/src/main/java/io/legado/app/constant/Action.kt +++ b/app/src/main/java/io/legado/app/constant/Action.kt @@ -12,6 +12,7 @@ object Action { const val nextParagraph = "nextParagraph" const val upTtsSpeechRate = "upTtsSpeechRate" const val adjustProgress = "adjustProgress" + const val adjustSpeed = "adjustSpeed" const val prev = "prev" const val next = "next" const val moveTo = "moveTo" 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 ab5baab7f..2b1ca4b9b 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -88,6 +88,7 @@ class AudioPlayService : BaseService(), Action.resume -> resume() Action.prev -> moveToPrev() Action.next -> moveToNext() + Action.adjustSpeed -> upSpeed() Action.moveTo -> moveTo(intent.getIntExtra("index", AudioPlay.durChapterIndex)) Action.addTimer -> addTimer() Action.setTimer -> setTimer(intent.getIntExtra("minute", 0)) @@ -160,12 +161,12 @@ class AudioPlayService : BaseService(), } } - private fun changeplayerSpeed(speed: Float) { + private fun upSpeed() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (mediaPlayer.isPlaying) { - mediaPlayer.playbackParams = mediaPlayer.playbackParams.setSpeed(speed) + mediaPlayer.playbackParams = mediaPlayer.playbackParams.setSpeed(AudioPlay.speed) } else { - mediaPlayer.playbackParams = mediaPlayer.playbackParams.setSpeed(speed) + mediaPlayer.playbackParams = mediaPlayer.playbackParams.setSpeed(AudioPlay.speed) mediaPlayer.pause() } } @@ -179,6 +180,7 @@ 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 40fd0ca35..8e00da703 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 @@ -52,6 +52,14 @@ object AudioPlay { } } + fun adjustSpeed(context: Context) { + if (AudioPlayService.isRun) { + val intent = Intent(context, AudioPlayService::class.java) + intent.action = Action.adjustSpeed + context.startService(intent) + } + } + fun adjustProgress(context: Context, position: Int) { if (AudioPlayService.isRun) { val intent = Intent(context, AudioPlayService::class.java) 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 05d2fb333..d64c2c190 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,6 +46,7 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a } private fun initView() { + tv_speed.text = AudioPlay.speed.toString() fab_play_stop.onClick { playButton() } @@ -86,10 +87,20 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a iv_fast_forward.invisible() } iv_fast_forward.onClick { - + AudioPlay.speed = AudioPlay.speed + 0.1f + tv_speed.text = AudioPlay.speed.toString() + if (AudioPlay.speed == 1f) { + tv_speed.invisible() + } else { + tv_speed.visible() + } + AudioPlay.adjustSpeed(this) } iv_fast_rewind.onClick { - + if (AudioPlay.speed > 0.5f) { + AudioPlay.speed = AudioPlay.speed - 0.1f + } + AudioPlay.adjustSpeed(this) } } diff --git a/app/src/main/res/layout/activity_audio_play.xml b/app/src/main/res/layout/activity_audio_play.xml index 76897d195..ef9532a16 100644 --- a/app/src/main/res/layout/activity_audio_play.xml +++ b/app/src/main/res/layout/activity_audio_play.xml @@ -29,7 +29,7 @@ app:layout_constraintTop_toBottomOf="@+id/title_bar" app:layout_constraintBottom_toBottomOf="parent" /> -