我正在使用 chrome,并且我有一个 HTML 音频元素连接到这样的分析器:
var audio = document.getElementById('audio');
audio.src = "http://127.0.0.1:5000/api/getfile/new.wav";
var ctx = new AudioContext();
var analyser = ctx.createAnalyser();
var audioSrc = ctx.createMediaElementSource(audio);
audioSrc.connect(analyser); //breaks here on 2nd run
analyser.connect(ctx.destination);
完成后,我调用一个重置方法,该方法传入此处声明的四个变量,然后尝试休息/重新初始化,以便可以将它们用于从同一 api/source 传入的下一个文件:
audioSrc.disconnect();//analyser);
analyser.disconnect();//ctx.destination);
audio.src = "";
ctx.close();
但它似乎没有正确断开连接,因为我收到了这个错误:
SimpleUpload.vue?3533:299 Uncaught (in promise) DOMException: Failed to execute 'createMediaElementSource' on 'AudioContext': HTMLMediaElement already connected previously to a different MediaElementSourceNode.
这是HTML:
<div id="audiovis">
<div v-if="loading"
class="loadspin">
<img class="spinner" src="./Wedges-3s-207px-trans.gif" width="80" height="80">
</div>
<canvas id='canvas' width="800" height="150"></canvas>
<br>
<br>
<audio crossOrigin="anonymous"
:src = "showVisualizer"
id = "audio" controls>
audio element not supported
<!-- "http://127.0.0.1:5000/api/getfile/new.wav" -->
</audio>
</div>
和 python Flask API:
@app.route('/api/getfile/<audiofile>')
def send_file(audiofile):
try:
return send_from_directory(os.getcwd(),filename=audiofile, as_attachment=True)
except FileNotFoundError:
abort(404)