Reputation: 7
Trying to play a notification sound using the Node.js package play-sound. However, when trying to do so, I get this error: "Node.js play-sound: TypeError: Cannot read property 'play' of undefined"
const player = require('play-sound')(opts = {});
start() {
this.player.play('/sounds/throughQueue.mp3', function(err){
if (err) throw err
})
}
This is what my program looks like if I cut out all the other stuff. Yes, I've installed the play-sound package.
I'm not experienced with JS and Node, if there's any info missing or if there's another package you'd recommend to play a simple notification sound, please let me know!
Looking forward to your answers!
Upvotes: 0
Views: 1298
Reputation: 30428
As CRice said, refer to the defined player
variable with player
, not this.player
:
const player = require('play-sound')(opts = {});
start() {
player.play('/sounds/throughQueue.mp3', function(err){
if (err) throw err
})
}
Upvotes: 1