Created
January 9, 2012 12:42
-
-
Save polaris/1582778 to your computer and use it in GitHub Desktop.
Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ctx = new webkitAudioContext(); | |
var startTime = 0; | |
function playSound(buffer) { | |
var src = ctx.createBufferSource(); | |
src.buffer = buffer; | |
src.looping = false; | |
src.connect(ctx.destination); | |
src.noteOn(startTime); | |
startTime += src.buffer.duration; | |
} | |
var ws = new WebSocket('ws://localhost:8080/data'); | |
ws.binaryType = 'arraybuffer'; | |
ws.onmessage = function(e) { | |
console.log('About to decode ' + e.data.byteLength + ' bytes MP3 data'); | |
ctx.decodeAudioData(e.data, function (buffer) { | |
console.log('Finished decoding'); | |
playSound(buffer); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment