var Audio = { audio: null, tid: null, init: function() { this.audio = document.getElementById('a'); }, play: function() { this.audio.play(); }, pause: function() { this.audio.pause(); }, setTrack: function(url) { this.audio.setAttribute('src', url); }, getLoadedPercent: function() { try { return Audio.audio.buffered.end(0) / Audio.audio.duration; } catch(e) {} return 0; }, getPlayedPercent: function() { try { return Audio.audio.currentTime / Audio.audio.duration; } catch(e) {} return 0; }, setPlayedPercent: function(val) { if (typeof(this.audio.duration) != undefined) { this.audio.currentTime = Math.round(val * this.audio.duration / 100); return true; } return false; }, startListener: function() { Audio.tid = window.setTimeout(Audio.startListener, 100); Player.updateUI( Audio.getLoadedPercent(), Audio.getPlayedPercent() ); } }