Players
class Source ↳ extends ToneAudioNode<PlayersOptions>
Players combines multiple Player objects.
Constructor
Section titled “Constructor”new Players(urls?: ToneAudioBuffersUrlMap, onload?: () => void)Parameters
-
urls
ToneAudioBuffersUrlMapoptionalAn object mapping a name to a url.
-
onload
() => voidoptionalThe function to invoke when all buffers are loaded.
new Players(urls?: ToneAudioBuffersUrlMap, options?: Partial<Omit<PlayersOptions, "urls">>)Parameters
-
urls
ToneAudioBuffersUrlMapoptionalAn object mapping a name to a url.
-
options
Partial<Omit<PlayersOptions, "urls">>optionalThe remaining options associated with the players
new Players(options?: Partial<PlayersOptions>)Parameters
- options
Partial<PlayersOptions>optional
Properties
Section titled “Properties”output
Section titled “output”read-only
output: OutputNodeThe combined output of all of the players
volume
Section titled “volume”read-only
volume: Param<"decibels">The volume of the output in decibels.
read-only
state: BasicPlaybackStateThe state of the players object. Returns “started” if any of the players are playing.
Methods
Section titled “Methods”add(name: string, url: string | ToneAudioBuffer | AudioBuffer, callback?: () => void): thisAdd 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
stringA unique name to give the player
-
url
string | ToneAudioBuffer | AudioBufferEither the url of the bufer or a buffer which will be added with the given name.
-
callback
() => voidoptionalThe callback to invoke when the url is loaded.
Returns this
has(name: string): booleanTrue if the buffers object has a buffer by that name.
Parameters
-
name
stringThe key or index of the buffer.
Returns boolean
player()
Section titled “player()”player(name: string): PlayerGet a player by name.
Parameters
-
name
stringThe players name as defined in the constructor object or
addmethod.
Returns Player
stopAll()
Section titled “stopAll()”stopAll(time?: Time): thisStop all of the players at the given time
Parameters
-
time
TimeoptionalThe time to stop all of the players.
Returns this
getDefaults()
Section titled “getDefaults()”static
getDefaults(): PlayersOptionsReturns all of the default options belonging to the class.
Returns PlayersOptions
Inherited members
Section titled “Inherited members”- From
ToneWithContext: context, blockTime, sampleTime, get(), immediate(), now(), set(), toFrequency(), toSeconds(), toTicks() - From
Tone: debug, version, disposed, toString() - From
ToneAudioNode: channelCount, channelCountMode, channelInterpretation, numberOfInputs, numberOfOutputs, chain(), connect(), disconnect(), fan(), toDestination(), toMaster()