简体   繁体   中英

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. 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

<?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. add it to your html. Just try and play the file using javascript rather imbeding it everytime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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