我一直在Node中try 二进制流.js,让我非常惊讶的是,它确实有一个工作演示,使用 node 无线电流获取Shoutcast流,并使用分块编码将其推送到HTML5元素中.但它只适用于狩猎!
以下是我的服务器代码:
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);
});
// Listen on a web port and respond with a chunked response header.
var server = http.createServer(function(req, res){
res.writeHead(200,{
"Content-Type": "audio/mpeg",
'Transfer-Encoding': 'chunked'
});
// Add the response to the clients array to receive streaming
clients.push(res);
console.log('Client connected; streaming');
});
server.listen("8000", "127.0.0.1");
console.log('Server running at http://127.0.0.1:8000');
我的客户代码很简单:
<audio controls src="http://localhost:8000/"></audio>
这在Mac上的Safari 5中运行良好,但在Chrome或Firefox中似乎没有任何作用.有什么 idea 吗?
可能的候选者包括编码问题,或者只是部分实现了HTML5功能...