我基本上想要播放一系列的mp3文件,一个接一个地播放。 这并不难,但是我正在努力保持解码器和扬声器通道打开,以便在播放完一首歌后提供新的mp3数据。 以下是我目前已经实现的播放单个mp3文件的简化版本。
var audioOptions = {channels: 2, bitDepth: 16, sampleRate: 44100};
// Create Decoder and Speaker
var decoder = lame.Decoder();
var speaker = new Speaker(audioOptions);
// My Playlist
var songs = ['samples/Piano11.mp3','samples/Piano12.mp3','samples/Piano13.mp3'];
// Read the first file
var inputStream = fs.createReadStream(songs[0]);
// Pipe the read data into the decoder and then out to the speakers
inputStream.pipe(decoder).pipe(speaker);
speaker.on('flush', function(){
// Play next song
});
我正在使用TooTallNate开发的模块node-lame(用于解码)和node-speaker(用于通过扬声器输出音频)。