Skip to content
Tone.js

Players

class Source ↳ extends ToneAudioNode<PlayersOptions>

Players combines multiple Player objects.

new Players(urls?: ToneAudioBuffersUrlMap, onload?: () => void)

Parameters

  • urls ToneAudioBuffersUrlMap optional

    An object mapping a name to a url.

  • onload () => void optional

    The function to invoke when all buffers are loaded.

new Players(urls?: ToneAudioBuffersUrlMap, options?: Partial<Omit<PlayersOptions, "urls">>)

Parameters

new Players(options?: Partial<PlayersOptions>)

Parameters

read-only

input: undefined

Players has no input.

Default: undefined

read-only

name: string

The name of the class

Default: "Players"

read-only

output: OutputNode

The combined output of all of the players

read-only

volume: Param<"decibels">

The volume of the output in decibels.

fadeIn: Time

The fadeIn time of the envelope applied to the source.

fadeOut: Time

The fadeOut time of the each of the sources.

read-only

loaded: boolean

If all the buffers are loaded or not

mute: boolean

Mute the output.

read-only

The state of the players object. Returns “started” if any of the players are playing.

add(name: string, url: string | ToneAudioBuffer | AudioBuffer, callback?: () => void): this

Add a player by name and url to the Players

const players = new Tone.Players();
players.add("gong", "https://tonejs.github.io/audio/berklee/gong_1.mp3", () => {
	console.log("gong loaded");
	players.player("gong").start();
});

Parameters

  • name string

    A unique name to give the player

  • url string | ToneAudioBuffer | AudioBuffer

    Either the url of the buffer or a buffer which will be added with the given name.

  • callback () => void optional

    The callback to invoke when the url is loaded.

Returns this

dispose(): this

Dispose and disconnect

Returns this

has(name: string): boolean

True if the buffers object has a buffer by that name.

Parameters

  • name string

    The key or index of the buffer.

Returns boolean

player(name: string): Player

Get a player by name.

Parameters

  • name string

    The players name as defined in the constructor object or add method.

Returns Player

stopAll(time?: Time): this

Stop all of the players at the given time

Parameters

  • time Time optional

    The time to stop all of the players.

Returns this

static

getDefaults(): PlayersOptions

Returns all of the default options belonging to the class.

Returns PlayersOptions