Improve player service dismiss logic

This commit is contained in:
vfsfitvnm 2022-09-06 18:02:06 +02:00
parent 4014675766
commit 996dbb4de1
2 changed files with 7 additions and 4 deletions

View file

@ -450,14 +450,16 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
if (notification == null) {
isNotificationStarted = false
makeInvincible(false)
stopForeground(true)
stopForeground(false)
sendCloseEqualizerIntent()
notificationManager?.cancel(NotificationId)
return
}
if (player.shouldBePlaying && !isNotificationStarted) {
isNotificationStarted = true
startForegroundService(this@PlayerService, intent<PlayerService>())
startForeground(NotificationId, notification())
startForeground(NotificationId, notification)
makeInvincible(false)
sendOpenEqualizerIntent()
} else {

View file

@ -52,12 +52,13 @@ fun Player.forcePlayAtIndex(mediaItems: List<MediaItem>, mediaItemIndex: Int) {
fun Player.forcePlayFromBeginning(mediaItems: List<MediaItem>) =
forcePlayAtIndex(mediaItems, 0)
fun Player.forceSeekToPrevious() =
fun Player.forceSeekToPrevious() {
if (hasPreviousMediaItem() || currentPosition > maxSeekToPreviousPosition) {
seekToPrevious()
}else {
} else if (mediaItemCount > 0) {
seekTo(mediaItemCount - 1, C.TIME_UNSET)
}
}
fun Player.forceSeekToNext() =
if (hasNextMediaItem()) seekToNext() else seekTo(0, C.TIME_UNSET)