1
0
Fork 0
oldhaven/public/javascripts/audio.js

51 lines
924 B
JavaScript
Raw Normal View History

2011-06-14 16:05:12 +00:00
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()
);
}
}