From 9095783fc4e0a2ba8cc650afc2d0c781f42eb055 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 4 Nov 2019 16:54:14 +0800 Subject: [PATCH] up --- app/src/main/java/io/legado/app/constant/Action.kt | 2 +- .../java/io/legado/app/service/AudioPlayService.kt | 12 ++++++++++++ .../java/io/legado/app/service/help/AudioPlay.kt | 4 ++-- .../java/io/legado/app/ui/audio/AudioPlayActivity.kt | 2 +- 4 files changed, 16 insertions(+), 4 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 3a73365d2..51ca3ae0f 100644 --- a/app/src/main/java/io/legado/app/constant/Action.kt +++ b/app/src/main/java/io/legado/app/constant/Action.kt @@ -11,5 +11,5 @@ object Action { const val prevParagraph = "prevParagraph" const val nextParagraph = "nextParagraph" const val upTtsSpeechRate = "upTtsSpeechRate" - const val upProgress = "upProgress" + const val adjustProgress = "adjustProgress" } \ 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 ab0dbc1bc..0ecb3571b 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -78,6 +78,7 @@ class AudioPlayService : BaseService(), Action.resume -> resume() Action.addTimer -> addTimer() Action.setTimer -> setTimer(intent.getIntExtra("minute", 0)) + Action.adjustProgress -> adjustProgress(intent.getIntExtra("position", position)) else -> stopSelf() } } @@ -107,6 +108,7 @@ class AudioPlayService : BaseService(), private fun pause(pause: Boolean) { this.pause = pause + position = mediaPlayer.currentPosition mediaPlayer.pause() upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) postEvent(Bus.AUDIO_STATE, Status.PAUSE) @@ -116,14 +118,24 @@ class AudioPlayService : BaseService(), private fun resume() { pause = false mediaPlayer.start() + mediaPlayer.seekTo(position) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) postEvent(Bus.AUDIO_STATE, Status.PLAY) upNotification() } + private fun adjustProgress(position: Int) { + if (mediaPlayer.isPlaying) { + mediaPlayer.seekTo(position) + } else { + this.position = position + } + } + override fun onPrepared(mp: MediaPlayer?) { if (pause) return mp?.start() + mp?.seekTo(position) postEvent(Bus.AUDIO_SIZE, mp?.duration) handler.post(mpRunnable) } 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 fefd33dab..48d3f5b15 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 @@ -41,10 +41,10 @@ object AudioPlay { } } - fun upProgress(context: Context, position: Int) { + fun adjustProgress(context: Context, position: Int) { if (AudioPlayService.isRun) { val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.upProgress + intent.action = Action.adjustProgress intent.putExtra("position", position) 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 c22ed4784..092a49c09 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 @@ -66,7 +66,7 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a override fun onStopTrackingTouch(seekBar: SeekBar?) { adjustProgress = false - AudioPlay.upProgress(this@AudioPlayActivity, player_progress.progress) + AudioPlay.adjustProgress(this@AudioPlayActivity, player_progress.progress) } }) }