优化
This commit is contained in:
@@ -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,12 +81,9 @@ 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 ?: ""
|
loadContent()
|
||||||
position = it.durChapterPos
|
|
||||||
loadContent()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
IntentAction.pause -> pause(true)
|
IntentAction.pause -> pause(true)
|
||||||
IntentAction.resume -> resume()
|
IntentAction.resume -> resume()
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user