I basically want to play a series of mp3-files after each other. It shouldn't be to hard, but I'm struggling to keep the decoder and speaker channel open to feed new mp3 data in after a song has been played. Here is a condensed version from what I have so far, playing one mp3 file.
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
});
I'm using TooTallNate's modules node-lame (for decoding) and node-speaker (for audio output through the speakers).