From 0c2eecf62c01d5f66f8e80264d3dbb720805d7c7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 19 May 2026 16:33:55 +0000 Subject: [PATCH] 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. --- .../playback/playerPool/MediaSessionPool.kt | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/playerPool/MediaSessionPool.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/playerPool/MediaSessionPool.kt index d05267f3cf..06170fcee4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/playerPool/MediaSessionPool.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/playerPool/MediaSessionPool.kt @@ -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, ): ListenableFuture> { // 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) }