pull/48/head
kunfei 5 years ago
parent 2265f7bd1c
commit 8601e24be8
  1. 2
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  2. 11
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt

@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.constant.Action import io.legado.app.constant.Action
import io.legado.app.constant.Status
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.service.AudioPlayService import io.legado.app.service.AudioPlayService
@ -11,6 +12,7 @@ import io.legado.app.service.AudioPlayService
object AudioPlay { object AudioPlay {
var titleData = MutableLiveData<String>() var titleData = MutableLiveData<String>()
var coverData = MutableLiveData<String>() var coverData = MutableLiveData<String>()
var status = Status.STOP
var book: Book? = null var book: Book? = null
var inBookshelf = false var inBookshelf = false
var chapterSize = 0 var chapterSize = 0

@ -37,7 +37,6 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
private var requestCodeChapter = 8461 private var requestCodeChapter = 8461
private var adjustProgress = false private var adjustProgress = false
private var status = Status.STOP
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
@ -104,7 +103,7 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
} }
private fun playButton() { private fun playButton() {
when (status) { when (AudioPlay.status) {
Status.PLAY -> AudioPlay.pause(this) Status.PLAY -> AudioPlay.pause(this)
Status.PAUSE -> AudioPlay.resume(this) Status.PAUSE -> AudioPlay.resume(this)
else -> AudioPlay.play(this) else -> AudioPlay.play(this)
@ -127,7 +126,7 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
if (status != Status.PLAY) { if (AudioPlay.status != Status.PLAY) {
AudioPlay.stop(this) AudioPlay.stop(this)
} }
} }
@ -149,9 +148,9 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
observeEvent<Boolean>(Bus.AUDIO_PLAY_BUTTON) { observeEvent<Boolean>(Bus.AUDIO_PLAY_BUTTON) {
playButton() playButton()
} }
observeEvent<Int>(Bus.AUDIO_STATE) { observeEventSticky<Int>(Bus.AUDIO_STATE) {
status = it AudioPlay.status = it
if (status == Status.PLAY) { if (it == Status.PLAY) {
fab_play_stop.setImageResource(R.drawable.ic_pause_24dp) fab_play_stop.setImageResource(R.drawable.ic_pause_24dp)
} else { } else {
fab_play_stop.setImageResource(R.drawable.ic_play_24dp) fab_play_stop.setImageResource(R.drawable.ic_play_24dp)

Loading…
Cancel
Save