wavesurfer.js
wavesurfer.js copied to clipboard
Fix Failed to execute 'createMediaElementSource' on 'AudioContext'
Short description of changes:
It works fine the first time I create the wavesurfer with MediaElementWebAudio backend, but when the component is unmounted and then recreated at a later point, I get the following error message:
Uncaught InvalidStateError: Failed to execute 'createMediaElementSource' on 'AudioContext': HTMLMediaElement already connected previously to a different MediaElementSourceNode.
It's possible to workaround this issue using WeakMap to remember MediaElementSourceNode:
createMediaElementSource(mediaElement) {
if (MediaElementMap.has(mediaElement)) {
this.sourceMediaElement = MediaElementMap.get(mediaElement);
} else {
this.sourceMediaElement = this.ac.createMediaElementSource(
mediaElement
);
MediaElementMap.set(mediaElement, this.sourceMediaElement);
}
this.sourceMediaElement.connect(this.analyser);
}
Breaking in the external API:
none
Breaking changes in the internal API:
none
ping @SchmidtWongxn
no feedback, closing.