pull/46/head
kunfei 5 years ago
parent a66a921e1e
commit 9095783fc4
  1. 2
      app/src/main/java/io/legado/app/constant/Action.kt
  2. 12
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  3. 4
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  4. 2
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.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"
}

@ -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)
}

@ -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)
}

@ -66,7 +66,7 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(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)
}
})
}

Loading…
Cancel
Save