From 9b4cae3921b05ea49a77708866c40a26aeb979b8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 24 Nov 2019 19:57:42 +0800 Subject: [PATCH] up --- .../java/io/legado/app/service/AudioPlayService.kt | 9 ++++++--- .../java/io/legado/app/service/help/AudioPlay.kt | 3 ++- .../io/legado/app/ui/audio/AudioPlayActivity.kt | 14 ++------------ 3 files changed, 10 insertions(+), 16 deletions(-) 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 f431a7c40..c153d260d 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -163,9 +163,12 @@ class AudioPlayService : BaseService(), } private fun upSpeed() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (mediaPlayer.isPlaying) { - mediaPlayer.playbackParams = mediaPlayer.playbackParams.setSpeed(AudioPlay.speed) + kotlin.runCatching { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (mediaPlayer.isPlaying) { + mediaPlayer.playbackParams = + mediaPlayer.playbackParams.setSpeed(AudioPlay.speed) + } } } } 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 8e00da703..ae0007e21 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,10 +52,11 @@ object AudioPlay { } } - fun adjustSpeed(context: Context) { + fun adjustSpeed(context: Context, adjust: Float) { if (AudioPlayService.isRun) { val intent = Intent(context, AudioPlayService::class.java) intent.action = Action.adjustSpeed + intent.putExtra("adjust", adjust) context.startService(intent) } } 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 d64c2c190..f3fd0034f 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 @@ -87,20 +87,10 @@ 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) + AudioPlay.adjustSpeed(this, 0.1f) } iv_fast_rewind.onClick { - if (AudioPlay.speed > 0.5f) { - AudioPlay.speed = AudioPlay.speed - 0.1f - } - AudioPlay.adjustSpeed(this) + AudioPlay.adjustSpeed(this, -0.1f) } }