gpt4 book ai didi

javascript - 如何在 WebAudioApi 中配置 MediaElementAudioSourceNode?

转载 作者:行者123 更新时间:2023-11-30 20:48:14 25 4
gpt4 key购买 nike

我正在使用 MediaElementAudioSourceNode 播放音频文件 ( refer to this question ),它按预期工作,但我对如何在断开连接后处理节点有疑问。

目前我有这段代码:

//Do we have already an MediaElementSourceNode ?
if (this._sourceNode) {
console.warn("THERE IS AUDIO PLAYING!");
//this._audioContainer.addTextTrack
// disconnect and remove all references.
this._audioContainer.pause();
this._audioContainer = undefined;
this._sourceNode.disconnect();
this._sourceNode = undefined;
console.warn("The _audioContainer was paused and the _sourceNode disconnected");
}

this._audioContainer = new Audio(filePath);

this._audioContainer.oncanplaythrough = () => {
clearTimeout(securityTimeout);
console.log(this._audioContainer.readyState);
console.dir(this._audioContainer);
this.audioPlayerActive = true;
// MediaElementSource are ONE TIME ONLY use kind of Node
this._sourceNode = this._AudioContext.createMediaElementSource(this._audioContainer);
this._sourceNode.connect(this._EqNode);
this._audioContainer.play();
console.log("playAudioFile() END");
};

this._audioContainer.onended = () => {
console.log("__audioContainer.onended()");
this._audioContainer = undefined;
this._sourceNode.disconnect();
this._sourceNode = undefined;
};

使用 Web Audio inspector on firefox我可以看到,每次运行此代码(单击按钮)时,它都会创建一个新的 MediaElementAudioSourceNode,如果检测到,则会断开先前创建的代码。此外,当音频结束时,它会断开连接。但是节点甚至在几分钟后仍然存在:

enter image description here

我想防止内存泄漏。我该如何处置它们?编辑:没有可用的功能(我认为)

enter image description here

最佳答案

目前没有办法做到这一点:https://github.com/WebAudio/web-audio-api/issues/1202

关于javascript - 如何在 WebAudioApi 中配置 MediaElementAudioSourceNode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48464797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com