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 :)
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