mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
d44d2a3b08
commit
bbe90f1c55
@ -116,7 +116,7 @@ object AudioPlay {
|
|||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
book?.let { book ->
|
book?.let { book ->
|
||||||
if (book.durChapterIndex > 0) {
|
if (book.durChapterIndex > 0) {
|
||||||
book.durChapterIndex = book.durChapterIndex - 1
|
book.durChapterIndex -= 1
|
||||||
book.durChapterPos = 0
|
book.durChapterPos = 0
|
||||||
durChapter = null
|
durChapter = null
|
||||||
saveRead()
|
saveRead()
|
||||||
@ -131,7 +131,7 @@ object AudioPlay {
|
|||||||
fun next(context: Context) {
|
fun next(context: Context) {
|
||||||
book?.let { book ->
|
book?.let { book ->
|
||||||
if (book.durChapterIndex + 1 < book.totalChapterNum) {
|
if (book.durChapterIndex + 1 < book.totalChapterNum) {
|
||||||
book.durChapterIndex = book.durChapterIndex + 1
|
book.durChapterIndex += 1
|
||||||
book.durChapterPos = 0
|
book.durChapterPos = 0
|
||||||
durChapter = null
|
durChapter = null
|
||||||
saveRead()
|
saveRead()
|
||||||
|
@ -20,7 +20,6 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import androidx.media.AudioFocusRequestCompat
|
import androidx.media.AudioFocusRequestCompat
|
||||||
import androidx.media3.common.PlaybackException
|
import androidx.media3.common.PlaybackException
|
||||||
import androidx.media3.common.Player
|
import androidx.media3.common.Player
|
||||||
import androidx.media3.common.util.UnstableApi
|
|
||||||
import androidx.media3.exoplayer.ExoPlayer
|
import androidx.media3.exoplayer.ExoPlayer
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseService
|
import io.legado.app.base.BaseService
|
||||||
@ -59,7 +58,6 @@ import splitties.systemservices.notificationManager
|
|||||||
import splitties.systemservices.powerManager
|
import splitties.systemservices.powerManager
|
||||||
import splitties.systemservices.wifiManager
|
import splitties.systemservices.wifiManager
|
||||||
|
|
||||||
@UnstableApi
|
|
||||||
/**
|
/**
|
||||||
* 音频播放服务
|
* 音频播放服务
|
||||||
*/
|
*/
|
||||||
@ -136,6 +134,7 @@ class AudioPlayService : BaseService(),
|
|||||||
.get()
|
.get()
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
cover = it
|
cover = it
|
||||||
|
upMediaMetadata()
|
||||||
upAudioPlayNotification()
|
upAudioPlayNotification()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -321,11 +320,7 @@ class AudioPlayService : BaseService(),
|
|||||||
postEvent(EventBus.AUDIO_STATE, Status.PAUSE)
|
postEvent(EventBus.AUDIO_STATE, Status.PAUSE)
|
||||||
}
|
}
|
||||||
postEvent(EventBus.AUDIO_SIZE, exoPlayer.duration)
|
postEvent(EventBus.AUDIO_SIZE, exoPlayer.duration)
|
||||||
mediaSessionCompat?.setMetadata(
|
upMediaMetadata()
|
||||||
MediaMetadataCompat.Builder()
|
|
||||||
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, exoPlayer.duration)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
upPlayProgress()
|
upPlayProgress()
|
||||||
AudioPlay.saveDurChapter(exoPlayer.duration)
|
AudioPlay.saveDurChapter(exoPlayer.duration)
|
||||||
}
|
}
|
||||||
@ -339,6 +334,17 @@ class AudioPlayService : BaseService(),
|
|||||||
upAudioPlayNotification()
|
upAudioPlayNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun upMediaMetadata() {
|
||||||
|
val metadata = MediaMetadataCompat.Builder()
|
||||||
|
.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, cover)
|
||||||
|
.putText(MediaMetadataCompat.METADATA_KEY_TITLE, AudioPlay.durChapter?.title ?: "null")
|
||||||
|
.putText(MediaMetadataCompat.METADATA_KEY_ARTIST, AudioPlay.book?.name ?: "null")
|
||||||
|
.putText(MediaMetadataCompat.METADATA_KEY_ALBUM, AudioPlay.book?.author ?: "null")
|
||||||
|
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, exoPlayer.duration)
|
||||||
|
.build()
|
||||||
|
mediaSessionCompat?.setMetadata(metadata)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 播放错误事件
|
* 播放错误事件
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user