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
This commit is contained in:
parent
178a323897
commit
7938978b51
@ -56,6 +56,10 @@
|
|||||||
* Add helper method `MediaSession.getControllerForCurrentRequest` to
|
* Add helper method `MediaSession.getControllerForCurrentRequest` to
|
||||||
obtain information about the controller that is currently calling
|
obtain information about the controller that is currently calling
|
||||||
a`Player` method.
|
a`Player` method.
|
||||||
|
* Fix bug that prevented the `MediaLibraryService` from returning null for
|
||||||
|
a call from System UI to `Callback.onGetLibraryRoot` with
|
||||||
|
`params.isRecent == true` on API 30
|
||||||
|
([#355](https://github.com/androidx/media/issues/355)).
|
||||||
* UI:
|
* UI:
|
||||||
|
|
||||||
* Add Util methods `shouldShowPlayButton` and
|
* Add Util methods `shouldShowPlayButton` and
|
||||||
|
@ -30,6 +30,7 @@ import androidx.media3.common.util.Util
|
|||||||
import androidx.media3.datasource.DataSourceBitmapLoader
|
import androidx.media3.datasource.DataSourceBitmapLoader
|
||||||
import androidx.media3.exoplayer.ExoPlayer
|
import androidx.media3.exoplayer.ExoPlayer
|
||||||
import androidx.media3.session.*
|
import androidx.media3.session.*
|
||||||
|
import androidx.media3.session.LibraryResult.RESULT_ERROR_NOT_SUPPORTED
|
||||||
import androidx.media3.session.MediaSession.ControllerInfo
|
import androidx.media3.session.MediaSession.ControllerInfo
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
import com.google.common.util.concurrent.Futures
|
import com.google.common.util.concurrent.Futures
|
||||||
@ -143,6 +144,12 @@ class PlaybackService : MediaLibraryService() {
|
|||||||
browser: ControllerInfo,
|
browser: ControllerInfo,
|
||||||
params: LibraryParams?
|
params: LibraryParams?
|
||||||
): ListenableFuture<LibraryResult<MediaItem>> {
|
): ListenableFuture<LibraryResult<MediaItem>> {
|
||||||
|
if (params != null && params.isRecent) {
|
||||||
|
// The service currently does not support playback resumption. Tell System UI by returning
|
||||||
|
// an error of type 'RESULT_ERROR_NOT_SUPPORTED' for a `params.isRecent` request. See
|
||||||
|
// https://github.com/androidx/media/issues/355
|
||||||
|
return Futures.immediateFuture(LibraryResult.ofError(RESULT_ERROR_NOT_SUPPORTED))
|
||||||
|
}
|
||||||
return Futures.immediateFuture(LibraryResult.ofItem(MediaItemTree.getRootItem(), params))
|
return Futures.immediateFuture(LibraryResult.ofItem(MediaItemTree.getRootItem(), params))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,8 +126,11 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
|||||||
.putBoolean(BROWSER_SERVICE_EXTRAS_KEY_SEARCH_SUPPORTED, isSearchSessionCommandAvailable);
|
.putBoolean(BROWSER_SERVICE_EXTRAS_KEY_SEARCH_SUPPORTED, isSearchSessionCommandAvailable);
|
||||||
return new BrowserRoot(result.value.mediaId, extras);
|
return new BrowserRoot(result.value.mediaId, extras);
|
||||||
}
|
}
|
||||||
// No library root, but keep browser compat connected to allow getting session.
|
// No library root, but keep browser compat connected to allow getting session unless the
|
||||||
return MediaUtils.defaultBrowserRoot;
|
// `Callback` implementation has not returned a `RESULT_SUCCESS`.
|
||||||
|
return result != null && result.resultCode != RESULT_SUCCESS
|
||||||
|
? null
|
||||||
|
: MediaUtils.defaultBrowserRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(b/192455639): Optimize potential multiple calls of
|
// TODO(b/192455639): Optimize potential multiple calls of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user