How to get the length of time that audio has been loaded (non-playback time)

how do I use JavaScript to get the length of data that the audio element has loaded?

<audio  id="audio" src="./static/audio/audio1.mp3" preload="none"></audio>
<div class="play_control">
     <img class="play_btn" src="./static/img/stop.png" alt="play">
     <span id="time">00:00</span>
     <span id="duration">/00:00</span>
     <div class="process">
          <span id="loaded"></span>
          <span id="playing_time"></span>
     </div>
 </div>
 

loaded progress bar is used as data loading progress bar and playing_time as playback progress bar, but I don"t know how to get the length of data loaded from the background, and it is incorrect to use the buffered property in using progress events.

Apr.10,2021

if the progress time of audio is not accurate, I think we can write a middleware responsible for loading, which is responsible for counting the current loading progress, and then feed it to audio with ObjectURL

.
Menu