BaseAudioContext: currentTime property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
ThecurrentTime read-only property of theBaseAudioContextinterface returns a double representing an ever-increasing hardware timestamp in seconds thatcan be used for scheduling audio playback, visualizing timelines, etc. It starts at 0.
In this article
Value
A floating point number.
Examples
const audioCtx = new AudioContext();// Older webkit/blink browsers require a prefix// …console.log(audioCtx.currentTime);Reduced time precision
To offer protection against timing attacks andfingerprinting, the precision ofaudioCtx.currentTime might get rounded depending on browser settings. In Firefox, theprivacy.reduceTimerPrecision preference is enabled by default and defaults to 2ms. You can also enableprivacy.resistFingerprinting, in which case the precision will be 100ms or the value ofprivacy.resistFingerprinting.reduceTimerPrecision.microseconds, whichever is larger.
For example, with reduced time precision, the result ofaudioCtx.currentTime will always be a multiple of 0.002, or a multiple of 0.1 (orprivacy.resistFingerprinting.reduceTimerPrecision.microseconds) withprivacy.resistFingerprinting enabled.
// reduced time precision (2ms) in Firefox 60audioCtx.currentTime;// Might be:// 23.404// 24.192// 25.514// …// reduced time precision with `privacy.resistFingerprinting` enabledaudioCtx.currentTime;// Might be:// 49.8// 50.6// 51.7// …Specifications
| Specification |
|---|
| Web Audio API> # dom-baseaudiocontext-currenttime> |