xxxxxxxxxx
19
let mySound;
function preload() {
soundFormats('mp3');
mySound = new p5.SoundFile('https://interactive-examples.mdn.mozilla.net/media/examples/t-rex-roar.mp3')
}
function setup() {
let cnv = createCanvas(100, 100);
cnv.mousePressed(canvasPressed);
background(220);
text('tap here to play', 10, 20);
}
function canvasPressed() {
// playing a sound file on a user gesture
// is equivalent to `userStartAudio()`
mySound.play();
}