Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
88 lines (77 sloc) 2.18 KB
<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>