How to jump to certain time offsets in HTML5 Audio elements?
They say you can simply set their currentTime
property (emphasis mine):
The
currentTime
attribute must, on getting, return the current playback position, expressed in seconds. On setting, if the media element has a current media controller, then it must throw an INVALID_STATE_ERR exception; otherwise, the user agent must seek to the new value (which might raise an exception).
Alas, it doesn't seem to work (I need it in Chrome).
There are similar questions, although, no answers.
Firefox also makes byte range requests when seeking content that it has not yet loaded- it is not just a chrome issue. Set the response header "Accept-Ranges: bytes" and return a 206 Partial Content status code to allow any client to make byte range requests.
See https://developer.mozilla.org/en-US/docs/Web/HTTP/Configuring_servers_for_Ogg_media#Handle_HTTP_1.1_byte_range_requests_correctly
Set time position to 5 seconds:
To jump around an audio file, your server must be configured properly.
The client sends byte range requests to seek and play certain regions of a file, so the server must response adequately:
Then, if the server responses to byte range requests correctly, you can set the position of audio via
currentTime
:See MDN's Configuring servers for Ogg media (the same applies for other formats, actually).
Also, see Configuring web servers for HTML5 Ogg video and audio.
I was facing problem that progress bar of audio was not working but audio was working properly. This code works for me. Hope it will help you too. Here song is the object of audio component.
HTML Part
JQuery Part
The @katspaugh's answer is correct, but there is a workaround that does not require any additional server configuration. The idea is to get the audio file as a blob, transform it to
dataURL
and use it as thesrc
for theaudio
element.Here is solution for angular
$http
, but if needed I can add vanilla JS version as well:cautions
A much easier solution is