简体   繁体   中英

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 . 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>

No more data in response. I can't understand how to get data from the MP3 stream.

The problem here is that you're putting the port ( 8080 ) in the path. This is incorrect. Your HTTP client is connecting to port 80 instead, as a default.

You don't need to specify the options object in this way. Just pass the URL and it will parse for you. Use http.get() and it will set the appropriate verb and .end() for you.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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