soundcloud-waveform-generator
soundcloud-waveform-generator copied to clipboard
Return file object onComplete
Is it possible to modify the onComplete function to accept a third argument and return the file object or make it available?
At the moment I'm not sure how I can relate the generated waveform with the file it was created for.
for (var i = 0; i < tracks.files.length; i++) {
var track = tracks.files[i];
track.id = i;
// Generate waveforms
SoundCloudWaveform.generate(track, {
onComplete: function(png, pixels) {
var id = track.id; // Returns the final value of i, not the current iteration
var canvas = document.createElement('canvas');
canvas.setAttribute('id', 'canvas' + id);
document.getElementById('track' + id).appendChild(canvas);
canvas.setAttribute('class', 'waveform');
var context = canvas.getContext('2d');
context.putImageData(pixels, 0, 0);
}
}
}