How to stop or clear pervious song in HTML Media Element?

Hi, I am doing streaming music player in ionic 3 by using HTML Media Element. I want to pause or stop or clear the pervious song when i click the next song in my playlist. I attached my code below.

 play(songId,songURL,i,songAlbum,songName,songSingerName){


      this.url = songURL;
      this.stream = new Audio(this.url);
      this.stream.load();
      this.previousId=songId;

      this.showSpinner = true;

      this.stream.play();

      this.stream.addEventListener("playing", (e) => {
        this.showSpinner=false;
        });



  }
  pause(){

    this.stream.pause();

    this.stream.src = '';
    this.stream.load();
    this.stream = null;
    this.stream = new Audio();
    this.stream.src =this.url;
    this.stream.preload = 'none';



  }

That’s easy to configure.
Just add this.stream = null;

to the next button.
This would work better if you have IDs per each track to dynamically unload each track as you load new ones.

@jamesharvey thanks for your information i will try it now

If you don’t have any other idea, try setTimeOut.


loadNextTrack() {
this.stream = null;
setTimeout(() => {
            this.load.Nextsong();
        }, 500);

}

This will initially unload all stream then load the next song.