melonJS
    Preparing search index...

    Interface SoundAsset

    Sound asset descriptor passed to audio.load.

    interface SoundAsset {
        autoplay?: boolean;
        format?: string | string[];
        html5?: boolean;
        loop?: boolean;
        mute?: boolean;
        name: string;
        on?: SoundEvents;
        pool?: number;
        preload?: boolean | "metadata";
        rate?: number;
        sprite?: Record<string, [number, number] | [number, number, boolean]>;
        src: string;
        stream?: boolean;
    }
    Index
    autoplay?: boolean

    Begin playback immediately on load. Defaults to false.

    format?: string | string[]

    Explicit format hint, for sources whose extension cannot be read from the URL (a blob, or a URL without one).

    html5?: boolean

    Force the HTML5 <audio> element backend instead of WebAudio decoding. Defaults to false.

    loop?: boolean

    Loop playback when the clip ends. Defaults to false.

    mute?: boolean

    Start muted. Defaults to false.

    name: string

    Logical name used to play / stop / reference the sound later.

    Lifecycle callbacks for this clip. Each is optional and fires for every instance of the clip.

    pool?: number

    How many finished instances of this clip are kept around for reuse before being discarded. Defaults to 5.

    This does not limit how many instances can play at once — it trades memory against the cost of recreating an instance for a clip that is triggered rapidly.

    preload?: boolean | "metadata"

    When the clip is downloaded. Defaults to true.

    • true: during the preload, so it plays the moment it is asked to.
    • false: when it is first played (audio.play, audio.playTrack, or autoplay). That play fetches it and streams it, as stream: true does, so the sound starts as soon as enough of the file has arrived rather than once all of it has. A clip never played is never downloaded: for music a player may not reach, such as a boss or an ending theme, that keeps the wait before the game starts short. As a streamed clip it plays through an <audio> element, so positional sound (follow, at, stereo) does not apply to it.
    • "metadata": on a streamed clip, only enough to know its duration during the preload, the rest when it plays. A buffered clip is downloaded whole either way.
    rate?: number

    Initial playback rate, 0.5..4.0. Defaults to 1.0.

    sprite?: Record<string, [number, number] | [number, number, boolean]>

    Named regions within a single file, each [start, duration] in milliseconds, with an optional third element marking the region as looping. Lets one download carry many effects.

    loader.preload([{
    type: "audio", name: "sfx", src: "data/sfx/",
    sprite: { jump: [0, 450], hit: [2000, 250], music: [4000, 12000, true] },
    }]);
    // then
    audio.play("sfx", { sprite: "jump" });
    src: string

    Base path / prefix for the audio resource. The loader builds the full URL as ${src}${name}.${ext} for each format configured by audio.init(), so src is typically a directory ending in /. Data URLs (data:audio/...) are used as-is and skip the prefix

    • extension construction.
    stream?: boolean

    Stream the resource instead of fully decoding upfront — preferred for long music tracks. It is still fetched during the preload; add preload: false to fetch it only when it is first played. Plays through an <audio> element, so positional sound (follow, at, stereo) does not apply to it. Defaults to false.