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 b4cc98183..2520d1c90 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 @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import androidx.lifecycle.MutableLiveData import io.legado.app.constant.Action +import io.legado.app.constant.Status import io.legado.app.data.entities.Book import io.legado.app.model.WebBook import io.legado.app.service.AudioPlayService @@ -11,6 +12,7 @@ import io.legado.app.service.AudioPlayService object AudioPlay { var titleData = MutableLiveData() var coverData = MutableLiveData() + var status = Status.STOP var book: Book? = null var inBookshelf = false var chapterSize = 0 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 87e713c1f..fd9a2549c 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,7 +37,6 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a private var requestCodeChapter = 8461 private var adjustProgress = false - private var status = Status.STOP override fun onActivityCreated(savedInstanceState: Bundle?) { setSupportActionBar(toolbar) @@ -104,7 +103,7 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a } private fun playButton() { - when (status) { + when (AudioPlay.status) { Status.PLAY -> AudioPlay.pause(this) Status.PAUSE -> AudioPlay.resume(this) else -> AudioPlay.play(this) @@ -127,7 +126,7 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a override fun onDestroy() { super.onDestroy() - if (status != Status.PLAY) { + if (AudioPlay.status != Status.PLAY) { AudioPlay.stop(this) } } @@ -149,9 +148,9 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a observeEvent(Bus.AUDIO_PLAY_BUTTON) { playButton() } - observeEvent(Bus.AUDIO_STATE) { - status = it - if (status == Status.PLAY) { + observeEventSticky(Bus.AUDIO_STATE) { + AudioPlay.status = it + if (it == Status.PLAY) { fab_play_stop.setImageResource(R.drawable.ic_pause_24dp) } else { fab_play_stop.setImageResource(R.drawable.ic_play_24dp)