pull/46/head
kunfei 5 years ago
parent ca105c81c5
commit 70f2353136
  1. 2
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  2. 21
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt

@ -34,7 +34,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
private fun readAloud(context: Context) { private fun readAloud(context: Context) {
if (ActivityHelp.isExist(AudioPlayActivity::class.java)) { if (ActivityHelp.isExist(AudioPlayActivity::class.java)) {
postEvent(Bus.READ_ALOUD_BUTTON, true) postEvent(Bus.AUDIO_PLAY_BUTTON, true)
} else if (!ActivityHelp.isExist(ReadBookActivity::class.java)) { } else if (!ActivityHelp.isExist(ReadBookActivity::class.java)) {
val intent = Intent(context, ReadBookActivity::class.java) val intent = Intent(context, ReadBookActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

@ -37,13 +37,7 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
private fun initView() { private fun initView() {
fab_play_stop.onClick { fab_play_stop.onClick {
when (status) { playButton()
Status.PLAY -> AudioPlay.pause(this)
Status.PAUSE -> AudioPlay.resume(this)
else -> viewModel.bookData.value?.let {
viewModel.loadContent(it, viewModel.durChapterIndex)
}
}
} }
fab_play_stop.onLongClick { fab_play_stop.onLongClick {
AudioPlay.stop(this) AudioPlay.stop(this)
@ -80,6 +74,16 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
.setAsDrawable(iv_cover) .setAsDrawable(iv_cover)
} }
private fun playButton() {
when (status) {
Status.PLAY -> AudioPlay.pause(this)
Status.PAUSE -> AudioPlay.resume(this)
else -> viewModel.bookData.value?.let {
viewModel.loadContent(it, viewModel.durChapterIndex)
}
}
}
override fun contentLoadFinish(bookChapter: BookChapter, content: String) { override fun contentLoadFinish(bookChapter: BookChapter, content: String) {
AudioPlay.play( AudioPlay.play(
this, this,
@ -94,6 +98,9 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
} }
override fun observeLiveBus() { override fun observeLiveBus() {
observeEvent<Boolean>(Bus.AUDIO_PLAY_BUTTON) {
playButton()
}
observeEvent<Int>(Bus.AUDIO_NEXT) { observeEvent<Int>(Bus.AUDIO_NEXT) {
viewModel.moveToNext() viewModel.moveToNext()
} }

Loading…
Cancel
Save