Tone.Player
↳ EXTENDS Tone.SourceTone.Player is an audio file player with start, loop, and stop functions.
CONSTRUCTOR
new Tone.Player (Either the AudioBuffer or the url from which to load the AudioBuffer
The function to invoke when the buffer is loaded. Recommended to use Tone.Buffer.onload instead.
DEFAULTS
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();.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.
.state
↝ Tone.State READONLY #Returns the playback state of the source, either “started” or “stopped”.
.volume
↝ Decibels #The volume of the output in decibels.
EXAMPLE
source.volume.value = -6;Methods
.load ( )
#The url of the buffer to load. Filetype support depends on the browser.
The function to invoke once the sample is loaded.
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 ( )
#The loop end time
The loop end time
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;.start ( )
#When the source should be started.
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.stop ( )
#When the source should be stopped.
this
Stop the source at the specified time. If no time is given, stop the source now.
EXAMPLE
source.stop(); // stops the source immediately.sync ( )
#Delay time before starting the source after the Transport has started.
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();.unsync ( )
#this
Unsync the source to the Transport. See Tone.Source.sync