Skip to content

Commit 7938978

Browse files
marcbaechingericbaker
authored andcommitted
Allow MediaLibraryService to reject the resumption notification
To reliably reject the System UI playback resumption notification on all API levels (specifically API 30), the backward compatibility layer needs to return `null` for the library root. This is not possible in the Media3 implementation. This change allows an app to return a `LibraryResult.ofError(RESULT_ERROR_NOT_SUPPORTED)` that then is translated to return null by the backwards compatibility layer. Issue: androidx/media#355 Issue: androidx/media#167 Issue: androidx/media#27 See https://developer.android.com/guide/topics/media/media-controls#mediabrowserservice_implementation PiperOrigin-RevId: 527276529
1 parent 178a323 commit 7938978

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

RELEASENOTES.md

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
* Add helper method `MediaSession.getControllerForCurrentRequest` to
5757
obtain information about the controller that is currently calling
5858
a`Player` method.
59+
* Fix bug that prevented the `MediaLibraryService` from returning null for
60+
a call from System UI to `Callback.onGetLibraryRoot` with
61+
`params.isRecent == true` on API 30
62+
([#355](https://github.com/androidx/media/issues/355)).
5963
* UI:
6064

6165
* Add Util methods `shouldShowPlayButton` and

demos/session/src/main/java/androidx/media3/demo/session/PlaybackService.kt

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import androidx.media3.common.util.Util
3030
import androidx.media3.datasource.DataSourceBitmapLoader
3131
import androidx.media3.exoplayer.ExoPlayer
3232
import androidx.media3.session.*
33+
import androidx.media3.session.LibraryResult.RESULT_ERROR_NOT_SUPPORTED
3334
import androidx.media3.session.MediaSession.ControllerInfo
3435
import com.google.common.collect.ImmutableList
3536
import com.google.common.util.concurrent.Futures
@@ -143,6 +144,12 @@ class PlaybackService : MediaLibraryService() {
143144
browser: ControllerInfo,
144145
params: LibraryParams?
145146
): ListenableFuture<LibraryResult<MediaItem>> {
147+
if (params != null && params.isRecent) {
148+
// The service currently does not support playback resumption. Tell System UI by returning
149+
// an error of type 'RESULT_ERROR_NOT_SUPPORTED' for a `params.isRecent` request. See
150+
// https://github.com/androidx/media/issues/355
151+
return Futures.immediateFuture(LibraryResult.ofError(RESULT_ERROR_NOT_SUPPORTED))
152+
}
146153
return Futures.immediateFuture(LibraryResult.ofItem(MediaItemTree.getRootItem(), params))
147154
}
148155

libraries/session/src/main/java/androidx/media3/session/MediaLibraryServiceLegacyStub.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,11 @@ public BrowserRoot onGetRoot(
126126
.putBoolean(BROWSER_SERVICE_EXTRAS_KEY_SEARCH_SUPPORTED, isSearchSessionCommandAvailable);
127127
return new BrowserRoot(result.value.mediaId, extras);
128128
}
129-
// No library root, but keep browser compat connected to allow getting session.
130-
return MediaUtils.defaultBrowserRoot;
129+
// No library root, but keep browser compat connected to allow getting session unless the
130+
// `Callback` implementation has not returned a `RESULT_SUCCESS`.
131+
return result != null && result.resultCode != RESULT_SUCCESS
132+
? null
133+
: MediaUtils.defaultBrowserRoot;
131134
}
132135

133136
// TODO(b/192455639): Optimize potential multiple calls of

0 commit comments

Comments
 (0)