I wanted to play the audio from a specific time whenever the user plays the audio, So, I wanted to save the current time of play while the audio is being played.
I have the HTML set up in this way.
<audio id="track" src="/api/streamer/stream"
ontimeupdate="document.getElementById('tracktime').innerHTML = Math.floor(this.currentTime) + ' / ' + Math.floor(this.duration);">
<p>Your browser does not support the audio element</p>
</audio>
<span id="tracktime">0 / 0</span>
I can set the current time of the audio as:
var audioElement = document.getElementById('track');
audioElement.currentTime = 226;
My question is in what event would it be efficient to save the current time of the audio? One possible event would be when the user pauses the audio.
I wanted to save that time and update the database and wanted to start from the same time when users open the audio on multiple devices or browsers.