node-stream-player
node-stream-player copied to clipboard
Local files playing
Hi,
You wrote on the readme a future local files handling, when do you plan adding this feature or do you have an advise/trick for me to make it works ? :)
Thanks !
Hi,
I've been busy with a lot of other things lately, but I'll give it a look and get back to you tomorrow. I don't think it will be going a huge pain to implement.
On Wednesday, November 18, 2015, Romain Racamier [email protected] wrote:
Hi,
You wrote on the readme a future local files handling, when do you plan adding this feature or do you have an advise/trick for me to make it works ? :)
Thanks !
— Reply to this email directly or view it on GitHub https://github.com/michael-gillett/node-stream-player/issues/1.
Cool :)
I started to do that, if it can help :
StreamPlayer.prototype.getStream = function(url, callback) {
console.log('=> fetching ' + url);
if (url.indexOf('http') === -1) {
fs.exists(url, function (exists) {
if (exists) {
console.log('=> local url exists but is not handled yet');
// return callback(fs.createReadStream(url));
} else {
console.log('=> local url does not exists');
}
return loadNextSong();
});
} else {
return request.get(url).on('response', function(res) {
if (res.headers['content-type'] === 'audio/mpeg') {
return callback(res);
} else {
self.emit('invalid distant url');
return loadNextSong();
}
});
}
};
The commented line does not work for me :'(
I just pushed an update with a first attempt at local MP3 playing capability. The solution was very similar to the one you outlined (not sure why yours didn't work). Pass the path to the file the same way you would pass a URL. If your audio files play too fast/ slow its because the sample rate defaults to 44,100 (I couldn't find an easy way to extract this information from each audio file). You can change this value for all playback at the top of stream-play.js in audioOptions. Let me know if this works for your project.
Hum that was exactly the problem I had :) I'll try to change the sample rate