shime / play-sound

Play sounds by shelling out to one of the available audio players.
MIT License
208 stars 31 forks source link

Unable to play #30

Open ThatTonybo opened 5 years ago

ThatTonybo commented 5 years ago

I've run into an error when I try to run this code.

let player = require('play-sound')(opts = {});

player.play('Haywyre - Contagious.mp3', function (err) {
    if (err) throw err;
});
INFO: Could not find files for the given pattern(s).
INFO: Could not find files for the given pattern(s).
INFO: Could not find files for the given pattern(s).
INFO: Could not find files for the given pattern(s).
INFO: Could not find files for the given pattern(s).
INFO: Could not find files for the given pattern(s).
INFO: Could not find files for the given pattern(s).
INFO: Could not find files for the given pattern(s).

Is anyone able to provide some insight into this?

dperez3 commented 5 years ago

I have Win10 with mplayer installed and my PATH set to mplayer's directory.

In my case, the problem seemed to be that play-sound was looking for mplayer. And, although, mplayer can be found from Command Prompt terminals, the same is not true for Bash terminals.

For Bash, what works, instead, is mplayer.exe.

So, the solution for me was...

const playSoundPlayers = [
  'mplayer',
  'afplay',
  'mpg123',
  'mpg321',
  'play',
  'omxplayer',
  'aplay',
  'cmdmp3'
];
const players = playSoundPlayers.concat(playSoundPlayers.map(x => `${x}.exe`));

player.play(mp3File, {players: players}, (err: any) => { });