Prevent media from continuing to click on <audio> tag

Asked

Viewed 101 times

0

I have an audio player on the page, and reload the source through javascript. But every time I upload a new audio, the old one keeps loading, although it is no longer playing. And this is disrupting the performance of my application. It’s as if the old audio just went mute.

Look at the image below, my problem. Each "stream.mp3" is a different audio source, which was "switched" to the later after an action. note that the previous ones although not reproducing, continue to load.

My question is there is a way to "destroy" this, reset before loading a new audio source?

inserir a descrição da imagem aqui

  • Where is the javascript code?

  • You have tried removing the DOM element and re-inserting with the new link?

  • Here is the code, summarizing I remove the existing element, create a new one and upload the audio. Every time so, but the previous one persists by pressing background. http://prntscr.com/7gypct

  • Can you create a jsFIddle or some example that we can test? so we can also see devtools and test.

  • I’ll put, I’m simplifying the code for such.

1 answer

0

As this response from Soen would remove the old player and add a new one with the new audio track:

A quick example using jQuery:

var audio = $("#audio-player audio").get(0);
audio.pause(0); //Pausa o player 
audio.src = ""; //Remove a faixa
audio.load();   //Dispara o load 
$("audio").remove();//Remove o audio

$('<audio controls preload="none"></audio>').appendTo("#audio-player");

audio = $("#audio-player audio").get(0);
audio.src = NOVO AUDIO;

To summarize the process is:

  1. Pause the <audio>
  2. Empty setar no src
  3. Run the event audio.load();
  4. Remove the element audio

I didn’t add any details because 7. of the explanation of the posting was confused and the note below explains legal on iOS, but does not make it clear if the thing that it states in meu caso is the Desktop or something else

  • Your code is similar to mine that I currently use, in order of events. I will try anyway. I thank you very much

  • @Fabioweydson if you want to add your code to the question I might add an example to advance your side

Browser other questions tagged

You are not signed in. Login or sign up in order to post.