Run a core action exactly like its menu item or key: same checks, same
on-screen text. Resolves when it finished (or was dropped because the
same action is still running). Rejects unavailable when disabled,
invalid for an unknown id. Needs commands.
Prefer this over reimplementing playback buttons.
The plugin's own Play button behaves exactly like the player's Space
key, including its on-screen text. host.run runs the core action
with the player's checks; it resolves when the action finished, and
rejects with unavailable while the action is disabled (nothing open).
bar.on("playPause", async () => {
try {
await plugin.host.run("play-pause");
} catch (error) {
if ((error as PluginError).code !== "unavailable") throw error;
// Nothing to play: the button simply does nothing.
}
});
One step seek of seconds (0.1–3600 in tenths) instead of the
Player.setStepSeek step: the same checks, mode (exact or
keyframes), accumulation and on-screen text as ← / →. Use it for more
seek steps of your own (Ctrl+→ and the like) so that they add up with
the core's and land the same way.
In keyframe mode it resolves once the seek has landed (so
player.state.position is current after the await); presses that add
up resolve together, the last with the text. In exact mode it resolves
once the seek is submitted, as before. invalid for seconds out of
range.
The plugin's "+30 s" button seeks forward 30 seconds and shows the same
text as →. Passing seconds makes the core step seek use that step
with the player's mode (exact or keyframes); quick presses of it and of
→ add up into one seek.
bar.on("forward30", () => plugin.host.run("seek-forward", { seconds: 30 }));
plugin.host: the player's own core actions.Remarks
The player's core actions (play/pause, stop, step seeks, speed, volume, fullscreen…) are commands of the player itself,
host/<action>in the binding table. Running them throughhost.rungives a plugin's own buttons exactly the player's behaviour: the same checks, the same accumulation of repeated presses and the same on-screen text, instead of reimplementing them with Player calls.Example: Give a custom bar the player's own Stop and Mute
The plugin's bar buttons stop playback and mute exactly as the player's own keys do, with the same on-screen text. Each callback runs a core action; the player applies its checks and rejects with
unavailablewhile the action is disabled, which the bar ignores.See
HostAction, Player
Since
1.0.0