mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
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 (cherry picked from commit 7938978b5165a9cbb63a6ee1fe5209934e996c6e)
This commit is contained in:
parent
31492031c1
commit
3406334ee8
@ -16,6 +16,10 @@
|
|||||||
* Fix issue where `MediaController` doesn't update its available commands
|
* Fix issue where `MediaController` doesn't update its available commands
|
||||||
when connected to a legacy `MediaSessionCompat` that updates its
|
when connected to a legacy `MediaSessionCompat` that updates its
|
||||||
actions.
|
actions.
|
||||||
|
* 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)).
|
||||||
|
|
||||||
### 1.0.1 (2023-04-18)
|
### 1.0.1 (2023-04-18)
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import androidx.media3.common.MediaItem
|
|||||||
import androidx.media3.common.util.Util
|
import androidx.media3.common.util.Util
|
||||||
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
|
||||||
@ -142,6 +143,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