Skip to content

Audio

1 min read

Import: import system.audio;

Read the audio guide for usage, limits, and current platform restrictions.

Audio

A web-style audio player. Constructors configure sources; load and play perform I/O.

public class Audio

constructor

Creates an empty player. Assign src before calling play.

public constructor()

constructor

Creates a streaming player for a path or HTTP URL without starting I/O.

public constructor(src: string)

constructor

Creates a streaming player for a path or URL with snapshotted buffering limits.

public constructor(src: string, options: AudioOptions)

constructor

Snapshots encoded bytes; detection and decoding begin when loading starts.

public constructor(bytes: byte[])

constructor

Snapshots encoded bytes with a configurable decoded-data limit.

public constructor(bytes: byte[], options: AudioOptions)

constructor

Creates a player from already decoded PCM without including encoded-format decoders.

public constructor(buffer: AudioBuffer)

load

Cancels prior loading and prepares the current source; returns an I/O or decoding error.

public async fun load(): Result<Unit, AudioError>

play

Loads if necessary and starts or resumes playback. Browser activation may be required.

public async fun play(): Result<Unit, AudioError>

pause

Pauses without changing position; repeating pause emits no duplicate event.

public fun pause(): Result<Unit, AudioError>

close

Cancels loading and releases output. Queued events remain available after closure.

public fun close(): void

poll_events

Drains ordered typed notifications, including after close.

public fun poll_events(): AudioEvent[]

src

Current string source; empty for PCM and encoded-byte constructors.

public get src(): string

src

Replaces the source, cancelling prior playback and pending loads.

public set src(value: string)

current_time

Current position in seconds.

public get current_time(): double

current_time

Requests an absolute seek in seconds; invalid requests preserve the current position.

public set current_time(value: double)

duration

Source duration in seconds, absent until metadata is loaded and for streams that do not declare one, such as streamed MP3.

public get duration(): Option<double>

volume

Linear gain from zero to one; mute does not change this value.

public get volume(): float

volume

Sets finite gain from zero to one, preserving the previous value on error.

public set volume(value: float)

muted

Whether this player is muted.

public get muted(): bool

muted

Toggles mute without changing the stored volume.

public set muted(value: bool)

loop

Whether natural completion restarts playback.

public get loop(): bool

loop

Enables repetition of a seekable source.

public set loop(value: bool)

paused

Whether playback is paused, including before the first play call.

public get paused(): bool