diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 586d13423..1df892cda 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -34,7 +34,7 @@ class MediaButtonReceiver : BroadcastReceiver() { private fun readAloud(context: Context) { 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)) { val intent = Intent(context, ReadBookActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 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 092a49c09..73ed2b909 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 @@ -37,13 +37,7 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a private fun initView() { fab_play_stop.onClick { - when (status) { - Status.PLAY -> AudioPlay.pause(this) - Status.PAUSE -> AudioPlay.resume(this) - else -> viewModel.bookData.value?.let { - viewModel.loadContent(it, viewModel.durChapterIndex) - } - } + playButton() } fab_play_stop.onLongClick { AudioPlay.stop(this) @@ -80,6 +74,16 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a .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) { AudioPlay.play( this, @@ -94,6 +98,9 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a } override fun observeLiveBus() { + observeEvent(Bus.AUDIO_PLAY_BUTTON) { + playButton() + } observeEvent(Bus.AUDIO_NEXT) { viewModel.moveToNext() }