是否可以将事件侦听器添加到web音频api声音?我一直在寻找当声音结束时的事件或触发器,但找不到任何东西。下面是我设想的工作原理:
soundSource = context.createBufferSource();
soundBuffer = context.createBuffer(audioData, true);
soundSource.buffer = soundBuffer;
soundSource.connect(volumeNode);
soundSource.addEventListener('ended', function(e){
console.log("ended", "", e);
}, false);
soundSource.noteOn(context.currentTime);
发布于 2014-01-17 07:48:51
var isFinished = false;
var source = context.createBufferSource();
source.onended = onEnded;
function onEnded() {
isFinished = true;
console.log('playback finished');
}
发布于 2012-11-29 19:30:59
不是今天不是。我知道有关于添加某种事件系统的讨论,但它还没有在规范中(如果它会出现的话)。但是,您可以签出缓冲源的playbackState属性:https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#AudioBufferSourceNode
除此之外,最好的办法是根据缓冲区长度使用超时,并在触发时运行回调。
发布于 2016-07-15 23:20:29
是的,看起来像是添加了: AudioBufferSourceNode.onended https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/onended
https://stackoverflow.com/questions/13617047
复制相似问题