Baseline Widely available
The HTMLMediaElement
interface's currentTime
property specifies the current playback time in seconds.
Changing the value of currentTime
seeks the media to the new time.
A double-precision floating-point value indicating the current playback time in seconds.
If the media is not yet playing, the value of currentTime
indicates the time position within the media at which playback will begin once the play()
method is called.
Setting currentTime
to a new value seeks the media to the given time, if the media is available.
For media without a known durationâsuch as media being streamed liveâit's possible that the browser may not be able to obtain parts of the media that have expired from the media buffer. Also, media whose timeline doesn't begin at 0 seconds cannot be seeked to a time before its timeline's earliest time.
The length of the media in seconds can be determined using the duration
property.
const video = document.createElement("video");
console.log(video.currentTime);
Usage notes Reduced time precision
To offer protection against timing attacks and fingerprinting, the precision of video.currentTime
might get rounded depending on browser settings. In Firefox, the privacy.reduceTimerPrecision
preference is enabled by default and defaults to 2ms. You can also enable privacy.resistFingerprinting
, in which case the precision will be 100ms or the value of privacy.resistFingerprinting.reduceTimerPrecision.microseconds
, whichever is larger.
For example, with reduced time precision, the result of video.currentTime
will always be a multiple of 0.002, or a multiple of 0.1 (or privacy.resistFingerprinting.reduceTimerPrecision.microseconds
) with privacy.resistFingerprinting
enabled.
// reduced time precision (2ms) in Firefox 60
video.currentTime;
// Might be:
// 23.404
// 24.192
// 25.514
// â¦
// reduced time precision with `privacy.resistFingerprinting` enabled
video.currentTime;
// Might be:
// 49.8
// 50.6
// 51.7
// â¦
Specifications Browser compatibility See also
HTMLMediaElement
: Interface used to define the HTMLMediaElement.currentTime
propertyHTMLMediaElement.fastSeek()
: Another way to set the timeHTMLMediaElement.duration
: The duration of the media in secondsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4