ottstackplayer: drop a load that was stopped while it was preparing
ottstack_player: drop a load that was stopped while it was preparing
Section titled “ottstack_player: drop a load that was stopped while it was preparing”Problem
Section titled “Problem”disposeMediaResources() cancels mediaLoader, but cancelling a
CancelableOperation does not stop the future it wraps. When _loadMediaEntry
is waiting on media.prepare (a network call, for example for fresh key
headers) and the app stops playback, prepare eventually returns and
_loadMediaEntry still calls kController.play(...). The stopped media
starts playing, often behind another screen.
There is a second, smaller version of the same gap. A stop that lands while
playNewMedia is awaiting kController.play(null) is followed by the loader
being created anyway.
Change
Section titled “Change”OSPlayerController keeps a _loadGeneration counter.
playNewMedia,retryCurrentMedia, the playlist advance anddisposeMediaResourceseach bump it.playNewMediareturns early if the counter moved duringplay(null)._loadMediaEntryresolvesprepareinto a local and returns early if the counter moved. Only then does it set_activeMediaEntryand call nativeplay.catchandfinallyonly touch_errorand_loadingMediafor the current generation, so a stale load cannot overwrite a newer one’s state.
The Chorki app pins this with three cases in
test/contract/player_lib_load_guard_test.dart:
- a stop while
prepareis pending - a stop while
play(null)is in flight - a superseded load
All three fail without this change and pass with it.
🤖 Generated with Claude Code