getOutputTimestamp() 特性为 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's AudioContext.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 stored contextTime value was rendered by the audio output device, in the same units and origin as performance.now() . This is the time after the document containing the audio context was first rendered.

句法

var timestamp = AudioContext.getOutputTimestamp()
					

参数

None.

返回

An AudioTimestamp object, which has the following properties.

  • contextTime : A point in the time coordinate system of the currentTime BaseAudioContext ; the time after the audio context was first created.
  • performanceTime : A point in the time coordinate system of a 性能 interface; the time after the document containing the audio context was first rendered

范例

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 ( 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);
}
					

规范

规范 状态 注释
Web 音频 API
The definition of 'getOutputTimestamp()' in that specification.
工作草案 初始定义。

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getOutputTimestamp Chrome 57 Edge ≤79 Firefox 70 IE 不支持 No Opera 44 Safari 不支持 No WebView Android 57 Chrome Android 57 Firefox Android 不支持 No Opera Android 43 Safari iOS 不支持 No Samsung Internet Android 7.0

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

元数据

  • 最后修改: