Prevent media from continuing to load in audio tag

0

I have an audio player on the page, and I reload the source through javascript. But every time I load a new audio, the old one continues to load, even though it is no longer playing. And this is hindering the performance of my application. It's as if the old audio just became mute.

Look at the image below, my problem. Each "stream.mp3" is a different audio source, which has been "swapped" by the latter after an action. see that the previous ones although they are not reproducing, continue to load.

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

    
asked by anonymous 14.06.2015 / 21:49

1 answer

0

As this SOen response 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:

  • Pause% with%
  • Set empty at <audio>
  • Run the event src
  • Remove element audio.load();
  •   

    I did not add details because audio of the explanation of the post was confused and the note that explains below explains legal about iOS, but it does not make it clear if the issue that he says in 7. is Desktop or something else

        
    15.06.2015 / 06:07