Controls act on the current state by default. While a
Player.stream (or anything else that follows the source) keeps
player.state current, that is the state they act on; otherwise the SDK
reads the state first (calls made together share one read). If another
plugin or the user changed the source in between, the call fails with
code stale and nothing happens. Pass ifCurrent to pin the call to an
older snapshot instead (for example the state when a dialog opened); it
is sent as given.
The SDK refreshes player.state after its own operations, so a plugin's
consecutive calls do not make each other stale. Player.open is
unconditional unless ifCurrent is given.
Example: Play the next file only if nothing else was opened
When the plugin's file ends, the next one starts, unless the user or
another plugin opened something in the meantime. onEnd passes the
state at the end; open with ifCurrent: ended is refused with stale
when the source changed after that state, so nothing is replaced.
media.onEnd(async (ended) => { try { awaitplugin.player.open(next, { ifCurrent:ended }); } catch (error) { // Someone opened another file: leave it playing. if ((errorasPluginError).code !== "stale") throwerror; } });
Controls act on the current state by default. While a Player.stream (or anything else that follows the source) keeps
player.statecurrent, that is the state they act on; otherwise the SDK reads the state first (calls made together share one read). If another plugin or the user changed the source in between, the call fails with codestaleand nothing happens. PassifCurrentto pin the call to an older snapshot instead (for example the state when a dialog opened); it is sent as given.The SDK refreshes
player.stateafter its own operations, so a plugin's consecutive calls do not make each other stale. Player.open is unconditional unlessifCurrentis given.Example: Play the next file only if nothing else was opened
When the plugin's file ends, the next one starts, unless the user or another plugin opened something in the meantime.
onEndpasses the state at the end;openwithifCurrent: endedis refused withstalewhen the source changed after that state, so nothing is replaced.See
Control playback
Since
1.0.0