Why Does Audio.buffered.end(0) Get An Error Message When I Try To Get Buffered Time
I'm building mp3 playlist player with HTML5 and jQuery. At this player there is a horizontal bar grow gradually in conjunction with the buffered present of mp3 file. here is my ful
Solution 1:
I believe that error is coming when accessing buffered.end before the element is initialized. you can rewrite that code as to avoid it
track = document.getElementById("music");
track.onprogress = function(){
var w = 100*(track.buffered.end(0))/track.duration;
$('#buffered').css("width",w+"%");
}
Solution 2:
track = document.getElementById("music");
track.onprogress = function(){
if(track.buffered.length>0){
var w = 100*(track.buffered.end(0))/track.duration;
$('#buffered').css("width",w+"%");
}
}
Solution 3:
The accepted answer doesn't solve the problem for me. You also should check that the track has loaded before you access buffered.end like so:
track.onprogress = function(){
if (track.readyState === 4){
var w = 100*(track.buffered.end(0))/track.duration;
$('#buffered').css("width",w+"%");
}
}
Post a Comment for "Why Does Audio.buffered.end(0) Get An Error Message When I Try To Get Buffered Time"