How to play a notification sound on websites?

前端 未结 11 1541
生来不讨喜
生来不讨喜 2020-11-28 01:32

When a certain event occurs, I want my website to play a short notification sound to the user.

The sound should not auto-start (instantly) when the

11条回答
  •  天命终不由人
    2020-11-28 02:13

    Play cross browser compatible notifications

    As adviced by @Tim Tisdall from this post , Check Howler.js Plugin.

    Browsers like chrome disables javascript execution when minimized or inactive for performance improvements. But This plays notification sounds even if browser is inactive or minimized by the user.

      var sound =new Howl({
                         src: ['../sounds/rings.mp3','../sounds/rings.wav','../sounds/rings.ogg',
                               '../sounds/rings.aiff'],
                         autoplay: true,
                         loop: true
                        });
    
                   sound.play();
    

    Hope helps someone.

提交回复
热议问题