大网数据广告活动
Web 标准与前端开发

AudioProcessingEvent: playbackTime property

· 52CE 我爱测

The **`playbackTime`** read-only property of the AudioProcessingEvent interface represents the time when the audio will be played. It is in the same coordinate system as the time used by the AudioContext.

Web Audio API

The playbackTime read-only property of the AudioProcessingEvent interface represents the time when the audio will be played. It is in the same coordinate system as the time used by the AudioContext.

Value

A number that doesn't need to be an integer.

Examples

const audioContext = new AudioContext();
const processor = audioContext.createScriptProcessor(256, 2, 2);

processor.addEventListener("audioprocess", (event) => {
  const inputBuffer = event.inputBuffer;
  const outputBuffer = event.outputBuffer;

  for (let channel = 0; channel < outputBuffer.numberOfChannels; channel++) {
    const inputData = inputBuffer.getChannelData(channel);
    const outputData = outputBuffer.getChannelData(channel);

    // Log the corresponding time for this audio buffer
    console.log(`Received audio data to be played at ${event.playbackTime}`);

    // Process the audio data here
    for (let i = 0; i < outputBuffer.length; i++) {
      outputData[i] = inputData[i] * 0.5;
    }
  }
});

processor.connect(audioContext.destination);

Specifications

Browser compatibility

See also

  • AudioProcessingEvent
  • ScriptProcessorNode

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。