-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathslave_mobile.html
More file actions
136 lines (124 loc) · 3.47 KB
/
slave_mobile.html
File metadata and controls
136 lines (124 loc) · 3.47 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<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) {
// function testTrigger(){
// var data = {};
// var events = ['play', 'stop', 'load', 'error'];
// var ran = Math.random()*events.length >> 0;
// data.audioEvent = events[ran];
console.log(data, events, ran, data.audioEvent);
if (data.audioEvent == 'play') {
$("#status")
.text("playing")
.attr("class", "playing");
globalSource.noteOn(0);
}
else if (data.audioEvent == 'stop') {
$("#status")
.text("stopped")
.attr("class", "stopped");
globalSource.noteOff(0);
}
else if (data.audioEvent == 'load') {
$("#status")
.text("loading")
.attr("class", "loading");
$("#source")
.text(data.source);
currentFile = data.source;
loadAudio(currentFile);
}
else if (data.audioEvent == 'error') {
$("#status")
.text("error: " + data.message)
.attr("class", "error");
}
// }
});
$(document).ready(function(){
socket.emit('slaveEvent', {
'audioEvent': 'requestSource'
});
})
$(window).bind('beforeunload',function(){
socket.emit('slaveEvent', {
'audioEvent': 'removeSource',
'source': currentFile
});
});
</script>
<style>
body{
margin: 0;
padding: 20px;
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#D2D4C6), to(#BEBFAD));
font-family: "Helvetica Neue", helvetica, sans-serif;
}
#container {
max-width: 280px;
margin: 0 auto;
}
#info > div {
margin: 20px 0;
text-align: center;
padding: 12px;
text-transform: uppercase;
font-size: 12px;
letter-spacing: 2px;
background: -webkit-gradient(linear, 0 0, 100% 100%, from(#0B0301), color-stop(.2, #2D2220), color-stop(.7, #0B0301), to(#2D2220));
color: #FFA304;
text-shadow: 0 1px 6px #FFA304;
border-radius: 3px;
box-shadow: 0 3px 4px black inset, 0 1px 1px rgba(255, 255, 255, .5);
}
#source {
font-size: 14px;
color: rgba(0, 0, 0, .5);
text-shadow: 0 1px rgba(255, 255, 255, .4);
text-align: center;
}
</style>
</head>
<body>
<div id="container">
<div id="info">
<div id="status" class="">...</div>
<!-- <div class="loading">loading</div>
<div class="playing">playing</div>
<div class="stopped">stopped</div>
<div class="error">error</div> -->
</div>
<div id="source">
</div>
</div>
</body>
</html>