forked from drewbharris/node-multi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slave_mobile.html
88 lines (77 loc) · 2.18 KB
/
slave_mobile.html
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<html>
<head>
<meta name="viewport" content="user-scalable=no, width=device-width" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script>
var audioBuffer = null,
context = new webkitAudioContext(),
socket = io.connect('http://192.168.1.167'),
globalSource = context.createBufferSource(),
currentFile;
function loadAudio(url) {
var request = new XMLHttpRequest();
request.open('GET', '/static/audio/' + url, true);
request.responseType = 'arraybuffer';
request.onload = function() {
context.decodeAudioData(request.response, function(buffer) {
console.log('decode recieved');
globalSource.buffer = buffer;
globalSource.connect(context.destination);
socket.emit('slaveEvent', {
'audioEvent': 'loaded',
'source': currentFile
});
$("#info").text('loaded');
}, function(err){
console.log(err);
});
}
request.send();
}
socket.on('slaveEvent', function (data) {
if (data.audioEvent == 'play') {
$("#info")
.text("playing")
.css("color", "green");
globalSource.noteOn(0);
}
else if (data.audioEvent == 'stop') {
$("#info")
.text("stopped")
.css("color", "red");
globalSource.noteOff(0);
}
else if (data.audioEvent == 'load') {
$("#info")
.text("loading...");
$("#source")
.text(data.source);
currentFile = data.source;
loadAudio(currentFile);
}
else if (data.audioEvent == 'error') {
$("#info")
.text("error: " + data.message);
}
});
$(document).ready(function(){
socket.emit('slaveEvent', {
'audioEvent': 'requestSource'
});
})
$(window).bind('beforeunload',function(){
socket.emit('slaveEvent', {
'audioEvent': 'removeSource',
'source': currentFile
});
});
</script>
</head>
<body>
<div id="info">
</div>
<div id="source">
</div>
</body>
</html>