Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return file object onComplete #2

Open
iforwms opened this issue Dec 5, 2015 · 0 comments
Open

Return file object onComplete #2

iforwms opened this issue Dec 5, 2015 · 0 comments

Comments

@iforwms
Copy link

iforwms commented Dec 5, 2015

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);

      }
   }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants