Skip to content

Audio

const audio = require("@vectarine/audio")
export type AudioResource = ...
AudioResource:play(loop: boolean?, fadeIn: number?): ()

Play an audio resource from its beginning. If loop is true, the audio will loop indefinitely. fadeIn: milliseconds over which the volume rises from silence (default: 100 when starting, 0 when resuming).

A sound plays once at a time: playing it while it plays does nothing. Use pause and resume for that.

AudioResource:isPlaying(): boolean

Returns true if the audio resource is currently playing.

AudioResource:getDuration(): number

Returns the duration of the audio resource in seconds.

AudioResource:getProgress(): number

Returns the current progress of the audio resource in seconds. This is a number between 0 and the duration.

AudioResource:pause(fadeOut: number?): ()

Stop an audio resource. If fadeOut is provided, the audio will fade out over that many milliseconds (it counts as playing until then). Does nothing if the audio is not playing.

AudioResource:resume(fadeIn: number?): ()

Play a paused audio resource again from where it was. If fadeIn is provided, the volume rises from silence over that many milliseconds.

AudioResource:setVolume(volume: number): ()
AudioResource:getVolume(): number