简体   繁体   English

如何读取节点js中的音频流?

[英]How to read audio stream in node js?

I just want to read some audio stream for example from http://livestream.rfn.ru:8080/kulturafm/mp3_192kbps . 我只想阅读一些音频流,例如http://livestream.rfn.ru:8080/kulturafm/mp3_192kbps My code is like this 我的代码是这样的

http = require('http')

options = 
  host: 'livestream.rfn.ru'
  path: ':8080/kulturafm/mp3_192kbps'

callback = (res) ->
  res.on 'data', (chunk) -> console.log String(chunk)
  res.on 'end', -> console.log('No more data in response.')

http.request(options, callback).end()

Output is: 输出是:

<html><head><title>Wowza Streaming Engine 4 Monthly Edition 4.4.0 build17748</title></head><body>Wowza Streaming Engine 4 Monthly Edition 4.4.0 build17748</body></html> <html> <head> <title> Wowza Streaming Engine 4每月版4.4.0 build17748 </ title> </ head> <body> Wowza Streaming Engine 4每月版4.4.0 build17748 </ body> </ html>

No more data in response. 没有更多数据作为回应。 I can't understand how to get data from the MP3 stream. 我无法理解如何从MP3流中获取数据。

The problem here is that you're putting the port ( 8080 ) in the path. 这里的问题是您要将端口( 8080 )放在路径中。 This is incorrect. 这是不正确的。 Your HTTP client is connecting to port 80 instead, as a default. 默认情况下,HTTP客户端将连接到端口80

You don't need to specify the options object in this way. 您不需要以这种方式指定选项对象。 Just pass the URL and it will parse for you. 只需传递URL,它就会为您解析。 Use http.get() and it will set the appropriate verb and .end() for you. 使用http.get() ,它将为您设置适当的动词和.end()

var streamUrl = 'http://livestream.rfn.ru:8080/kulturafm/mp3_192kbps';
http.get(streamUrl, callback);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM