Adding Players.add example

Fixes #916
This commit is contained in:
Yotam Mann 2021-07-25 08:43:18 -07:00
parent 7ec588f937
commit 26392c29a7

View file

@ -202,6 +202,12 @@ export class Players extends ToneAudioNode<PlayersOptions> {
* @param name A unique name to give the player * @param name A unique name to give the player
* @param url Either the url of the bufer or a buffer which will be added with the given name. * @param url Either the url of the bufer or a buffer which will be added with the given name.
* @param callback The callback to invoke when the url is loaded. * @param callback The callback to invoke when the url is loaded.
* @example
* const players = new Tone.Players();
* players.add("gong", "https://tonejs.github.io/audio/berklee/gong_1.mp3", () => {
* console.log("gong loaded");
* players.get("gong").start();
* });
*/ */
add(name: string, url: string | ToneAudioBuffer | AudioBuffer, callback?: () => void): this { add(name: string, url: string | ToneAudioBuffer | AudioBuffer, callback?: () => void): this {
assert(!this._buffers.has(name), "A buffer with that name already exists on this object"); assert(!this._buffers.has(name), "A buffer with that name already exists on this object");