简体   繁体   English

聊天系统中的ping声音

[英]ping sound in chat system

i have made a simple chat system here http://theawesomecoder.com/c i am trying to generate a ping sound whenever user enters any message which should be heard by every one online. 我在这里http://theawesomecoder.com/c制作了一个简单的聊天系统,我试图在用户输入任何在线上应该听到的消息时发出ping声音。 for this i have written a play sound code in which the message is being written to the file but when the message is being written to the file using ajax no sound is being generated 为此,我编写了一个播放声音代码,其中将消息写入文件,但是使用ajax将消息写入文件时,则不会生成声音

<?php

session_start();
if (isset($_SESSION['user'])) {
    $text = $_POST['text'];

    echo "<script>playSound('button-1.wav')</script>";

    $date = date('H:i:s');
    $handle = fopen("messages.html", 'a+');
    fwrite($handle, '<div class="message"><span class="name">' . $_SESSION['user'] . ':</span> ' . stripslashes(htmlspecialchars($text)) . '<span class="right">'.$date .'</span></div>');
    fclose($handle);
}
?>
<!doctype html>
<html>
<head>
<meta charset="ISO-8859-1" />
<title></title>
<script language="javascript" type="text/javascript">
function playSound(soundfile) {
  document.getElementById("dummy").innerHTML=
    "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
</script>
</head>

<body>
<span id="dummy"></span>


</body>
</html>

<?php

echo "<script>playSound('button-1.wav')</script>";

?>

is your sound file correct? 您的声音文件正确吗? you can just play the sound when you load the content. 您可以在加载内容时播放声音。 Try not loading the sound files with javascript. 尝试不使用javascript加载声音文件。 add it to your html. 将其添加到您的html中。 Just try and play the file using javascript rather imbeding it everytime. 只需尝试使用javascript播放文件,而不是每次都将其嵌入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM