Note that the behavior will vary from one browser to another. In Chrome, you have a different type of download. When resources are not in the cache , it will extract either the full file (for example, for js or css), or part of the file (for example, mp3). This partial file contains metadata , which allows the browser to determine the duration and other data, such as the time it takes to download the entire file at that speed, for example, canplay or canplaythrough . If you look at network usage in your dev console, you will see that the HTTP status code will be either 200 (successful download) or 206 (partial download - for mp3, for example).
When you click refresh , items are checked to see if they have changed. The HTTP status will be 304 , that is, the file has not been changed. If it has not changed and is still in the browser cache, it will not load. A call to determine whether it has been modified or not comes from the server providing the file.
When you simply press enter in the address bar, it is automatically taken from the cache, and not checked online. So it is much faster.
Thus, depending on how you call or refresh your page (or just enter, refresh or fill out the update without a cache), you will have big differences from the moment you get metadata from your mp3. Between receiving metadata from the cache directly and receiving a request to the server, the difference can be several hundred milliseconds, which is enough to change what data is available at another moment.
In this case, listening to loadedmetada should give a consistent result. This event is triggered when data with information about the duration is loaded, therefore, regardless of the page loading method, it does not matter if this called message is executed correctly. At this point, you should consider intervening with some other elements. What you have to do is follow your sound through various events to determine exactly where it is at different times. Therefore, in your document you can add listeners for different events and see where this problem is. Like this:
$('audio')[0].addEventListener('loadstart', check_event) $('audio')[0].addEventListener('loadeddata', check_event) $('audio')[0].addEventListener('loadedmetadata', check_event)
You will see that depending on how you are updating, these events may occur at different times, possibly explaining inconsistencies in your results.