-
-
Save mii9000/c4b288f2283458a2bd58 to your computer and use it in GitHub Desktop.
basic nodejs mp3 player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var async = require('async'); | |
var lame = require('lame'); | |
var fs = require('fs'); | |
var Speaker = require('speaker'); | |
var volume = require("pcm-volume"); | |
var audioOptions = { | |
channels: 2, | |
bitDepth: 16, | |
sampleRate: 44100, | |
mode: lame.STEREO | |
}; | |
var song = 'test.mp3'; | |
function playStream(input, options) { | |
var decoder = lame.Decoder(); | |
options = options || {}; | |
var v = new volume(); | |
if (options.volume) { | |
v.setVolume(options.volume); | |
} | |
var speaker = new Speaker(audioOptions); | |
speaker.on('finish', function() { | |
if (options.loop) { | |
console.log('loop'); | |
// i want to restart here | |
start(); | |
} | |
}); | |
function start() { | |
//input.pos = 0; | |
console.dir(input); | |
v.pipe(speaker); | |
decoder.pipe(v); | |
input.pipe(decoder); | |
} | |
start(); | |
} | |
var inputStream = fs.createReadStream(song); | |
playStream(inputStream, { | |
volume: 0.5, | |
loop: true | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment