NodeJS basedRadio (without ShoutCast)

我是研究僧i 提交于 2019-12-04 14:29:18

问题


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

来源:https://stackoverflow.com/questions/22962666/nodejs-basedradio-without-shoutcast

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!