基于 NodeJS 的Radio(不带 ShoutCast)

2024-05-08

我喜欢创建一个基于 NodeJS 的广播电台not使用ShoutCast。

基于 NodeJS 的播放列表

目前我已成功将音频文件发送到浏览器,但我不知道如何创建服务器端播放列表它会持续“播放”当前歌曲,并在播放结束后重新开始播放。

这就是我目前的方法:

'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 作为播放列表?

刚刚发现这个线程: 有关的:Node.js 是否有一个好的类似广播的音频流解决方案? https://stackoverflow.com/questions/16224808/is-there-a-good-radio-like-audio-streaming-solution-for-node-js/16239355?noredirect=1#comment35066445_16239355

Brad 告诉我,他使用 VLC 作为他的基于节点的广播的来源。

所以我假设他将输出从 VLC 传输到 Node? 如何处理元数据? 有没有办法从 VLC 获取它们? 或者至少是否有可能获取当前歌曲 ID 或其他方式来识别当前播放的歌曲? 举个例子就很好了。


欢迎任何建设性的帮助:)


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

基于 NodeJS 的Radio(不带 ShoutCast) 的相关文章

随机推荐