pull/48/head
kunfei 5 years ago
parent 791ceeeea0
commit 863fe96ba5
  1. 12
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -50,6 +50,7 @@ class AudioPlayService : BaseService(),
private val mediaPlayer = MediaPlayer() private val mediaPlayer = MediaPlayer()
private var mediaSessionCompat: MediaSessionCompat? = null private var mediaSessionCompat: MediaSessionCompat? = null
private var broadcastReceiver: BroadcastReceiver? = null private var broadcastReceiver: BroadcastReceiver? = null
private var url: String = ""
private var position = 0 private var position = 0
private val dsRunnable: Runnable = Runnable { doDs() } private val dsRunnable: Runnable = Runnable { doDs() }
private var mpRunnable: Runnable = Runnable { upPlayProgress() } private var mpRunnable: Runnable = Runnable { upPlayProgress() }
@ -75,7 +76,8 @@ class AudioPlayService : BaseService(),
title = intent.getStringExtra("title") ?: "" title = intent.getStringExtra("title") ?: ""
subtitle = intent.getStringExtra("subtitle") ?: "" subtitle = intent.getStringExtra("subtitle") ?: ""
position = intent.getIntExtra("position", 0) position = intent.getIntExtra("position", 0)
play(intent.getStringExtra("url")) url = intent.getStringExtra("url")
play()
} }
Action.pause -> pause(true) Action.pause -> pause(true)
Action.resume -> resume() Action.resume -> resume()
@ -100,7 +102,7 @@ class AudioPlayService : BaseService(),
postEvent(Bus.AUDIO_STATE, Status.STOP) postEvent(Bus.AUDIO_STATE, Status.STOP)
} }
private fun play(url: String) { private fun play() {
upNotification() upNotification()
if (requestFocus()) { if (requestFocus()) {
try { try {
@ -147,6 +149,9 @@ class AudioPlayService : BaseService(),
} }
} }
/**
* 加载完成
*/
override fun onPrepared(mp: MediaPlayer?) { override fun onPrepared(mp: MediaPlayer?) {
if (pause) return if (pause) return
mp?.start() mp?.start()
@ -167,6 +172,9 @@ class AudioPlayService : BaseService(),
return true return true
} }
/**
* 播放结束
*/
override fun onCompletion(mp: MediaPlayer?) { override fun onCompletion(mp: MediaPlayer?) {
handler.removeCallbacks(mpRunnable) handler.removeCallbacks(mpRunnable)
postEvent(Bus.AUDIO_NEXT, 1) postEvent(Bus.AUDIO_NEXT, 1)

Loading…
Cancel
Save