alt.Audio

Used to create an audio source for an .ogg file.

This documentation covers all additional functionality that comes with audio.

Declaration

alt.Audio(source: string, volume: number, category?: string, play2D?: boolean): Audio

Usage

const audio = new alt.Audio('@audio/client/test.ogg', 1, 'test', false);

Real World Example

Plays audio based on the local player entity.

const audio = new alt.Audio('@audio/client/test.ogg', 1, 'test', false);
audio.addOutput(alt.Player.local.scriptID);
audio.play();

audio.category

Returns the current category of the audio.

Declaration

audio.category: string

Usage

const currentCategory = audio.category;

audio.currentTime

Returns the current time in milliseconds of the audio.

Declaration

audio.currentTime: number

Usage

const currentTimeInMS = audio.currentTime;

audio.frontendPlay

Returns if this audio is playing as a 2D.

Declaration

audio.frontendPlay: boolean

Usage

const isFrontendAudio = audio.frontendPlay;

audio.looped

Returns if this audio is set to be looping or not.

Declaration

audio.looped: boolean

Usage

const isLooping = audio.looped;

audio.playing

Returns the maximum time of the track in milliseconds.

Declaration

audio.playing: boolean

Usage

const playing = audio.playing;

audio.playing

Returns whether or not the audio source is currently playing.

Declaration

audio.playing: number

Usage

const playing = audio.playing;

audio.source

Returns the audio source that is currently in-use.

Otherwise, the audio source can be set as well.

Declaration

audio.source: number

Usage

const source = audio.source;

// OR

audio.source = '@audio/client/otherFile.ogg'

audio.volume

Returns the current audio source volume

Otherwise, the audio source volume can be set.

Declaration

audio.volume: number

Usage

const volume = audio.volume;

// OR

audio.volume = 100;

audio.addOutput

Allows a target entity be set as the source of where the audio is coming from. Entity being a player, vehicle, local player, etc.

Declaration

audio.addOutput(entity: number | Entity): void

Usage

const audio = new alt.Audio('@audio/client/test.ogg', 1, 'test', false);
audio.addOutput(alt.Player.local.vehicle.scriptID);
audio.play();

audio.getOutputs

Returns an array of entity numbers that are currently playing the audio output on them. If a single output is specified you will only get the number of the entity. Otherwise, you will get an array of entities.

Declaration

audio.getOutputs(): number | Entity[]

Usage

const outputs = audio.getOutputs();

if (Array.isArray(outputs)) {
    console.log('many outputs');
} else {
    console.log('single output');
}

audio.on('streamEnded')

An event that gets emitted when the audio source is done playing.

Declaration

audio.on(event: 'streamEnded', callback: Function): void

Usage

audio.on('streamEnded' () => {
    console.log(`The audio stream has ended.`);
});

audio.on('error')

An event that gets emitted when the audio source is invalid or something has gone wrong with loading the audio source.

Declaration

audio.on(event: "error", callback: (code: number, message: string) => void): void

Usage

audio.on('error' (code: number, message: string) => {
    console.log(`Got Error: ${code} ${message} for Audio`);
});

audio.play

A function to start the playback of the audio.

Declaration

audio.play(): void;

Usage

audio.play();

audio.pause

A function to pause the audio playback.

Declaration

audio.pause(): void;

Usage

audio.pause();

audio.removeOutput

A function to remove the audio playback from an entity.

Declaration

audio.removeOutput(entity: number | Entity): void;

Usage

audio.removeOutput(alt.Player.local.scriptID);

audio.reset

Should completely reset / restart the audio and stop it from playing.

Should, there's no real example of usage for this.

Declaration

audio.reset(): void;

Usage

audio.reset();

audio.seek

Should seek to a different time in the audio track in milliseconds.

Declaration

audio.seek(time: number): void;

Usage

audio.seek(5000); // 5 seconds in

These examples assume you have imported alt from alt-client.

results matching ""

    No results matching ""