The getOutputTimestamp() property of the AudioContext interface returns a new AudioTimestamp object containing two audio timestamp values relating to the current audio context.
The two values are as follows:
AudioTimestamp.contextTime: The time of the sample frame currently being rendered by the audio output device (i.e., output audio stream position), in the same units and origin as the context'sAudioContext.currentTime. Basically, this is the time after the audio context was first created.AudioTimestamp.performanceTime: An estimation of the moment when the sample frame corresponding to the storedcontextTimevalue was rendered by the audio output device, in the same units and origin asperformance.now(). This is the time after the document containing the audio context was first rendered.
Syntax
var timestamp = AudioContext.getOutputTimestamp()
Parameters
None.
Returns
An AudioTimestamp object, which has the following properties.
contextTime: A point in the time coordinate system of thecurrentTimefor theBaseAudioContext; the time after the audio context was first created.performanceTime: A point in the time coordinate system of aPerformanceinterface; the time after the document containing the audio context was first rendered
Examples
In the following code we start to play an audio file after a play button is clicked, and start off a requestAnimationFrame loop running, which constantly outputs the contextTime and performanceTime.
You can see full code of this example at output-timestamp ([[../../../../../../../mdn.github.io/webaudio-examples/output-timestamp/index|see it live also]]).
play.addEventListener('click', () => {
if(!audioCtx) {
audioCtx = new window.AudioContext();
}
getData();
source.start(0);
play.setAttribute('disabled', 'disabled');
rAF = requestAnimationFrame(outputTimestamps);
});
stop.addEventListener('click', () => {
source.stop(0);
play.removeAttribute('disabled');
cancelAnimationFrame(rAF);
});
// function to output timestamps
function outputTimestamps() {
let ts = audioCtx.getOutputTimestamp()
console.log('Context time: ' + ts.contextTime + ' | Performance time: ' + ts.performanceTime);
rAF = requestAnimationFrame(outputTimestamps);
}
Specifications
| Specification | Status | Comment |
| Web Audio APIThe definition of 'getOutputTimestamp()' in that specification. | Working Draft | Initial definition. |
Browser Compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Chrome
Full support 57 |
Edge
Full support 79 |
Firefox
Full support 70 |
IE
No support No |
Opera
Full support 44 |
Safari
No support No |
WebView Android
Full support 57 |
Chrome Android
Full support 57 |
Firefox Android
No support No |
Opera Android
Full support 43 |
Safari iOS
No support No |
Samsung Internet Android
Full support 7.0 |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.'
- Experimental. Expect behavior to change in the future.
AudioContext.getOutputTimestamp() by Mozilla Contributors is licensed under CC-BY-SA 2.5.