Good work, but looks like I'm doing something wrong
sergionader opened this issue · comments
Hello,
node-mplayer plays perfectly my mp3 files. Nice job!
However, I should have missed something, once I can stop or pause the music (well, any other command will also fail). Below my code:
function musicControl(command, file) {
var player = new mPlayer();
switch (command) {
case 'S':
player.stop();
console.log('this command IS ' + command);
break;
case 'p':
player.pause();
console.log('command IS ' + command);
break;
case 'v':
player.setVolume(30);
console.log('command IS ' + command);
break;
case 'V':
player.setVolume(80);
console.log('command IS ' + command);
break;
case 'P':
player.setFile(file);
player.play({volume: 30});
console.log('command IS ' + command);
break;
default:
}
}
Any help will be appreciated.
Regards,
Sérgio
Hello!
Yeah it seems that there's something broken... I'll investigate and I'll try to fix it as soon as possible. Thanks for reporting the problem!
Loïc
Ha! I just saw the error! You recreate your mPlayer object each time you call the function. Do something like this :
var player = new mPlayer(); //extract this from musicControl
//...
function musicControl(command, file) {
switch (command) {
case 'S':
player.stop();
console.log('this command IS ' + command);
break;
case 'p':
player.pause();
console.log('command IS ' + command);
break;
case 'v':
player.setVolume(30);
console.log('command IS ' + command);
break;
case 'V':
player.setVolume(80);
console.log('command IS ' + command);
break;
case 'P':
player.setFile(file);
player.play({volume: 30});
console.log('command IS ' + command);
break;
default:
}
}
Hi, there. Yes, you are right! -- such a silly mistake...
Everything works now.
Thanks a lot and have a nice day!