我一直在尝试使用Node.js中的二进制流,令我惊讶的是,实际上有一个工作演示,即使用节点无线电流获取Shoutcast流并使用分块编码将其推送到HTML5元素.但它只适用于Safari!
这是我的服务器代码:
var radio = require("radio-stream");
var http = require('http');
var url = "http://67.205.85.183:7714";
var stream = radio.createReadStream(url);
var clients = [];
stream.on("connect", function() {
console.error("Radio Stream connected!");
console.error(stream.headers);
});
// When a chunk of data is received on the stream, push it to all connected clients
stream.on("data", function (chunk) {
if (clients.length > 0){
for (client in clients){
clients[client].write(chunk);
};
}
});
// When a 'metadata' event happens, usually a new song is starting.
stream.on("metadata", function(title) {
console.error(title);
}); …
Run Code Online (Sandbox Code Playgroud)