首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >JavaScript从音频解析元数据(ICY)

JavaScript从音频解析元数据(ICY)
EN

Stack Overflow用户
提问于 2018-06-30 16:43:18
回答 1查看 1K关注 0票数 0

我终于找到了一个有用的库来解析来自音频流的元数据,这里是:https://github.com/ghaiklor/icecast-parser。但是,当我像下面的例子一样发送报头时,我仍然无法获得预期的响应。

第一个函数向无线电台/频道发出请求并获取流:

代码语言:javascript
复制
_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;
}

当成功调用对无线电台的请求时,将调用此函数:

代码语言:javascript
复制
_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时,它似乎确实包含元数据。

你知道这里出了什么问题吗?谢谢!;

EN

回答 1

Stack Overflow用户

发布于 2018-07-15 04:26:50

请求是Fetch API的一部分,当进行跨域请求时,您只能访问有限范围的headers。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51113285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档