node-stream-player icon indicating copy to clipboard operation
node-stream-player copied to clipboard

Local files playing

Open Shuunen opened this issue 9 years ago • 4 comments

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 !

Shuunen avatar Nov 19 '15 00:11 Shuunen

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.

michael-gillett avatar Nov 20 '15 04:11 michael-gillett

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 :'(

Shuunen avatar Nov 20 '15 08:11 Shuunen

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.

michael-gillett avatar Nov 20 '15 18:11 michael-gillett

Hum that was exactly the problem I had :) I'll try to change the sample rate

Shuunen avatar Nov 20 '15 19:11 Shuunen