Skip to content

Instantly share code, notes, and snippets.

@mukulmishra18
Created March 1, 2018 14:39
Show Gist options
  • Save mukulmishra18/f0d2d97a430efe4e7288012a0baf65dd to your computer and use it in GitHub Desktop.
Save mukulmishra18/f0d2d97a430efe4e7288012a0baf65dd to your computer and use it in GitHub Desktop.
.declareMethod('calculateDuration', function (data) {
// Create a temporary audio element and assign the data to
// calculate the time duration.
var gadget = this,
audioElement = document.createElement('audio');
audioElement.src = URL.createObjectURL(data);
return RSVP.Queue()
.push(function () {
return promiseEventListener(
audioElement,
'loadedmetadata',
false
);
})
.push(function () {
gadget.duration = audioElement.duration;
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment