Skip to content

Commit 2ac334e

Browse files
committed
Fix a bug where media resumption would break if prepare() was called in onCreate()
Media resumption code relied on the assumption that if no media controller sends any commands, the player will stay in STATE_IDLE. This optimization however breaks if a developer calls prepare() in or shortly after (in my case, which caused this to be a race) onCreate(). Instead, use playWhenReady to determine whether we need to do a query with effort, because playWhenReady really shouldn't be set to true on device bootup. :) SystemUI asks for resumption support while a session is active and just started playing (playWhenReady=true), hence the optimization is still valid.
1 parent e0ce5ed commit 2ac334e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ public ListenableFuture<LibraryResult<ImmutableList<MediaItem>>> onGetChildrenOn
166166
if (!canResumePlaybackOnStart()) {
167167
return Futures.immediateFuture(LibraryResult.ofError(ERROR_NOT_SUPPORTED));
168168
}
169-
// Advertise support for playback resumption. If STATE_IDLE, the request arrives at boot time
170-
// to get the full item data to build a notification. If not STATE_IDLE we don't need to
171-
// deliver the full media item, so we do the minimal viable effort.
172-
return getPlayerWrapper().getPlaybackState() == Player.STATE_IDLE
169+
// Advertise support for playback resumption. If we're not playing, the request probably
170+
// arrived at boot time to get the full item data to build a notification. If we're playing,
171+
// we don't need to deliver the full media item, so we do the minimal viable effort.
172+
return !getPlayerWrapper().getPlayWhenReady()
173173
? getRecentMediaItemAtDeviceBootTime(browser, params)
174174
: Futures.immediateFuture(
175175
LibraryResult.ofItemList(

0 commit comments

Comments
 (0)