pull/46/head
kunfei 5 years ago
parent 35d049f65a
commit 60112a7ecb
  1. 4
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -64,6 +64,7 @@ class AudioPlayService : BaseService(),
mediaPlayer.setOnCompletionListener(this) mediaPlayer.setOnCompletionListener(this)
initMediaSession() initMediaSession()
initBroadcastReceiver() initBroadcastReceiver()
upNotification()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
launch(IO) { launch(IO) {
while (isActive) { while (isActive) {
@ -95,6 +96,7 @@ class AudioPlayService : BaseService(),
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
isRun = false isRun = false
mediaPlayer.release()
mediaSessionCompat?.release() mediaSessionCompat?.release()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
postEvent(Bus.AUDIO_STATE, Status.STOP) postEvent(Bus.AUDIO_STATE, Status.STOP)
@ -114,6 +116,7 @@ class AudioPlayService : BaseService(),
mediaPlayer.pause() mediaPlayer.pause()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED)
postEvent(Bus.AUDIO_STATE, Status.PAUSE) postEvent(Bus.AUDIO_STATE, Status.PAUSE)
upNotification()
} }
private fun resume() { private fun resume() {
@ -121,6 +124,7 @@ class AudioPlayService : BaseService(),
mediaPlayer.start() mediaPlayer.start()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
postEvent(Bus.AUDIO_STATE, Status.PLAY) postEvent(Bus.AUDIO_STATE, Status.PLAY)
upNotification()
} }
override fun onPrepared(mp: MediaPlayer?) { override fun onPrepared(mp: MediaPlayer?) {

Loading…
Cancel
Save