4

我使用 Websocket 编写了一个网络聊天。问题是用户切换浏览器的标签,我想播放声音让他们知道有人想在聊天标签中与他交谈。

我看到 FaceBook 和 GMail 可以在他们的聊天在非活动选项卡中有新消息时播放“ping”

他们如何使用 javascript 或有任何解决方案

此致

4

1 回答 1

4

这个怎么样?

function beep(file,volume){
    var snd = new Audio(file);
    volume = volume ? volume : 0.5; // defaults to 50% volume level
    snd.volume = volume;

    // LISTENER: Rewind the playhead when play has ended
    snd.addEventListener('ended',function(){
        this.pause();
        this.currentTime=0;
    });

    // Play the sound
    snd.play();
}

beep("audioFiles/beep.mp3", 1.0);
于 2013-03-09T16:56:57.267 回答