pull/1744/head
kunfei 3 years ago
parent dab92ae44a
commit 7f7e40228f
  1. 20
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -45,7 +45,7 @@ class AudioPlayService : BaseService(),
companion object { companion object {
var isRun = false var isRun = false
private set private set
var pause = false var pause = true
private set private set
var timeMinute: Int = 0 var timeMinute: Int = 0
private set private set
@ -59,11 +59,9 @@ class AudioPlayService : BaseService(),
private val exoPlayer: ExoPlayer by lazy { private val exoPlayer: ExoPlayer by lazy {
ExoPlayer.Builder(this).build() ExoPlayer.Builder(this).build()
} }
private var title: String = ""
private var subtitle: String = ""
private var mediaSessionCompat: MediaSessionCompat? = null private var mediaSessionCompat: MediaSessionCompat? = null
private var broadcastReceiver: BroadcastReceiver? = null private var broadcastReceiver: BroadcastReceiver? = null
private var position = 0 private var position = AudioPlay.book?.durChapterPos ?: 0
private var dsJob: Job? = null private var dsJob: Job? = null
private var upPlayProgressJob: Job? = null private var upPlayProgressJob: Job? = null
private var playSpeed: Float = 1f private var playSpeed: Float = 1f
@ -83,13 +81,10 @@ class AudioPlayService : BaseService(),
intent?.action?.let { action -> intent?.action?.let { action ->
when (action) { when (action) {
IntentAction.play -> { IntentAction.play -> {
AudioPlay.book?.let { pause = false
title = it.name position = AudioPlay.book?.durChapterPos ?: 0
subtitle = AudioPlay.durChapter?.title ?: ""
position = it.durChapterPos
loadContent() loadContent()
} }
}
IntentAction.pause -> pause(true) IntentAction.pause -> pause(true)
IntentAction.resume -> resume() IntentAction.resume -> resume()
IntentAction.prev -> AudioPlay.prev(this) IntentAction.prev -> AudioPlay.prev(this)
@ -361,7 +356,6 @@ class AudioPlayService : BaseService(),
*/ */
private fun contentLoadFinish(chapter: BookChapter, content: String) { private fun contentLoadFinish(chapter: BookChapter, content: String) {
if (chapter.index == AudioPlay.book?.durChapterIndex) { if (chapter.index == AudioPlay.book?.durChapterIndex) {
subtitle = chapter.title
url = content url = content
play() play()
} }
@ -455,9 +449,9 @@ class AudioPlayService : BaseService(),
) )
else -> getString(R.string.audio_play_t) else -> getString(R.string.audio_play_t)
} }
nTitle += ": $title" nTitle += ": ${AudioPlay.book?.name}"
var nSubtitle = subtitle var nSubtitle = AudioPlay.durChapter?.title
if (subtitle.isEmpty()) { if (nSubtitle.isNullOrEmpty()) {
nSubtitle = getString(R.string.audio_play_s) nSubtitle = getString(R.string.audio_play_s)
} }
val builder = NotificationCompat val builder = NotificationCompat

Loading…
Cancel
Save