AudioProcessingEvent: playbackTime property
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Thuộc tính chỉ đọc playbackTime của giao diện AudioProcessingEvent biểu diễn thời điểm âm thanh sẽ được phát. Thuộc tính này dùng cùng hệ tọa độ thời gian với thời gian được AudioContext sử dụng.
Giá trị
Một số không nhất thiết phải là số nguyên.
Ví dụ
js
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);
// Ghi lại thời điểm tương ứng của bộ đệm âm thanh này
console.log(`Received audio data to be played at ${event.playbackTime}`);
// Xử lý dữ liệu âm thanh tại đây
for (let i = 0; i < outputBuffer.length; i++) {
outputData[i] = inputData[i] * 0.5;
}
}
});
processor.connect(audioContext.destination);
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Web Audio API> # dom-audioprocessingevent-playbacktime> |