首页 > 解决方案 > have to remove audioContext or MediaElementAudioSourceNode

问题描述

I am using an audio file received through the input type file, I also create an audio context for this file.

     const audio = this.$refs.testAudio; // <audio ref="testAudio" />
     this.audioContext = new (window.AudioContext || window.webkitAudioContext) ();
     this.srcAudio = this.audioContext.createMediaElementSource (audio);

I need to be able to delete this file and upload a new one. for this i clear the input, stop the context and disconnect the connections

this.srcAudio.context.close (). then (() => {
        this.srcAudio.disconnect ();
        this.analyser = null;
        this.srcAudio = null;
        inputAudio.value = '';
        this. $ refs.testAudio.src = null;
      });

      this.audioContext = null;

But any attempt to use the new file ends with an error:

Blockquote

InvalidStateError: Failed to execute 'createMediaElementSource' on 'AudioContext': HTMLMediaElement already connected previously to a different MediaElementSourceNode. "

Blockquote

help please solve the problem

标签: audiocontext

解决方案


推荐阅读