guo-yu / player

a command line player, supports play mp3 both from uri and local stream.
261 stars 66 forks source link

Error with basic example, the file sounds but then fail #51

Open developez opened 8 years ago

developez commented 8 years ago

I have got his code:

var Player = require('player');

var player = new Player(__dirname + '/public/aran_voice_1.mp3');

player.play(function(err, player){
  console.log('playend!');
});

player.play();

Error messages:

events.js:87
      throw Error('Uncaught, unspecified "error" event.');
            ^
Error: Uncaught, unspecified "error" event.
    at Error (native)
    at Player.emit (events.js:87:13)
    at Player.next ([MY_FOLDER]/node_modules/player/dist/player.js:281:14)
    at Decoder.<anonymous> ([MY_FOLDER]/node_modules/player/dist/player.js:172:25)
    at Decoder.g (events.js:199:16)
    at Decoder.emit (events.js:129:20)
    at finishMaybe ([MY_FOLDER]/node_modules/player/node_modules/lame/node_modules/readable-stream/lib/_stream_writable.js:371:12)
    at afterWrite ([MY_FOLDER]/node_modules/player/node_modules/lame/node_modules/readable-stream/lib/_stream_writable.js:291:5)
    at onwrite ([MY_FOLDER]/node_modules/player/node_modules/lame/node_modules/readable-stream/lib/_stream_writable.js:281:7)
    at WritableState.onwrite ([MY_FOLDER]/node_modules/player/node_modules/lame/node_modules/readable-stream/lib/_stream_writable.js:106:5)

I am working in a rapsberry B+. I have to install "speaker" using npm and libasound2-dev.

developez commented 8 years ago

More info using events.

Code:

var Player = require('player');
var debug = require('debug')('player');

var songs = [__dirname + '/aran_voice_1.mp3'];
var player = new Player(songs);

player
  .on('playing', function(song) {
    console.log('I\'m playing... ');
  })
  .on('playend', function(song) {
    console.log('Play done, Switching to next one ...');
  })
  .on('error', function(err) {
    console.log('Error');
    console.log(err);
  })
  .play(function(err, player){
    console.log('playend!');
    console.log(err);
  });

The output is:

I'm playing...
Error
No next song was found

It seems that expect a new song, but I only give to player one song. Also, using "new Player('path');" fails.

developez commented 8 years ago

Now I understand the error. As error event is not caught, the process fails, and in other hand, that error event is fired always on line 223 (this.emit('error', 'No next song was found')). I think that this line is a unnecessary.

Shuunen commented 8 years ago

I have the same error on mine :/ same I had to installl libasound2-dev and everything compile fine, but still have this error... did you find something ?

developez commented 8 years ago

@Shuunen To resolve the error is to need rebuild the package. The problem is on the code because it always fires a event tagged as "error" when the song list finishes.

To deal with this, manage the "error" event.

.on('error', function(err) {
    console.log('Error');
    console.log(err);
 })
x2es commented 7 years ago

why .next() by default?

codexp commented 6 years ago

why throw exception if there is no next item?