Created
September 18, 2013 23:20
-
-
Save TooTallNate/6617144 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Module dependencies. | |
*/ | |
var lame = require('lame'); | |
var icecast = require('icecast'); | |
var Speaker = require('speaker'); | |
/** | |
* The Icecast stream URL to connect to. | |
*/ | |
var url = process.argv[2] || 'http://firewall.pulsradio.com'; | |
/** | |
* Send a GET http request to the specified Icecast URL. | |
*/ | |
icecast.get(url, function (res) { | |
console.error('HTTP HEADERS:'); | |
console.error(res.headers); | |
// call `onMetadata` when a "metadata" event happens | |
res.on('metadata', onMetadata); | |
// decode the MP3 audio data and play through speakers | |
res.pipe(new lame.Decoder()).pipe(new Speaker()); | |
}); | |
/** | |
* Invoked for every "metadata" event from the `res` stream. | |
*/ | |
function onMetadata (metadata) { | |
metadata = icecast.parse(metadata); | |
console.error('METADATA EVENT:'); | |
console.error(metadata); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment