HTML 5 – Play file at certain time point

The best way to do this is to use the Media Fragment URI specification. Using your example, suppose you want to load the audio starting at 3:26 in.

<audio id="audio2" 
       preload="auto" 
       src="file.mp3#t=00:03:26" 
       oncanplaythrough="this.play();">
</audio>

Alternatively, we could just use the number of seconds, like file.mp3#t=206.

You can also set an end time by separating the start from the end times with a comma. file.mp3#t=206,300.5

This method is better than the JavaScript method, as you’re hinting to the browser that you only want to load from a certain timestamp. Depending on the file format and server support for ranged requests, it’s possible for the browser to download only the data required for playback.

See also:

Leave a Comment