@vestra-player/sdk - v1.11.3
    Preparing search index...

    Interface When

    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.

    Give a condition as a command's enabled or checked (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 an enabled condition the player shows the command's reason only 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.

    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.

    const { when } = plugin;
    for (const [id, title] of [["vestra", "Dark"], ["vestra-light", "Light"]] as const)
    plugin.commands.add({
    id: `theme.${id}`,
    path: ["Settings", "Appearance", title],
    radio: true,
    checked: when.theme(id), // evaluated by the player, not the plugin
    run: () => plugin.appearance.set(id),
    });

    1.5.40

    interface When {
        open: Condition;
        ready: Condition;
        playing: Condition;
        paused: Condition;
        stream: Condition;
        fullscreen: Condition;
        phase(
            ...phases: ("empty" | "loading" | "ready" | "ended" | "error")[],
        ): Condition;
        can(
            control:
                | "rate"
                | "pause"
                | "close"
                | "restart"
                | "seek"
                | "snapshot"
                | "next"
                | "previous",
        ): Condition;
        theme(theme: ThemeId): Condition;
        language(language: LanguagePreference): Condition;
        muted: Condition;
        maximized: Condition;
        pip: Condition;
        looping: Condition;
        duration(bounds: { min?: number; max?: number }): Condition;
        volume(bounds: { min?: number; max?: number }): Condition;
        rate(bounds: { min?: number; max?: number }): Condition;
        time(bounds: { min?: number; max?: number }): Condition;
        audioTrack(id: number): Condition;
        subtitleTrack(id: string): Condition;
        audioDevice(id: string): Condition;
        position: {
            in(
                ranges: Iterable<PositionRange>,
                options?: { lead?: number },
            ): Condition;
        };
    }
    Index
    • The source's phase is one of phases.

      Parameters

      • ...phases: ("empty" | "loading" | "ready" | "ended" | "error")[]

      Returns Condition

      TypeError (throws) No phase, or one that is not a phase.

      The item is enabled while the source is ready or has ended, as a snapshot needs a frame. The phases are those of PlayerState.phase.

      const { when } = plugin;
      const hasFrame = when.phase("ready", "ended");

      1.5.40

    • The source allows control: PlayerState.can[control] is true.

      Parameters

      • control:
            | "rate"
            | "pause"
            | "close"
            | "restart"
            | "seek"
            | "snapshot"
            | "next"
            | "previous"

      Returns Condition

      TypeError (throws) control is not one of PlayerState.can.

      "Jump to Middle" is greyed out on live streams that cannot seek. The player reads its own can.seek for the current source.

      const { when } = plugin;
      const seekable = when.can("seek");

      1.5.40

    • The palette in use is theme (plugin.appearance.theme).

      Parameters

      Returns Condition

      TypeError (throws) theme is not a palette of the player.

      The item carries a check mark while the light palette is in use, whoever switched to it.

      const { when } = plugin;
      const light = when.theme("vestra-light");

      1.5.40

    • The saved interface language is language (plugin.appearance.language: "system" or a locale).

      Parameters

      Returns Condition

      TypeError (throws) language is not "system" or a locale.

      The item carries a check mark while the player follows the system's language; the player reads its own saved preference.

      const { when } = plugin;
      const followSystem = when.language("system");

      1.5.40

    • The source's duration in seconds is within min ≤ duration < max (at least one bound); false while it is unknown.

      Parameters

      • bounds: { min?: number; max?: number }

      Returns Condition

      TypeError (throws) No bound, a bound that is not a finite number, or min ≥ max.

      The condition holds once the player knows the file lasts 600 seconds or more; with no max the range is open upwards.

      const { when } = plugin;
      const long = when.duration({ min: 600 });

      1.10.0

    • The volume (0–200) is within min ≤ volume < max.

      Parameters

      • bounds: { min?: number; max?: number }

      Returns Condition

      TypeError (throws) As When.duration.

      The item carries a check mark while the volume is above 100, whoever raised it; the player compares its own volume, so the plugin need not follow the state.

      const { when } = plugin;
      const boosted = when.volume({ min: 101 });

      1.10.0

    • The playback rate is within min ≤ rate < max.

      Parameters

      • bounds: { min?: number; max?: number }

      Returns Condition

      TypeError (throws) As When.duration.

      The item is greyed out at normal speed or slower: the condition holds from a rate of just over 1 upwards.

      const { when } = plugin;
      const fast = when.rate({ min: 1.01 });

      1.10.0

    • 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.

      Parameters

      • bounds: { min?: number; max?: number }

      Returns Condition

      TypeError (throws) As When.duration.

      The bound is computed once, when the condition is made, so the condition turns true 45 minutes later and stays true.

      const { when } = plugin;
      const due = when.time({ min: Date.now() + 45 * 60_000 });

      1.10.0

    • The selected audio track is id (AudioTrack.id).

      Parameters

      • id: number

      Returns Condition

      TypeError (throws) id is not an integer.

      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),
      });

      1.10.0

    • The primary subtitle track is id (SubtitleTrack.id).

      Parameters

      • id: string

      Returns Condition

      TypeError (throws) id is not a string of 1–256 characters.

      The item carries a check mark while the track with this id is the primary subtitle, whoever selected it.

      const { when } = plugin;
      const shown = when.subtitleTrack(trackId);

      1.10.0

    • The active audio output device is id (PlayerState.audioOutput.active).

      Parameters

      • id: string

      Returns Condition

      TypeError (throws) id is not a string of 1–256 characters.

      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),
      });

      1.10.0

    open: Condition

    A source is open: any phase but empty (loading, ready, ended, error).

    ready: Condition

    The source is loaded and can play (phase is ready).

    playing: Condition

    The source is ready and not paused.

    paused: Condition

    The source is ready and paused.

    stream: Condition

    The source is a generated stream (PlayerState.kind is stream).

    fullscreen: Condition

    The main window is fullscreen.

    muted: Condition

    The source is muted (PlayerState.muted).

    1.10.0

    maximized: Condition

    The main window is maximized (MainWindowState.maximized).

    1.10.0

    The video shows in the picture-in-picture window.

    1.10.0

    looping: Condition

    An A-B loop is set (PlayerState.loop is not null).

    1.10.0

    position: {
        in(
            ranges: Iterable<PositionRange>,
            options?: { lead?: number },
        ): Condition;
    }

    The playback position. For a trigger only: a command's state refuses it.

    Type Declaration

    • in: function
      • 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.

        Parameters

        • ranges: Iterable<PositionRange>

          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.

        Returns Condition

        TypeError (throws) A start that is not a finite number of 0 or more, an end not after its start, a negative lead.

        limit (throws) More than 1000 ranges.

        const { when } = plugin;
        const near = when.playing.and(when.position.in(spans, { lead: 2 }));

        1.10.0

    1.10.0