How to play a notification sound on websites?

前端 未结 11 1513
生来不讨喜
生来不讨喜 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:11

    One more plugin, to play notification sounds on websites: Ion.Sound

    • Basic Demo
    • Advanced Demo
    • Ion.Sound GitHub Page

    Advantages:

    • JavaScript-plugin for playing sounds based on Web Audio API with fallback to HTML5 Audio.
    • Plugin is working on most popular desktop and mobile browsers and can be used everywhere, from common web sites to browser games.
    • Audio-sprites support included.
    • No dependecies (jQuery not required).
    • 25 free sounds included.

    Set up plugin:

    // set up config
    ion.sound({
        sounds: [
            {
                name: "my_cool_sound"
            },
            {
                name: "notify_sound",
                volume: 0.2
            },
            {
                name: "alert_sound",
                volume: 0.3,
                preload: false
            }
        ],
        volume: 0.5,
        path: "sounds/",
        preload: true
    });
    
    // And play sound!
    ion.sound.play("my_cool_sound");
    

提交回复
热议问题