HTMLMediaElement: currentTime property - Web APIs | MDN (original) (raw)
Value
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 theplay() 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 theduration property.
Examples
js
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.
js
// 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
| Specification |
|---|
| HTML # dom-media-currenttime-dev |
Browser compatibility
See also
- HTMLMediaElement: Interface used to define the
HTMLMediaElement.currentTimeproperty - HTMLMediaElement.fastSeek(): Another way to set the time
- HTMLMediaElement.duration: The duration of the media in seconds