javascript - Feed FileReader from server side files -
i´m starting customize/improve old audio editor project. can import audio tracks canvas via drag&drop computer. thing use audio tracks stored in server clicking on list of available tracks... instead of use <input type="file">
tags. how can read server side files filereader?ajax perhaps? in advance.
this code file reader:
player.prototype.loadfile = function(file, el) { //console.log(file); var reader = new filereader, filetypes = ['audio/mpeg', 'audio/mp3', 'audio/wave', 'audio/wav'], = this; if (filetypes.indexof(file.type) < 0) { throw('unsupported file format!'); } reader.onloadend = function(e) { if (e.target.readystate == filereader.done) { // done == 2 $('.progress').children().width('100%'); var onsuccess = function(audiobuffer) { $(el).trigger('audiee:fileloaded', [audiobuffer, file]); }, onerror = function() { // on error - show alert modal var tpl = (_.template(alertt))({ message: 'error while loading file ' + file.name + '.' }), $tpl = $(tpl); $tpl.on('hide', function() { $tpl.remove() }) .modal(); // show modal window // hide new track modal $('#newtrackmodal').modal('hide'); }; that.context.decodeaudiodata(e.target.result, onsuccess, onerror); } }; // note: maybe move different module... reader.onprogress = function(e) { if (e.lengthcomputable) { $progress = $('.progress', '#newtrackmodal'); if ($progress.hasclass('hide')) $progress.fadein('fast'); // show loading progress var loaded = math.floor(e.loaded / e.total * 100); $progress.children().width(loaded + '%'); } }; reader.readasarraybuffer(file); }; return player;
maybe need not think in terms of filereader, create abstraction provides desired functionality , select different implementations based on kind of resource need access. may use xmlhttprequest resources located @ server (an http request), , filereader local files.
you can see similar solution implemented in winamp2-js project: https://github.com/captbaritone/winamp2-js/blob/master/js/my-file.js
Comments
Post a Comment