How to play and stop sound on key press + function

Hello, I’m new to Phaser 3 and in my Options Scene if M is pressed background audio will play and if N is pressed all music is stopped. I’m currently trying to make the audio to work, I haven’t added the stop function yet.

Here’s my code and I followed someone’s tutorial, it’s detecting the key press, but the audio won’t play.

create() {
// Add background
this.add.sprite(800, 450, “optionsbg”);

// Add background audio
this.audio = this.sound.add("musicA");    

// Add M as an input key
this.input.keyboard.addKeys("M");
this.input.keyboard.on("keydown_M", function() {
  console.log("M is pressed");
  this.audio.play();
  this.audio.loop = true;
  console.log("Playing music");    
});

}
} // END OF CREATE

image

This. Either bind your original scope to the keydown function, or create a reference to it outside the keydown function and use that.