The source's phase is one of phases.
The saved interface language is language
(plugin.appearance.language: "system" or a locale).
The source's duration in seconds is within min ≤ duration < max
(at least one bound); false while it is unknown.
The volume (0–200) is within min ≤ volume < max.
TypeError (throws) As When.duration.
The playback rate is within min ≤ rate < max.
TypeError (throws) As When.duration.
The wall clock (Unix milliseconds, as Date.now()) is within
min ≤ now < max. For a trigger only (plugin.trigger().firesOn): a
command's state refuses it.
TypeError (throws) As When.duration.
The selected audio track is id (AudioTrack.id).
One menu item per track of the file carries a check mark while that track plays, also when the user picks it in the player's own menu.
const { when, player } = plugin;
for (const track of player.state.audioTracks ?? [])
plugin.commands.add({
id: `audio-${track.id}`,
path: ["@audio", "Track", track.title ?? `Track ${track.id}`],
radio: true,
checked: when.audioTrack(track.id), // the player keeps the mark current
run: () => player.selectAudioTrack(track.id),
});
The active audio output device is id (PlayerState.audioOutput.active).
One menu item per output device carries a check mark while the player plays through it; the player compares its own active device.
const { when, player } = plugin;
for (const device of await player.audioDevices())
plugin.commands.add({
id: `out-${device.id}`,
path: ["@audio", "Output", device.name],
radio: true,
checked: when.audioDevice(device.id), // no state read in the plugin
run: () => player.setAudioDevice(device.id),
});
ReadonlyopenA source is open: any phase but empty (loading, ready, ended, error).
ReadonlyreadyThe source is loaded and can play (phase is ready).
ReadonlyplayingThe source is ready and not paused.
ReadonlypausedThe source is ready and paused.
ReadonlystreamThe source is a generated stream (PlayerState.kind is stream).
ReadonlyfullscreenThe main window is fullscreen.
ReadonlymutedThe source is muted (PlayerState.muted).
ReadonlymaximizedThe main window is maximized (MainWindowState.maximized).
ReadonlypipThe video shows in the picture-in-picture window.
ReadonlyloopingAn A-B loop is set (PlayerState.loop is not null).
ReadonlypositionThe playback position. For a trigger only: a command's state refuses it.
The position is inside one of ranges (start ≤ position < end; no
end: open), or less than lead media seconds before a range's
start. The player binds the list to the source that is current when
it receives it: for any other source this is false. When several
ranges hold, the one with the earliest start is the one a trigger's
enter gets as range. At most one position list per condition;
it counts as one part however long it is.
Objects with start and optionally end (media
seconds); other fields are ignored, so the list given to
TimelineLayer.setRanges fits as it is. At most 1000
(TIMELINE_LIMITS.ranges).
Optionaloptions: { lead?: number }
lead: media seconds each range starts earlier,
to make up for the time a plugin in standby takes to start.
plugin.when: the vocabulary of conditions. It names only state the player owns: the source's phase, kind, pause and controls (the same names as PlayerState), fullscreen, the palette and the saved interface language.Remarks
Give a condition as a command's
enabledorchecked(CommandOptions, Command.set). The player evaluates it and shows the result in menus, on keys and on bar buttons, again whenever that state changes, also while the plugin is stopped because nothing used it. With anenabledcondition the player shows the command'sreasononly while the condition is false (or the command is busy), so a fixed reason is enough.State the vocabulary does not name (a plugin's own settings, an open window, a track list) stays a function or a value set with Command.set.
Example: Check a palette item and follow the palette
The Appearance submenu has one radio item per palette; the player checks the one in use, also after another plugin or the user changed it, and while this plugin is stopped. Nothing in the plugin listens to the palette.
Since
1.5.40