您好,我在Google周围搜索了一个发现,发现我似乎找不到有关如何从Icecast流中读取实时元数据的数据。
我想做的是
执行类似的操作(请注意,此脚本可能不起作用-只是一个概念)
var http = require('http');
var fs = require('fs');
http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type': 'audio/mp3'
});
var rs = fs.createReadStream('ICECAST STREAM');
rs.pipe(res);
})
但是,当您尝试使用此脚本时,由于无法读取远程流,因此它将无法正常工作。
问题2)如何获取它以读取流中的元数据? 我想在元数据等于某个标签时进行一些触发
更新脚本</ p>
var http = require('http'),fs = require('fs'),request = require('request');
var icecast = require('icecast-stack');
var url = 'http://stream.radiomedia.com.au:8003/stream'; // URL to a known Icecast stream
var stream = icecast.createReadStream(url);
http.createServer(function(request, response) {
response.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': 15000
});
// Fired when the `net.Stream` has it's 'connect' event.
stream.on('connect', function() {
console.error("Radio Stream connected!");
});
// Fired after the HTTP response headers have been received.
stream.on('response', function(res) {
console.error("Radio Stream response!");
console.error(res.headers);
});
// When a 'metadata' event happens, usually a new song is starting.
stream.on('metadata', function(metadata) {
var title = icecast.parseMetadata(metadata).StreamTitle;
if(title === "SkypeTherapy.pro - Ad 1 [2b]"){
console.error("advert");
}
else{
console.error(title);
}
});
// Proxy the raw audio stream to 'stdout', redirect to a file!
//stream.pipe(process.stdout);
http.get(url, res => res.pipe(fs.createReadStream('some.mp3')));
})
.listen(2000);
但是脚本不会播放,而只是在控制台中打印数据。