Skip to main content
A queue of sounds playing through a [Machine]‘s default audio output. Obtain via [Machine.player]. The handle owns its output device connection: when it is garbage-collected playback stops. Appended sources play back to back; playback starts immediately on append.

Constructor

Returns

AudioPlayer

Properties

boolean
required
Whether the player is currently paused.
number
required
Playback speed; changing it changes pitch by the same factor.
number
required
Volume multiplier; 1.0 is the unfiltered input.

Methods

appendFile()

Decodes an audio file (WAV, MP3, FLAC, Vorbis/OGG, …) on the host and appends it to the playback queue.

Parameters

string
required

appendSamples()

Appends a sound to the end of the playback queue.

Parameters

SamplesBuffer
required

clear()

Removes all queued sounds and pauses the player.

empty()

Whether the queue has no more sounds to play.

Returns

boolean

getPos()

Playback position within the current sound in milliseconds, accounting for speed changes and seeks. Example: if you apply a speedup of 2 to a source and getPos() returns 5000 then the position in the recording is 10 seconds from its start.

Returns

number

len()

The number of sounds currently in the queue.

Returns

number

pause()

Pauses playback; resume with play().

play()

Resumes playback of a paused player. No effect if not paused.

skipOne()

Skips to the next sound in the queue.

sleepUntilEnd()

Blocks the current thread until every queued sound has finished.

stop()

Stops the player by emptying the queue.

trySeek()

Seeks within the current sound to the given position (in milliseconds), saturating at its end when the duration is known. For example given a source that reports a total duration of 42 seconds, calling trySeek(60000) will seek to 42 seconds. This blocks between 0 and ~5 milliseconds.

Parameters

number
required