Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a1eb63c
fix(perf): remove 1 second debounce for song liking in notification
stopper2408 Apr 15, 2026
3157e02
fix(playback): return accurate media session command results
stopper2408 Apr 15, 2026
f0539f1
fix(notification): harden media action latency and race safety
stopper2408 Apr 15, 2026
2fc3a46
Merge branch 'MetrolistGroup:main' into fix/notification-like-latency
stopper2408 Apr 16, 2026
1023058
fix(notification): make media favorite state episode-aware
stopper2408 Apr 16, 2026
5317e2f
fix(playback): address CodeRabbit issues in media action flows
stopper2408 Apr 16, 2026
291caa1
fix(playback): add rollback parity for like toggle failures
stopper2408 Apr 16, 2026
b9b9995
fix(playback): add CodeRabbit rollback parity for episode save-for-la…
stopper2408 Apr 16, 2026
75a1c4c
fix(playback): handle CodeRabbit no-recommendations state without err…
stopper2408 Apr 17, 2026
84f5a95
fix(playback): align CodeRabbit start radio failure handling across e…
stopper2408 Apr 17, 2026
12db548
fix(playback): harden queue, automix, and radio fallback error handli…
stopper2408 Apr 17, 2026
96337e6
fix(playback): propagate CancellationException in MusicService to pre…
stopper2408 Apr 19, 2026
1d243f3
Merge branch 'MetrolistGroup:main' into fix/media-action-latency-and-…
stopper2408 Apr 27, 2026
43cbaba
Fix duplicate CancellationException import
stopper2408 Apr 27, 2026
b4be4cd
Merge branch 'MetrolistGroup:main' into fix/media-action-latency-and-…
stopper2408 May 10, 2026
2764887
fix(playback): use episode save labels in media action to fix codeRab…
stopper2408 May 10, 2026
77deef1
Fixed coderabbit review
stopper2408 May 10, 2026
b62a6b6
Fixed compiling error
stopper2408 May 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ import com.metrolist.music.constants.AndroidAutoYouTubePlaylistsKey
import com.metrolist.music.ui.screens.settings.AndroidAutoSection
import com.metrolist.music.ui.screens.settings.deserializeSections
import com.metrolist.music.ui.screens.settings.serializeSections
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.withContext

class MediaLibrarySessionCallback
@Inject
Expand All @@ -74,10 +76,10 @@ constructor(
) : MediaLibrarySession.Callback {
private val scope = CoroutineScope(Dispatchers.Main) + Job()
lateinit var service: MusicService
var toggleLike: () -> Unit = {}
var toggleStartRadio: () -> Unit = {}
var toggleLibrary: () -> Unit = {}
var addToTargetPlaylist: () -> Unit = {}
var toggleLike: suspend () -> Unit = {}
var toggleStartRadio: suspend () -> Unit = {}
var toggleLibrary: suspend () -> Unit = {}
var addToTargetPlaylist: suspend () -> Unit = {}

fun release() {
scope.cancel()
Expand Down Expand Up @@ -107,19 +109,47 @@ constructor(
controller: MediaSession.ControllerInfo,
customCommand: SessionCommand,
args: Bundle,
): ListenableFuture<SessionResult> {
when (customCommand.customAction) {
MediaSessionConstants.ACTION_TOGGLE_LIKE -> toggleLike()
MediaSessionConstants.ACTION_TOGGLE_START_RADIO -> toggleStartRadio()
MediaSessionConstants.ACTION_TOGGLE_LIBRARY -> toggleLibrary()
MediaSessionConstants.ACTION_TOGGLE_SHUFFLE -> session.player.shuffleModeEnabled =
!session.player.shuffleModeEnabled

MediaSessionConstants.ACTION_TOGGLE_REPEAT_MODE -> session.player.toggleRepeatMode()
MediaSessionConstants.ACTION_ADD_TO_TARGET_PLAYLIST -> addToTargetPlaylist()
): ListenableFuture<SessionResult> =
scope.future {
try {
when (customCommand.customAction) {
MediaSessionConstants.ACTION_TOGGLE_LIKE -> toggleLike()
MediaSessionConstants.ACTION_TOGGLE_START_RADIO -> toggleStartRadio()
MediaSessionConstants.ACTION_TOGGLE_LIBRARY -> toggleLibrary()
MediaSessionConstants.ACTION_TOGGLE_SHUFFLE ->
withContext(Dispatchers.Main.immediate) {
session.player.shuffleModeEnabled = !session.player.shuffleModeEnabled
}

MediaSessionConstants.ACTION_TOGGLE_REPEAT_MODE ->
withContext(Dispatchers.Main.immediate) {
session.player.toggleRepeatMode()
}

MediaSessionConstants.ACTION_ADD_TO_TARGET_PLAYLIST -> addToTargetPlaylist()
else -> {
return@future SessionResult(
SessionError(
SessionError.ERROR_BAD_VALUE,
"Unsupported command: ${customCommand.customAction}",
),
)
}
}

SessionResult(SessionResult.RESULT_SUCCESS)
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
reportException(e)
SessionResult(
SessionError(
SessionError.ERROR_UNKNOWN,
e.message ?: "Failed to execute command",
),
)
}
}
return Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
}

@Deprecated("Deprecated in MediaLibrarySession.Callback")
override fun onPlaybackResumption(
Expand Down
Loading
Loading