Interface MPV

The MPV module provides direct access to mpv's API, including properties, commands, and hooks.

Remarks

Setting a window-related property in mpv, such as fullscreen, may also work in IINA. However, it is recommended to use IINA's own API when possible.

Seealso

Please make sure to check out mpv's documentation before using this module.

For MPV events, use the event module.

Available In Entry

Main entry only

Hierarchy

  • MPV

Methods

  • Get a property as a boolean (flag).

    Example

    // is muted?
    let muted = mpv.getFlag("mute");

    Parameters

    • name: string

      The name of the property.

    Returns boolean

  • Get a property as a number.

    Remarks

    Internally, it always reads the double format of the property, i.e. using mpv's MPV_FORMAT_DOUBLE, because JavaScript doesn't distinguish between integers and floats.

    Example

    // get the raw byte positon in the source stream
    let pos = mpv.getNumber("stream-pos");

    Parameters

    • name: string

      The name of the property.

    Returns number

  • Get a property as a string. Most mpv properties are available as strings.

    Example

    // get the pixel format of the current video
    let pm = mpv.getString("video-params/pixelformat");

    Parameters

    • name: string

      The name of the property.

    Returns string

  • Try to get the property as a native JavaScript object. It's useful for getting dictionaries (e.g. video-params) and lists (e.g. vf).

    Example

    // get the current video's parameters
    let params = mpv.getNative("video-params");
    // => { "stereo-in": "mono", "h": 1080, "w": 1920, "chroma-location": "mpeg2/4/h264", ... }

    Type Parameters

    • T

    Parameters

    • name: string

      The name of the property.

    Returns T

  • Set the value of a property.

    Parameters

    • name: string

      The name of the property.

    • value: any

      The value to set. If the value is a JavaScript object, it will be treated as a dictionary and converted to a mpv node.

    Returns void

  • Run a mpv command.

    Example

    // seek to 00:10, at the nearest keyframe
    mpv.command("seek", ["10", "absolute+keyframes"]);

    Parameters

    • name: string

      The name of the command.

    • args: string[]

      The argument list.

    Returns void

  • Adds a mpv hook.

    Example

    // the user opened an unrecognized web URL;
    // run an external handler (e.g. yt-dlp) to get the actual video URL
    mpv.addHook("on_load", 50, async (next) => {
    // get the current URL
    const url = mpv.getString("stream-open-filename");
    // run the external parser
    const actualURL = await runCustomHandler(url);
    // set the actual URL
    mpv.set("stream-open-filename", actualURL);
    // continue loading the video; MUST be called if the callback is async
    next();
    });

    Seealso

    mpv's hook API.

    Parameters

    • name: string

      The name of the hook, such as on_load or on_load_fail.

    • priority: number

      The priority of the hook, should be an integer. Higher priority hooks are executed first.

    • callback: ((next?: (() => void)) => void)

      The callback function to run when the hook is triggered. If it is an async function, the next function must be called manually when the hook is finished. If it is a normal function, the next function should be ignored. The hook callback is considered finished when the function returns.

        • (next?: (() => void)): void
        • Parameters

          • Optional next: (() => void)

            The function to call when the hook is finished, if the callback is async.

              • (): void
              • The function to call when the hook is finished, if the callback is async.

                Returns void

          Returns void

    Returns void

Generated using TypeDoc