我试着在用户提交聊天时发出声音,这也会在另一个人的一端听到。下面是我的代码:
Enter Chat and press enter
<div><input id=input placeholder=you-chat-here /></div>
<code>Chat Output</code>
<div id=box></div>
<div id=pubnub pub-key=demo sub-key=demo></div>
<script src=http://cdn.pubnub.com/pubnub-3.1.min.js></script>
<script>(function(){
var box = PUBNUB.$('box'), input = PUBNUB.$('input'), channel = 'chatlllll';
PUBNUB.subscribe({
channel : channel,
callback : function(text) {
box.innerHTML =
(''+text).replace( /[<>]/g, '' ) + '<br>' + box.innerHTML;
}
});
PUBNUB.bind( 'keyup', input, function(e) {
(e.keyCode || e.charCode) === 13 && PUBNUB.publish({
playsound('http://www.aphpsite.comuv.com/sound/chat.wav')
channel : channel,
message : input.value,
x : (input.value='')
});
});
})();</script>这就是我拥有的。我在添加声音时遇到问题。这个脚本坏了。所以这些都不管用。我希望有人能把它修好。
谢谢。
发布于 2012-07-18 14:11:21
您正在询问有关PubNub和一个示例聊天应用程序,该应用程序具有聊天消息到达/发送的声音效果。我已经更新了示例,并提供了一个额外的sound.js JavaScript HTML5库来帮助播放声音效果。请注意,我将你的声音WAV文件转换为OGG和MP3文件格式,以便提供跨浏览器兼容性。下一步,我将粘贴完整的和工作的源代码聊天与音效收到一条消息。根据源代码,我已经粘贴了您需要的URL资源,如sound.js和音频文件。
试试LIVE! - http://pubnub-demo.s3.amazonaws.com/chat-with-sounds/chat.html
请参阅源代码:
<div><input id=input placeholder=chat-here></div>
<code>Chat Output</code>
<div id=box></div>
<div id=pubnub pub-key=demo sub-key=demo></div>
<script src=http://cdn.pubnub.com/pubnub-3.1.min.js></script>
<script src=sound.js></script>
<script>(function(){
var box = PUBNUB.$('box'), input = PUBNUB.$('input'), channel = 'chatlllll';
PUBNUB.subscribe({
channel : channel,
callback : function(text) {
// PLAY SOUND HERE
sounds.play('chat');
// UPDATE TEXT OUTPUT HERE
box.innerHTML =
(''+text).replace( /[<>]/g, '' ) +
'<br>' +
box.innerHTML;
}
});
PUBNUB.bind( 'keyup', input, function(e) {
(e.keyCode || e.charCode) === 13 && PUBNUB.publish({
channel : channel,
message : input.value,
x : (input.value='')
});
});
})();</script>在GitHub上下载源代码
https://github.com/pubnub/pubnub-api/tree/master/app-showcase/chat-with-sounds -单击链接访问PubNub GitHub存储库,其中包含与声音聊天演示的源代码。
https://stackoverflow.com/questions/11532364
复制相似问题