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

    Interface Rendering

    plugin.rendering: the player's rendering choice, GPU or software: read it, change the saved choice, restart the player.

    The choice works like a browser's hardware acceleration switch: the player saves it in its own settings at once, and the running player keeps its renderer. The next start uses it, whether the user restarts now through Rendering.restartPlayer or quits and starts the player later. The player can still rule the GPU out at a start (an environment variable, a graphics driver on its denylist, a GPU crash at an earlier start); RenderingState.nextMode and RenderingState.nextReason say what the next start will do.

    The renderer is a choice for the whole player and a restart stops every plugin, so change it only when the user asks. A plugin that only needs to know whether render options work reads SystemInfo.rendering.

    Settings ▸ GPU Rendering (Experimental) carries a check mark while the next start will draw on the GPU, is greyed out with the player's reason where the GPU cannot be chosen, and saves the other choice when picked. state() reads the player's view once; setPreference saves the choice and resolves with the new state, which the item's bound values read again after the handler. The how-to guide adds the restart.

    let state = await plugin.rendering.state();
    plugin.commands.add({
    id: "gpu-rendering",
    path: ["@settings", "GPU Rendering (Experimental)"],
    checked: () => state.nextMode === "gpu", // also for "auto" on a GPU system
    enabled: () => state.gpu.available,
    reason: () => state.gpu.reason?.message ?? null, // shown while disabled
    run: async () => {
    const choice = state.nextMode === "gpu" ? "software" : "gpu";
    state = await plugin.rendering.setPreference(choice);
    },
    });

    0.5.13

    1.5.35

    interface Rendering {
        state(): Promise<RenderingState>;
        setPreference(preference: RenderingPreference): Promise<RenderingState>;
        restartPlayer(): Promise<void>;
    }
    Index
    • Read the renderer drawing now, the saved choice, what the next start will use and whether "gpu" can be chosen.

      Returns Promise<RenderingState>

      unsupported (rejects) A player before 0.5.13, which does not know the request.

      The plugin reads the state once while it starts and keeps it for its menu. Each call asks the player; gpu.available is false, with a reason, where this player has no GPU renderer, without a user interface, or when the driver is ruled out.

      const state = await plugin.rendering.state().catch((error: PluginError) => {
      if (error.code === "unsupported") return null; // a player before 0.5.13
      throw error;
      });
      if (state && !state.gpu.available) console.log(state.gpu.reason?.message);

      1.5.35

    • Save the user's rendering choice. The player writes it to its settings at once; the running player keeps its renderer, and the next start uses the choice whether or not the user restarts now. "auto" and "software" are always accepted.

      Parameters

      Returns Promise<RenderingState>

      The new state; RenderingState.restartPending tells whether a restart would change the renderer.

      invalid (rejects) preference is not "auto", "gpu" or "software".

      unsupported (rejects) "gpu" where this player has no GPU renderer on this system, or runs without a user interface; also any value on a player before 0.5.13.

      unavailable (rejects) "gpu" while it is ruled out: the graphics driver is on the player's denylist, or GPU rendering crashed at an earlier start. The message says which, with the adapter's name and the driver version.

      failed (rejects) The player could not write its settings file.

      A Reset item returns the renderer to the player's own choice and tells the user when it takes effect. setPreference saves the choice and resolves with the new state; restartPending is true when the next start will draw differently from this run. A refused save leaves the old choice in place.

      try {
      const state = await plugin.rendering.setPreference("auto");
      if (state.restartPending) await plugin.osd.show("Applies after a restart");
      } catch (error) {
      // `failed`: the player's settings file could not be written.
      await plugin.osd.show("Not saved ({})", [(error as PluginError).code]);
      }

      1.5.35

    • Restart the player so that a changed choice applies now. Resolves once the player has accepted; the player then quits normally, which stops every plugin (this one included), and starts again with the same plugins. A local file that was open continues at its position, paused or playing as it was; a stream or another source that is not a file is not reopened.

      Returns Promise<void>

      unsupported (rejects) The player runs without a user interface; also a player before 0.5.13.

      busy (rejects) A restart is already under way, or this player was itself started by a restart less than 30 seconds ago (so a plugin that restarts on activation cannot make a loop).

      failed (rejects) The new player process could not be started; the player keeps running.

      After the user changed the renderer, the plugin offers to restart now. confirm asks first, because a restart closes every window; once restartPlayer resolves, the player is quitting and will stop this plugin, so nothing else is started after it.

      const { confirmed } = await plugin.dialogs.confirm({
      message: "Restart the player now?",
      detail: "The new renderer is used from the restart on. The video continues where it is.",
      confirm: "Restart",
      });
      if (confirmed)
      await plugin.rendering.restartPlayer().catch((error: PluginError) => {
      // `failed`: the new player could not start; this one keeps running.
      void plugin.osd.show("Could not restart ({})", [error.code]);
      });

      1.5.35