Search code examples
angulartypescriptsettimeoutwavesurfer.js

Replace set timeout in typescript. Wavesurfer.js


I have a function where I change the source for the wavesurfer.js audio file, then want to play the song with the newly loaded audio file. Currently, my code is running how I want it to, but I feel like there has to be a better way of doing this.

Here is my function.

changeAudioFile(i){
   let newSong = 'Link to a different File'
   this.ws.load(newSong);

   setTimeout(() => {
     this.ws.play()
   }, 1000);
}

Solution

  • You can isten for the ready event

    this.ws.on('ready',() => {
        this.ws.play()
    });
    
    

    Documentation