pull/49/head
kunfei 5 years ago
parent 9b4cae3921
commit 4edf35fc0f
  1. 1
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 14
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  3. 1
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  4. 4
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt

@ -17,4 +17,5 @@ object Bus {
const val AUDIO_STATE = "audioState" const val AUDIO_STATE = "audioState"
const val AUDIO_PROGRESS = "audioProgress" const val AUDIO_PROGRESS = "audioProgress"
const val AUDIO_SIZE = "audioSize" const val AUDIO_SIZE = "audioSize"
const val AUDIO_SPEED = "audioSpeed"
} }

@ -88,7 +88,7 @@ class AudioPlayService : BaseService(),
Action.resume -> resume() Action.resume -> resume()
Action.prev -> moveToPrev() Action.prev -> moveToPrev()
Action.next -> moveToNext() Action.next -> moveToNext()
Action.adjustSpeed -> upSpeed() Action.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f))
Action.moveTo -> moveTo(intent.getIntExtra("index", AudioPlay.durChapterIndex)) Action.moveTo -> moveTo(intent.getIntExtra("index", AudioPlay.durChapterIndex))
Action.addTimer -> addTimer() Action.addTimer -> addTimer()
Action.setTimer -> setTimer(intent.getIntExtra("minute", 0)) Action.setTimer -> setTimer(intent.getIntExtra("minute", 0))
@ -145,7 +145,6 @@ class AudioPlayService : BaseService(),
pause = false pause = false
mediaPlayer.start() mediaPlayer.start()
mediaPlayer.seekTo(position) mediaPlayer.seekTo(position)
upSpeed()
handler.removeCallbacks(mpRunnable) handler.removeCallbacks(mpRunnable)
handler.postDelayed(mpRunnable, 1000) handler.postDelayed(mpRunnable, 1000)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
@ -162,12 +161,14 @@ class AudioPlayService : BaseService(),
} }
} }
private fun upSpeed() { private fun upSpeed(adjust: Float) {
kotlin.runCatching { kotlin.runCatching {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (mediaPlayer.isPlaying) { with(mediaPlayer) {
mediaPlayer.playbackParams = if (isPlaying) {
mediaPlayer.playbackParams.setSpeed(AudioPlay.speed) playbackParams = playbackParams.apply { speed += adjust }
}
postEvent(Bus.AUDIO_SPEED, playbackParams.speed)
} }
} }
} }
@ -181,7 +182,6 @@ class AudioPlayService : BaseService(),
mp?.let { mp?.let {
mp.start() mp.start()
mp.seekTo(position) mp.seekTo(position)
upSpeed()
postEvent(Bus.AUDIO_SIZE, mp.duration) postEvent(Bus.AUDIO_SIZE, mp.duration)
bookChapter?.let { bookChapter?.let {
it.end = mp.duration.toLong() it.end = mp.duration.toLong()

@ -18,7 +18,6 @@ object AudioPlay {
var chapterSize = 0 var chapterSize = 0
var durChapterIndex = 0 var durChapterIndex = 0
var durPageIndex = 0 var durPageIndex = 0
var speed: Float = 1f
var webBook: WebBook? = null var webBook: WebBook? = null
val loadingChapters = arrayListOf<Int>() val loadingChapters = arrayListOf<Int>()

@ -46,7 +46,6 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
} }
private fun initView() { private fun initView() {
tv_speed.text = AudioPlay.speed.toString()
fab_play_stop.onClick { fab_play_stop.onClick {
playButton() playButton()
} }
@ -180,6 +179,9 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
if (!adjustProgress) player_progress.progress = it if (!adjustProgress) player_progress.progress = it
tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss")
} }
observeEventSticky<Float>(Bus.AUDIO_SPEED) {
tv_speed.text = String.format("%.1f", it)
}
} }
} }
Loading…
Cancel
Save