Drag and Drop Audio Bug?

Not sure what's going on here, but I tried to create a drag and drop option to play audio (for now that's all it does), but if I drop in a second audio file before the first one has finished, it just plays both at once instead of replacing the first one. I based it around the example for Dom titled "Drop".

Code looks like this:

var aud;

function setup() { // create canvas var c = createCanvas(710, 400); background(100); // Add an event for when a file is dropped onto the canvas c.drop(gotFile); }

function draw() { fill(255); noStroke(); textSize(24); textAlign(CENTER); text('Drag an audio file onto the canvas.', width/2, height/2); noLoop(); }

function gotFile(file) { if (file.type === 'audio') { // Create an sound element but don't show it aud = loadSound(file.data, gotAudio,loading);

} else { println('Not an audio file!'); }
function gotAudio(){ aud.play(); }
function loading(progress){ print(progress); } }

Answers

Sign In or Register to comment.