NodeJS basedRadio (without ShoutCast)
Asked Answered
S

0

2

I like to create a radio Station which is based on NodeJS while not using ShoutCast.

NodeJS based Playlist

Currently I have managed to steam an audio file to the browser, but I don't know how to create a server side Playlist which continuously keeps "playing" the current song and restart it once the end has been reached.

thats my current approach:

'use strict';
var http = require('http');
var fs = require('fs');
var mm = require('musicmetadata');
var ID3 = require('id3');
var express = require('express');
var app = express();

var stream;

function startPlaylist() {
    stream = fs.createReadStream(__dirname + '/AnsolasChill_loop.mp3', {
        start: 0
    }); //10130000
   /*
      * Start serverside "Playback" here.
      * Restart Playlist once the end of the song has been reached
    */

}
startPlaylist(); // Start Server Side Playlist once the Server starts.


app.get('/', function(req, res) {


    /*
       * get current playback postion of playlist 
       * start stream from current playback position  
    */
    
    res.setHeader('Content-Type', 'audio/mpeg');
    stream.pipe(res);

    // Events
    stream.on('data', function(chunk) {
      console.log('data: got %d bytes of data', chunk.length);
    })

    stream.on('end', function() {
        console.log('there will be no more data.');
        stream = null;
        stream = fs.createReadStream(__dirname + '/AnsolasChill_loop.mp3', {
            start: 0
        });
    
    });

    stream.on('readable', function() {
        var chunk;
        while (null !== (chunk = stream.read())) {
          //console.log(i,' readable:', chunk.length);
        }
    });

});

app.listen(3000);

[edit]

VLC as Playlist ?

Just found this thread: Related: Is there a good radio-like audio streaming solution for node.js?

Brad told me that he use VLC as source for his node based Radio.

So I assume that he pipes the output from VLC to Node? How to deal with Metadata ? Is there a way to get them from VLC either ? Or at least is it possible to get the Current Song ID or some other way to identify the current playing song? An example would be very nice.


Any constructive help is welcome :)

Staceystaci answered 9/4, 2014 at 12:32 Comment(4)
I'm doing something similar, I'm using the shoutcast protocol, so the only thing that changes is a URI to the file. Because you are streaming directly from a single file, in your function stream.on('end',callback) you need to point to another one. Commonly, you would store your available files in a database and chose a subset from your table as your playlist.Bounded
Check this library out, it queues up your files to form a playlist github.com/ncb000gt/node-queuestreamBounded
Thank you very much. I am not looking for a simple List which gets played back from the start to the end once a client starts playback. I am looking for a Player which keeps 'playing' even if no client is connected so that the clients will have a Radio like experience. idea?Staceystaci
For anyone who may read this, try out npmjs.com/package/queuestream. It's old but it works.Cirrhosis

© 2022 - 2024 — McMap. All rights reserved.