Improve player service dismiss logic
This commit is contained in:
@@ -450,14 +450,16 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
|
|||||||
if (notification == null) {
|
if (notification == null) {
|
||||||
isNotificationStarted = false
|
isNotificationStarted = false
|
||||||
makeInvincible(false)
|
makeInvincible(false)
|
||||||
stopForeground(true)
|
stopForeground(false)
|
||||||
|
sendCloseEqualizerIntent()
|
||||||
|
notificationManager?.cancel(NotificationId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.shouldBePlaying && !isNotificationStarted) {
|
if (player.shouldBePlaying && !isNotificationStarted) {
|
||||||
isNotificationStarted = true
|
isNotificationStarted = true
|
||||||
startForegroundService(this@PlayerService, intent<PlayerService>())
|
startForegroundService(this@PlayerService, intent<PlayerService>())
|
||||||
startForeground(NotificationId, notification())
|
startForeground(NotificationId, notification)
|
||||||
makeInvincible(false)
|
makeInvincible(false)
|
||||||
sendOpenEqualizerIntent()
|
sendOpenEqualizerIntent()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -52,12 +52,13 @@ fun Player.forcePlayAtIndex(mediaItems: List<MediaItem>, mediaItemIndex: Int) {
|
|||||||
fun Player.forcePlayFromBeginning(mediaItems: List<MediaItem>) =
|
fun Player.forcePlayFromBeginning(mediaItems: List<MediaItem>) =
|
||||||
forcePlayAtIndex(mediaItems, 0)
|
forcePlayAtIndex(mediaItems, 0)
|
||||||
|
|
||||||
fun Player.forceSeekToPrevious() =
|
fun Player.forceSeekToPrevious() {
|
||||||
if (hasPreviousMediaItem() || currentPosition > maxSeekToPreviousPosition) {
|
if (hasPreviousMediaItem() || currentPosition > maxSeekToPreviousPosition) {
|
||||||
seekToPrevious()
|
seekToPrevious()
|
||||||
}else {
|
} else if (mediaItemCount > 0) {
|
||||||
seekTo(mediaItemCount - 1, C.TIME_UNSET)
|
seekTo(mediaItemCount - 1, C.TIME_UNSET)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun Player.forceSeekToNext() =
|
fun Player.forceSeekToNext() =
|
||||||
if (hasNextMediaItem()) seekToNext() else seekTo(0, C.TIME_UNSET)
|
if (hasNextMediaItem()) seekToNext() else seekTo(0, C.TIME_UNSET)
|
||||||
|
|||||||
Reference in New Issue
Block a user