Tone.Player

↳ EXTENDS Tone.Source

Tone.Player is an audio file player with start, loop, and stop functions.

CONSTRUCTOR

new Tone.Player (
url
, [
onload
] )
url

Either the AudioBuffer or the url from which to load the AudioBuffer

type: string or AudioBuffer
onload

The function to invoke when the buffer is loaded. Recommended to use Tone.Buffer.onload instead.

type: function
optional

DEFAULTS

{
onload : Tone.noOp ,
playbackRate : 1 ,
loop : false ,
autostart : false ,
loopStart : 0 ,
loopEnd : 0 ,
retrigger : false ,
reverse : false
}

EXAMPLE

var player = new Tone.Player("./path/to/sample.mp3").toMaster();
Tone.Buffer.onload = function(){
	player.start();
}

Members

.autostart

↝ boolean #

If the file should play as soon as the buffer is loaded.

EXAMPLE

//will play as soon as it's loaded
var player = new Tone.Player({
	"url" : "./path/to/sample.mp3",
	"autostart" : true,
}).toMaster();
</>

.buffer

↝ Tone.Buffer #

The audio buffer belonging to the player.

</>

.loop

↝ boolean #

If the buffer should loop once it’s over.

</>

.loopEnd

↝ Time #

If loop is true, the loop will end at this position.

</>

.loopStart

↝ Time #

If loop is true, the loop will start at this position.

</>

.playbackRate

↝ number #

The playback speed. 1 is normal speed. This is not a signal because Safari and iOS currently don’t support playbackRate as a signal.

</>

.retrigger

↝ boolean #

Enabling retrigger will allow a player to be restarted before the the previous ‘start’ is done playing. Otherwise, successive calls to Tone.Player.start will only start the sample if it had played all the way through.

</>

.reverse

↝ boolean #

The direction the buffer should play in

</>
↳ inherited from Tone.Source

.state

↝ Tone.State READONLY #

Returns the playback state of the source, either “started” or “stopped”.

</>
↳ inherited from Tone.Source
∿

.volume

↝ Decibels #

The volume of the output in decibels.

EXAMPLE

source.volume.value = -6;
</>

Methods

.dispose ( )

#
↪ returns Tone.Player

this

Dispose and disconnect.

</>

.load ( )

#
url

The url of the buffer to load. Filetype support depends on the browser.

type: string
callback

The function to invoke once the sample is loaded.

optional
↪ returns Tone.Player

this

Load the audio file as an audio buffer. Decodes the audio asynchronously and invokes the callback once the audio buffer loads. Note: this does not need to be called if a url was passed in to the constructor. Only use this if you want to manually load a new url.

</>

.setLoopPoints ( )

#
loopStart

The loop end time

type: Time
loopEnd

The loop end time

type: Time
↪ returns Tone.Player

this

Set the loop start and end. Will only loop if loop is set to true.

EXAMPLE

//loop 0.1 seconds of the file. 
player.setLoopPoints(0.2, 0.3);
player.loop = true;
</>
↳ inherited from Tone.Source

.start ( )

#
time

When the source should be started.

type: Time
default: now
↪ returns Tone.Source

this

Start the source at the specified time. If no time is given, start the source now.

EXAMPLE

source.start("+0.5"); //starts the source 0.5 seconds from now
</>
↳ inherited from Tone.Source

.stop ( )

#
time

When the source should be stopped.

type: Time
default: now
↪ returns Tone.Source

this

Stop the source at the specified time. If no time is given, stop the source now.

EXAMPLE

source.stop(); // stops the source immediately
</>
↳ inherited from Tone.Source

.sync ( )

#
delay

Delay time before starting the source after the Transport has started.

type: Time
default: 0
↪ returns Tone.Source

this

Sync the source to the Transport so that when the transport is started, this source is started and when the transport is stopped or paused, so is the source.

EXAMPLE

//sync the source to start 1 measure after the transport starts
source.sync("1m");
//start the transport. the source will start 1 measure later. 
Tone.Transport.start();
</>
↳ inherited from Tone.Source

.unsync ( )

#
↪ returns Tone.Source

this

Unsync the source to the Transport. See Tone.Source.sync

</>
docs generated Sep 15 2019