pull/46/head
kunfei 5 years ago
parent ecc20d0be1
commit c88309b9d1
  1. 5
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -19,6 +19,7 @@ import io.legado.app.base.BaseService
import io.legado.app.constant.Action import io.legado.app.constant.Action
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.constant.Status
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.help.MediaHelp import io.legado.app.help.MediaHelp
import io.legado.app.receiver.MediaButtonReceiver import io.legado.app.receiver.MediaButtonReceiver
@ -96,10 +97,12 @@ class AudioPlayService : BaseService(),
isRun = false isRun = false
mediaSessionCompat?.release() mediaSessionCompat?.release()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
postEvent(Bus.AUDIO_STATE, Status.STOP)
} }
private fun play(url: String) { private fun play(url: String) {
if (requestFocus()) { if (requestFocus()) {
postEvent(Bus.AUDIO_STATE, Status.PLAY)
mediaPlayer.reset() mediaPlayer.reset()
mediaPlayer.setDataSource(url) mediaPlayer.setDataSource(url)
mediaPlayer.prepareAsync() mediaPlayer.prepareAsync()
@ -110,12 +113,14 @@ class AudioPlayService : BaseService(),
this.pause = pause this.pause = pause
mediaPlayer.pause() mediaPlayer.pause()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED)
postEvent(Bus.AUDIO_STATE, Status.PAUSE)
} }
private fun resume() { private fun resume() {
pause = false pause = false
mediaPlayer.start() mediaPlayer.start()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
postEvent(Bus.AUDIO_STATE, Status.PLAY)
} }
override fun onPrepared(mp: MediaPlayer?) { override fun onPrepared(mp: MediaPlayer?) {

Loading…
Cancel
Save