/** * File-based playback — load audio assets, then play / pause / fade / * seek / etc. Every function in this module operates on the shared * `audioState.tracks` map exposed from `backend.ts`, so the audio module's * other surfaces (track helpers, mix, unload) can see the same set of * loaded sounds. */ import type { LoadSettings, PannerAttributes, PlayOptions, SoundAsset } from "./types.ts"; /** * Load an audio file. * * `sound.src` is treated as a base path / prefix; the URL is built as * `${sound.src}${sound.name}.${ext}` for each extension configured by * {@link init}, until one loads. Data URLs (`data:audio/...`) are * used as-is and skip the prefix-and-extension dance. * @param sound - The {@link SoundAsset} descriptor — logical `name`, * `src` base path / prefix (or data URL), and optional playback * flags (`autoplay`, `loop`, `stream`, `html5`). * @param onloadcb - Called when the resource has finished loading. * @param onerrorcb - Called when loading fails. * @param settings - Optional {@link LoadSettings} — `nocache` (query * string appended for cache busting) and `withCredentials` (forwarded * to the underlying XHR for cross-origin authenticated requests). * @returns The number of assets loaded (always `1` on success). * @category Audio */ export declare function load(sound: SoundAsset, onloadcb?: () => void, onerrorcb?: () => void, settings?: LoadSettings): number; /** * Play the specified sound. * @param sound_name - Audio clip name (case-sensitive). * @param loopOrOptions - Whether to loop the clip (defaults to `false`), or a * {@link PlayOptions} object. The object form is the only way to name a * sprite region; the boolean form is unchanged. * @param onend - Called when the sound instance ends playing. * @param volume - Playback volume, `0.0..1.0`. Defaults to the current * global volume. * @returns The sound instance ID. * @example * // play the "cling" audio clip * me.audio.play("cling"); * // play & loop the "engine" audio clip * me.audio.play("engine", true); * // play the "gameover_sfx" audio clip and call myFunc when finished * me.audio.play("gameover_sfx", false, myFunc); * // play the "gameover_sfx" audio clip at half volume * me.audio.play("gameover_sfx", false, null, 0.5); * // play a named region of a sprite sheet, at half volume * me.audio.play("sfx", { sprite: "jump", volume: 0.5 }); * @category Audio */ export declare function play(sound_name: string, loopOrOptions?: boolean | PlayOptions, onend?: (() => void) | null, volume?: number): number; /** * Fade a currently playing sound between two volumes. * @param sound_name - Audio clip name (case-sensitive). * @param from - Volume to fade from, `0.0..1.0`. * @param to - Volume to fade to, `0.0..1.0`. * @param duration - Fade time in milliseconds. * @param id - Sound instance ID. When omitted, all sounds in the group * are faded. * @category Audio */ export declare function fade(sound_name: string, from: number, to: number, duration: number, id?: number): void; /** @inheritDoc */ export declare function seek(sound_name: string): number; /** @inheritDoc */ export declare function seek(sound_name: string, seek: number, id?: number): void; /** @inheritDoc */ export declare function rate(sound_name: string): number; /** @inheritDoc */ export declare function rate(sound_name: string, rate: number, id?: number): void; /** @inheritDoc */ export declare function stereo(sound_name: string): number; /** @inheritDoc */ export declare function stereo(sound_name: string, pan: number, id?: number): void; /** @inheritDoc */ export declare function position(sound_name: string): [number, number, number]; /** @inheritDoc */ export declare function position(sound_name: string, x: number, y?: number, z?: number, id?: number): void; /** @inheritDoc */ export declare function orientation(sound_name: string): [number, number, number]; /** @inheritDoc */ export declare function orientation(sound_name: string, x: number, y?: number, z?: number, id?: number): void; /** * Get or set the panner-node attributes for a sound or sound group. * @param sound_name - Audio clip name (case-sensitive). * @param attributes - The {@link PannerAttributes} to apply (cone angles, * distance model, panning algorithm, …). See the interface for * per-field defaults. * @param id - Sound instance ID. When omitted, all sounds in the group * are affected. * @returns The resulting {@link PannerAttributes} after the update. * @example * me.audio.panner("cling", { * panningModel: "HRTF", * refDistance: 0.8, * rolloffFactor: 2.5, * distanceModel: "exponential", * }); * @category Audio */ export declare function panner(sound_name: string, attributes?: PannerAttributes, id?: number): PannerAttributes; /** * Stop the specified sound on all channels. * @param sound_name - Audio clip name (case-sensitive). When omitted, * every sound currently playing is stopped. * @param id - Sound instance ID. When omitted, all sounds in the group * are stopped. * @example * me.audio.stop("cling"); * @category Audio */ export declare function stop(sound_name?: string, id?: number): void; /** * Pause the specified sound on all channels. Does not reset the * current playback position. * @param sound_name - Audio clip name (case-sensitive). * @param id - Sound instance ID. When omitted, all sounds in the group * are paused. * @example * me.audio.pause("cling"); * @category Audio */ export declare function pause(sound_name: string, id?: number): void; /** * Resume the specified sound on all channels. * @param sound_name - Audio clip name (case-sensitive). * @param id - Sound instance ID. When omitted, all sounds in the group * are resumed. * @example * // play an audio clip * let id = me.audio.play("myClip"); * // ... * // pause it * me.audio.pause("myClip", id); * // ... * // resume * me.audio.resume("myClip", id); * @category Audio */ export declare function resume(sound_name: string, id?: number): void; /** * Get the duration of an audio clip, in seconds. * * With no `id`, returns the duration of the whole clip; with one, the duration * of the region that instance is playing, which differs when the instance was * started from a sprite. * @param sound_name - Audio clip name (case-sensitive). * @param id - Sound instance ID. Omit for the whole clip. * @returns Duration in seconds, or `0` while the clip is still loading. * @example * const total = me.audio.duration("theme"); * @category Audio */ export declare function duration(sound_name: string, id?: number): number; /** * Check whether an audio clip is currently playing. * * With no `id`, reports whether *any* instance of the clip is playing; with * one, only that instance. * @param sound_name - Audio clip name (case-sensitive). * @param id - Sound instance ID. Omit to ask about the whole group. * @returns `true` when playing. * @example * if (!me.audio.playing("theme")) { * me.audio.play("theme", true); * } * @category Audio */ export declare function playing(sound_name: string, id?: number): boolean; /** * Get the load state of an audio clip. * * Useful when a clip was declared with `preload: false`, or to tell "still * loading" apart from "loaded but silent". * @param sound_name - Audio clip name (case-sensitive). * @returns `"unloaded"`, `"loading"` or `"loaded"`. * @example * if (me.audio.state("theme") === "loaded") { ... } * @category Audio */ export declare function state(sound_name: string): "unloaded" | "loading" | "loaded"; //# sourceMappingURL=playback.d.ts.map