The best way to stop Audio?


#1

I try to make a sonor reminder in my app, and this is my code;

    let x;
   if (!!this.Reminder()) {
      x = new Audio('../bells.mp3');
        if (typeof x.loop == 'boolean')
            {
                x.loop = true;
            }
            else
            {
                x.addEventListener('ended', function() {
                    this.currentTime = 0;
                    this.play();
                }, false);
            };
                  x.play();

   } else{
                   if (!x.paused) {
                            
                            x.pause();
                            }else{
                            x.pause();
                          };

   };

but even if !!this.Reminder() is false but the audio keep playing.

Ve you an idea on how to stop it ??

Thank’s


#2

x.load() should stop it


#3

@juliancwirko thank’s