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 full code: get buffered end


<audio id="music" controls>
  <source src="https://archive.org/download/musicTestAudio27/Very%20nice%20%2827%29.mp3" type="audio/mpeg">
    <div id="buffered"></div>


    border:solid #ccc 1px;


var track = document.getElementById("music");
var w = 100*(track.buffered.end(0))/track.duration;
}, 1000);

but Firefox give me an error message said:

IndexSizeError: Index or size is negative or greater than the allowed amount

var w = 100*(track.buffered.end(0))/track.duration;

and Google chrome said:

Uncaught IndexSizeError: Failed to execute 'end' on 'TimeRanges': The index provided (0) is greater than or equal to the maximum bound (0).


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;

Collected from the Internet

Please contact javaer1[email protected] to delete if infringement.

edited at


Login to comment


In golang, why does my program run slower when I use a buffered (asynchronous) channel?

When I try and run pyspark.cmd I get the error message "find: 'version': No such file or directory"

Why do I get an error for "__CrtGetFileInformationByHandleEx " when I try to compile

Why I get error when I try to create stored procedure?

Why I get error message when transfer INSERT method to Function

Displaying Buffered percentage of Audio

How can i get a number obtained from a buffered reader file?

When running an ansible playbook via a shell script in Jenkins pipeline, the echo output is buffered and does not show in real time

How do I get a better error message when I try to pip install with an incompatible python version?

Why I get error when try append element to document?

Why Do I get an error when I try to get tkinter slider value?

Why do I get an error message pointing to Inf values when trying to plot counts over time in R?

Why did i get every time an Syntax error when i try to put an Variable in an Xpath

Why do I get a message saying "Object is not a function" when I try to do an apply?

Buffered audio in SoundJS

I get this error when I try to install

Why does my activity crash when I try to get a number?

How to know when AVPlayerItem is buffered to the end of a song

Why do I get an error message of NoneType object is not callable when I try to call this function?

Why I get error when I try to install pyaudio?

I get error message "runtime error: index out of range [0] with length 0" when I try to start minikube

I get a syntax error when I try to send a discord message

Why I get error when I try to declare local variable?

Why I get an error when I try to upload a picture

Why do I get error when try to convert Carbon to DateTime?

I get an error message when i try to parse an XML response using REST assured

Python/Terminal - Why am I getting this error message when I try to get user input

Buffered function to get line command parameters

Why I get error when try build image in docker?