When working with audio elements ( <audio>
) or contexts( AudioContext
), you can check their currentTime
property to know exactly the play time of your buffer.(当使用音频元素( <audio>
)或上下文( AudioContext
)时,可以检查它们的currentTime
属性以确切了解缓冲区的播放时间。)
All of this is fine an dandy until I created multiple sources (or AudioBufferSourceNode
) in a single AudioContext
.(在我在一个AudioContext
创建多个源(或AudioBufferSourceNode
)之前,所有这些都是不错的选择。)
The sources could be played at different times, therefore I would need to know their corresponding currentTime
's, to illustrate:(源可以在不同的时间播放,因此我需要知道它们对应的currentTime
,以说明:)
Some base code for you to work off:(一些基础代码供您解决:)
buffer1 = [0,1,0]; //not real buffers
buffer2 = [1,0,1];
ctx = new AudioContext();
source1 = ctx.createBufferSourceNode();
source1.buffer = buffer1;
source1.connect(ctx.destination);
source1.start(0);
source2 = ctx.createBufferSourceNode();
source2.buffer = buffer2;
source2.connect(ctx.destination);
setTimeout(1000/*some time later*/){
source2.start(0);
}
setTimeout(1500/*some more time later*/){
getCurrentTime();
}
function getCurrentTime(){
/* magic */
/* more magic */
console.log("the sources currentTime values are obviously 1500 (source1) and 500 (source2).");
}
ask by undefined translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…