0

I am developing a lobby for multiplayer online experiment. The lobby basically is a stage where the participants wait until we have the required number of people. I want to play a bell sound that I have in the project public directory public/newPlayerSound.mp3 .. and I have the following helper:

Template.lobby_page.helpers({
    numWaiting(){
        if (Meteor.userId()){
            let lobby = Lobbies.findOne({players:Meteor.userId()});
            if (lobby){
                //play the newPlayerSound.mp3
                return lobby.players.length
            }
        }
    },
});

I want to play the newPlayerSound.mp3 every-time the numWaiting() changes. What would be an easy way to do this?

amaatouq
  • 2,297
  • 5
  • 29
  • 50

1 Answers1

1

Based on what Uri has said here, you can use HTMLAudioElement.

new Audio("newPlayerSound.mp3").play()
Nicholas
  • 156
  • 8