【发布时间】:2016-08-02 08:49:45
【问题描述】:
我正在制作一个网络聊天应用程序,现在我需要在新消息到达时播放通知声音。
首先我使用howler.js 来播放声音。在 howler 中,我们可以开始播放声音,然后如果我们锁定屏幕或更改浏览器选项卡焦点,它会继续播放。 但是如果标签页打开并且手机屏幕被锁定,它不会开始播放声音,如果用户在另一个标签页上打开另一个标签页上的应用程序,它也不会播放。
所以基本上我的问题是,是否可以在屏幕锁定时开始播放声音,或者当用户在另一个选项卡上时开始播放声音?
app.js
var notify_sound = new Howl({
src: ['./assets/sounds/notify2.mp3'],
volume: 1.0
});
.
.
.
.
.
.
.
.
if(type == "user"){
if(userAddress == remoteAddress) {
typing.html('').fadeOut('fast');
messages.append('<li class="self"><p class="message">'+ obj.message + '</p><p class="time">' + time +'</p></li><p class="username_self">' + userAddress + '</p>');
}
else {
typing.html('').fadeOut('fast');
messages.append('<li class="other"><p class="message">'+ obj.message + '</p><p class="time">' + time +'</p></li><p class="username_other">' + userAddress + '</p>');
notify_sound.play();
}
}
【问题讨论】:
标签: javascript html notifications howler.js