Why does setting currentTime of HTML5 video element reset time in Chrome?
I finally figured out an answer! Chrome requires you to set the currentTime as a String, and not as a number.
function settime() { var video = document.getElementById("video1"); console.log(video.currentTime); // output 0 video.currentTime = 10.0; console.log(video.currentTime); // output 0 for some chrome users or 10 for firefox and others video.currentTime = "10.0"; console.log(video.currentTime); // output 10}settime();
<audio id="video1" src="https://sample-videos.com/audio/mp3/crowd-cheering.mp3" controls></audio><div>Click play to start the audio at 10 s.</div>
This is caused in many cases by the server not replying with an Accept-Ranges
header. For an obscure, only-Google-developer-relevant reason (the FF folks don't seem to be so offended by a server replying without an Accept-Ranges
header), they refuse to implement seeking when such a header is not provided. You can add one very easily (at least for testing) by using an nginx proxy and adding proxy_force_ranges on;
(server or location both work).
This is a bug in Chrome, which apparently only happens with 'some' videos. Similar bug reports have been filed and closed numerous times in the past, so I suggest we keep a watch on it, so it doesn't get closed again until the issue is actually fixed.