我喜欢创建一个基于NodeJS的电台,而不使用ShoutCast。
目前我已设法将音频文件传输到浏览器,但我不知道如何创建服务器端播放列表,这会持续保持"播放"当前的歌曲,一旦到达结束就重新开始。
这就是我目前的做法:
'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);
[编辑]
刚刚找到这个帖子: 相关:Is there a good radio-like audio streaming solution for node.js?
布拉德告诉我,他使用VLC作为基于节点的Radio的源。所以我假设他将输出从VLC传输到Node? 如何处理元数据? 有没有办法让他们从VLC获得? 或者至少可以获得当前歌曲ID或其他方式来识别当前播放的歌曲? 一个例子非常好。
欢迎任何建设性的帮助:)