pull/48/head
kunfei 5 years ago
parent f7cd351081
commit bc4e782566
  1. 5
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -104,6 +104,7 @@ class AudioPlayService : BaseService(),
mediaSessionCompat?.release() mediaSessionCompat?.release()
unregisterReceiver(broadcastReceiver) unregisterReceiver(broadcastReceiver)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
AudioPlay.status = Status.STOP
postEvent(Bus.AUDIO_STATE, Status.STOP) postEvent(Bus.AUDIO_STATE, Status.STOP)
} }
@ -112,6 +113,7 @@ class AudioPlayService : BaseService(),
upNotification() upNotification()
if (requestFocus()) { if (requestFocus()) {
try { try {
AudioPlay.status = Status.PLAY
postEvent(Bus.AUDIO_STATE, Status.PLAY) postEvent(Bus.AUDIO_STATE, Status.PLAY)
mediaPlayer.reset() mediaPlayer.reset()
mediaPlayer.setDataSource(url) mediaPlayer.setDataSource(url)
@ -132,6 +134,7 @@ class AudioPlayService : BaseService(),
position = mediaPlayer.currentPosition position = mediaPlayer.currentPosition
mediaPlayer.pause() mediaPlayer.pause()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED)
AudioPlay.status = Status.PAUSE
postEvent(Bus.AUDIO_STATE, Status.PAUSE) postEvent(Bus.AUDIO_STATE, Status.PAUSE)
upNotification() upNotification()
} }
@ -143,6 +146,7 @@ class AudioPlayService : BaseService(),
handler.removeCallbacks(mpRunnable) handler.removeCallbacks(mpRunnable)
handler.postDelayed(mpRunnable, 1000) handler.postDelayed(mpRunnable, 1000)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
AudioPlay.status = Status.PLAY
postEvent(Bus.AUDIO_STATE, Status.PLAY) postEvent(Bus.AUDIO_STATE, Status.PLAY)
upNotification() upNotification()
} }
@ -171,6 +175,7 @@ class AudioPlayService : BaseService(),
* 播放出错 * 播放出错
*/ */
override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean {
AudioPlay.status = Status.STOP
postEvent(Bus.AUDIO_STATE, Status.STOP) postEvent(Bus.AUDIO_STATE, Status.STOP)
launch { launch {
toast("error: $what $extra $url") toast("error: $what $extra $url")

Loading…
Cancel
Save