AudioContext .ended 未正确触发
AudioContext .ended not firing properly
我有一个创建 audiocontext 节点并用缓冲区加载它的简单例程。 onended 事件似乎在一开始就触发了。我为持续时间设置了一个计时器,onended 事件在音频停止播放之前触发大约该时间量。任何人都知道如何获得真正的 onended 事件。我尝试使用目标和源,结果相同
function playSoundFile(buffer) {
'use strict';
audioCtx.close();
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
audioSource = audioCtx.createBufferSource();
audioSource.connect(audioCtx.destination);
audioSource.buffer = buffer;
audioSource.playbackRate.value = 1;
stillPlaying(true);
audio_player = audioCtx.destination;
audioSource.addEventListener('onended', whatsUp());
console.log('start ' + showTime());
filePlayed(buffer.duration);
audioSource.start();
}
play 和 onended 事件的时间戳仅相差 1 毫秒。
filePlayed 启动超时事件以显示开始和结束时间。
好的,guest271314 基本答对了。
文档令人困惑。 eventListener 是 "ended" 而不是 "onended" 并且您必须将函数名称与 parans
一起使用
所以
audioSource.addEventListener('ended', whatsup);
解决了这个问题。谢谢
我有一个创建 audiocontext 节点并用缓冲区加载它的简单例程。 onended 事件似乎在一开始就触发了。我为持续时间设置了一个计时器,onended 事件在音频停止播放之前触发大约该时间量。任何人都知道如何获得真正的 onended 事件。我尝试使用目标和源,结果相同
function playSoundFile(buffer) {
'use strict';
audioCtx.close();
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
audioSource = audioCtx.createBufferSource();
audioSource.connect(audioCtx.destination);
audioSource.buffer = buffer;
audioSource.playbackRate.value = 1;
stillPlaying(true);
audio_player = audioCtx.destination;
audioSource.addEventListener('onended', whatsUp());
console.log('start ' + showTime());
filePlayed(buffer.duration);
audioSource.start();
}
play 和 onended 事件的时间戳仅相差 1 毫秒。 filePlayed 启动超时事件以显示开始和结束时间。
好的,guest271314 基本答对了。
文档令人困惑。 eventListener 是 "ended" 而不是 "onended" 并且您必须将函数名称与 parans
一起使用所以
audioSource.addEventListener('ended', whatsup);
解决了这个问题。谢谢