mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-26 16:37:58 +01:00
Set isActive correctly when pausing.
This commit is contained in:
parent
a910818b70
commit
bc2c591ff2
@ -500,7 +500,7 @@ class MediaPlayerService : Service() {
|
|||||||
// Create playback State
|
// Create playback State
|
||||||
val playbackState = PlaybackStateCompat.Builder()
|
val playbackState = PlaybackStateCompat.Builder()
|
||||||
val state: Int
|
val state: Int
|
||||||
val isPlaying = (playerState === PlayerState.STARTED)
|
val isActive: Boolean
|
||||||
|
|
||||||
var actions: Long = PlaybackStateCompat.ACTION_PLAY_PAUSE or
|
var actions: Long = PlaybackStateCompat.ACTION_PLAY_PAUSE or
|
||||||
PlaybackStateCompat.ACTION_SKIP_TO_NEXT or
|
PlaybackStateCompat.ACTION_SKIP_TO_NEXT or
|
||||||
@ -511,25 +511,33 @@ class MediaPlayerService : Service() {
|
|||||||
when (playerState) {
|
when (playerState) {
|
||||||
PlayerState.STARTED -> {
|
PlayerState.STARTED -> {
|
||||||
state = PlaybackStateCompat.STATE_PLAYING
|
state = PlaybackStateCompat.STATE_PLAYING
|
||||||
|
isActive = true
|
||||||
actions = actions or
|
actions = actions or
|
||||||
PlaybackStateCompat.ACTION_PAUSE or
|
PlaybackStateCompat.ACTION_PAUSE or
|
||||||
PlaybackStateCompat.ACTION_STOP
|
PlaybackStateCompat.ACTION_STOP
|
||||||
}
|
}
|
||||||
PlayerState.COMPLETED,
|
PlayerState.COMPLETED,
|
||||||
PlayerState.STOPPED -> {
|
PlayerState.STOPPED -> {
|
||||||
|
isActive = false
|
||||||
state = PlaybackStateCompat.STATE_STOPPED
|
state = PlaybackStateCompat.STATE_STOPPED
|
||||||
}
|
}
|
||||||
PlayerState.IDLE -> {
|
PlayerState.IDLE -> {
|
||||||
|
isActive = false
|
||||||
state = PlaybackStateCompat.STATE_NONE
|
state = PlaybackStateCompat.STATE_NONE
|
||||||
actions = 0L
|
actions = 0L
|
||||||
}
|
}
|
||||||
PlayerState.PAUSED -> {
|
PlayerState.PAUSED -> {
|
||||||
|
isActive = true
|
||||||
state = PlaybackStateCompat.STATE_PAUSED
|
state = PlaybackStateCompat.STATE_PAUSED
|
||||||
actions = actions or
|
actions = actions or
|
||||||
PlaybackStateCompat.ACTION_PLAY or
|
PlaybackStateCompat.ACTION_PLAY or
|
||||||
PlaybackStateCompat.ACTION_STOP
|
PlaybackStateCompat.ACTION_STOP
|
||||||
}
|
}
|
||||||
else -> state = PlaybackStateCompat.STATE_PAUSED
|
else -> {
|
||||||
|
// These are the states PREPARING, PREPARED & DOWNLOADING
|
||||||
|
isActive = true
|
||||||
|
state = PlaybackStateCompat.STATE_PAUSED
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playbackState.setState(state, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f)
|
playbackState.setState(state, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f)
|
||||||
@ -541,9 +549,9 @@ class MediaPlayerService : Service() {
|
|||||||
mediaSession!!.setPlaybackState(playbackState.build())
|
mediaSession!!.setPlaybackState(playbackState.build())
|
||||||
|
|
||||||
// Set Active state
|
// Set Active state
|
||||||
mediaSession!!.isActive = isPlaying
|
mediaSession!!.isActive = isActive
|
||||||
|
|
||||||
Timber.d("Setting the MediaSession to active = %s", isPlaying)
|
Timber.d("Setting the MediaSession to active = %s", isActive)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createNotificationChannel() {
|
private fun createNotificationChannel() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user