2012-11-29 186 views
10

是否有可能將事件監聽器添加到Web音頻API聲音?我一直在尋找一個事件或觸發器,當一個聲音完成但找不到任何東西。這裏是我的想法如何工作:網絡音頻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); 

回答

9
var isFinished = false; 
var source = context.createBufferSource(); 
source.onended = onEnded; 
function onEnded() { 
    isFinished = true; 
    console.log('playback finished'); 
} 

Check this out