fix: make playback notification tap open the note on warm-pool resume

The playback notification's tap target (MediaSession.setSessionActivity)
was only bound from MediaSessionCallback.onAddMediaItems, which fires
when the in-app MediaController calls setMediaItem. GetVideoController's
warm-pool fast path skips setMediaItem when the acquired ExoPlayer was
retained with the same mediaId, so the new MediaSession was left with
no session activity and tapping the notification did nothing.

Bind the PendingIntent in newSession() from the acquired player's
current MediaItem extras, and share the construction with onAddMediaItems
via a single helper.
This commit is contained in:
Claude
2026-05-19 16:33:55 +00:00
parent 1afa86cb26
commit 0c2eecf62c
@@ -143,11 +143,33 @@ class MediaSessionPool(
reset(mediaSession, keepPlaying)
// Warm-pool fast path acquires a player that still holds its MediaItem, so the
// client side skips setMediaItem (see GetVideoController) and onAddMediaItems
// never fires for this fresh session — leaving the notification's tap target
// unset. Re-bind it from the player's current item so tapping the playback
// notification opens the originating nostr URI.
bindSessionActivity(mediaSession, mediaSession.player.currentMediaItem)
cache.put(mediaSession.id, SessionListener(mediaSession, listener))
return mediaSession
}
fun bindSessionActivity(
session: MediaSession,
mediaItem: MediaItem?,
) {
val callbackUri = mediaItem?.mediaMetadata?.extras?.getString(MediaItemCache.EXTRA_CALLBACK_URI) ?: return
session.setSessionActivity(
PendingIntent.getActivity(
appContext,
0,
Intent(Intent.ACTION_VIEW, callbackUri.toUri(), appContext, MainActivity::class.java),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
),
)
}
fun releaseSession(session: MediaSession) {
val listener = playingMap.get(session.id) ?: cache.get(session.id)
if (listener != null) {
@@ -220,16 +242,7 @@ class MediaSessionPool(
mediaItems: List<MediaItem>,
): ListenableFuture<List<MediaItem>> {
// set up return call when clicking on the Notification bar
mediaItems.firstOrNull()?.mediaMetadata?.extras?.getString(MediaItemCache.EXTRA_CALLBACK_URI)?.let {
mediaSession.setSessionActivity(
PendingIntent.getActivity(
appContext,
0,
Intent(Intent.ACTION_VIEW, it.toUri(), appContext, MainActivity::class.java),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
),
)
}
pool.bindSessionActivity(mediaSession, mediaItems.firstOrNull())
return Futures.immediateFuture(mediaItems)
}