Why is the HTML5 reset currentTime setting set in Chrome?

I want to set the time position of a video in HTML5. The time should be set as follows:

function settime(){ var video = document.getElementById("video1"); console.log(video.currentTime); //----->output for example 15.3 video.currentTime = 10.0; console.log(video.currentTime);//----->>output always 0 } 

And the video is embedded like this:

 <button onclick="settime();">Set Time</button> <div class="container"> <video id="video1" class="video-js vjs-default-skin" muted> <source src="video.m4v" type="video/mp4" /> HTML5 Video is required for this example. </video> 

But for some reason this always just resets currentTime to 0 in Chrome.

Why is time reset when setting currentTime? And how to set currentTime correctly?

+12
javascript html html5 google-chrome html5-video
source share
2 answers

I finally understood the answer! Chrome requires you to specify currentTime as a string, not 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> 
-one
source share

It should be

 var video = document.getElementById("video1"); 

since you have

 <video id="video1" class="video-js vjs-default-skin" muted> 
-3
source share

All Articles