我终于找到了一个有用的库来解析来自音频流的元数据,这里是:https://github.com/ghaiklor/icecast-parser。但是,当我像下面的例子一样发送报头时,我仍然无法获得预期的响应。
第一个函数向无线电台/频道发出请求并获取流:
_makeRequest() {
const request = http.request(this.getConfig('url'));
console.log("Making request to: " + this.getConfig('url'));
request.setHeader('Range', 'bytes=0-');
request.setHeader('User-Agent', 'VLC/2.2.4 LibVLC/2.2.4');
request.setHeader('Icy-MetaData', '1');
request.setHeader('Connection', 'close');
request.once('response', this._onRequestResponse.bind(this));
request.once('error', this._onRequestError.bind(this));
request.end();
return this;
}
当成功调用对无线电台的请求时,将调用此函数:
_onRequestResponse(response) {
console.log("Received response!");
console.log("Headers:");
console.log(response.headers['content-type']);
const icyMetaInt = response.headers['icy-metaint'];
console.log("icyMetaInt= " + icyMetaInt);
if (icyMetaInt) {
const reader = new StreamReader(icyMetaInt);
reader.on('metadata', metadata => {
console.log(metadata);
this._destroyResponse(response);
this._queueNextRequest(this.getConfig('metadataInterval'));
this.emit('metadata', metadata);
});
response.pipe(reader);
this.emit('stream', reader);
} else {
this._destroyResponse(response);
this._queueNextRequest(this.getConfig('emptyInterval'));
this.emit('empty');
}
return this;
}
当我在这个URL (url:'http://streaming.radionomy.com/70-s-80-sMetal')上使用这些函数时,控制台中的回复是:
音频/mpeg icyMetaInt=未定义
我知道这里最关键的标题是:
setHeader(‘Icy MetaData’,'1')
不过,我没有收到“icyMetaInt”。使用其他工具检查URL时,它似乎确实包含元数据。
你知道这里出了什么问题吗?谢谢!;
发布于 2018-07-15 04:26:50
请求是Fetch API的一部分,当进行跨域请求时,您只能访问有限范围的headers。
https://stackoverflow.com/questions/51113285
复制相似问题