This was a problem that got me stuck for a day. JQuery just cannot seem to load an audio file because the return type is always a string.
The solution that I came up with was to use traditional Javascript code using XMLHttpRequest.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
var xhr = new XMLHttpRequest(); xhr.addEventListener('progress', function(e) { if (e.lengthComputable) { var percentComplete = e.loaded / e.total; console.log('Status: Downloading: ' + percentComplete + '%'); } }); xhr.addEventListener('load', function(blob) { if (xhr.status == 200) { audio.src = window.URL.createObjectURL(xhr.response); } }); xhr.open('GET', src); xhr.responseType = 'blob'; xhr.send(null); |
There could be JQuery plugins that can do this but I was not able to find any. Traditional XMLHttpRequest can still do a lot of wonders ;).