index.html~
860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<audio controls="controls" id="mySound">
<source src ="sound.wav" type="audio/wav">
</audio>
<script
src="jquery.js"></script>
<script type="text/javascript">
window.WebSocket=(window.WebSocket||window.MozWebSocket);
var websocket=new WebSocket('ws://10.42.93:9000','myprotocol');
var test1 = document.getElementById("mySound");
test1.src="sound.wav";
test1.autoplay = true;
websocket.onopen=function(){ $('h1').css('color','green'); };
websocket.onerror=function(){ $('h1').css('color','red'); };
websocket.onmessage=function(message){
test1.pause();
test1.src="sound.wav?"+ new Date().getTime();
test1.load();
test1.play();
};
var son = document.getELementById("sound");
son.loop = true;
</script>
</head>
<body>
<h1>WebSockets test</h1>
</body>
</html>