Samplers let you play back audio samples mapped to different notes. Players are for playing audio files directly with control over playback.
Below is a simple sampler that maps a few piano notes to audio files. Press buttons to play notes!
Players play back whole audio files. Click the button below to play a sound file.
// Create a sampler mapped to audio files
const sampler = new Tone.Sampler({
urls: {
"C4": "C4.mp3",
"D#4": "Ds4.mp3", // D#4 note sample filename is usually Ds4.mp3
"F#4": "Fs4.mp3",
"A4": "A4.mp3",
"C5": "C5.mp3"
},
baseUrl: "https://tonejs.github.io/audio/salamander/",
}).toDestination();
// Create a player for a full audio file
const player = new Tone.Player("https://tonejs.github.io/audio/loop/FWDL.mp3").toDestination();