media icon indicating copy to clipboard operation
media copied to clipboard

Fix a bug and add a feature for media resumption

Open nift4 opened this issue 7 months ago • 0 comments

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.


Formal API to allow apps to handle playback resumption themselves

This could previously be achieved by inspecting stack trace of onPlaybackResumption() and then returning settable future that will never be set, but this API adds a cleaner way and makes the caveats of this clearer.

Issue: https://github.com/androidx/media/issues/1764

nift4 avatar May 22 '25 16:05 nift4