Zeno Fox
Zeno Fox

Reputation: 7

Node.js play-sound: TypeError: Cannot read property 'play' of undefined

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

Answers (1)

Rory O'Kane
Rory O'Kane

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

Related Questions