0

I have a node.js app which should plays 3 sounds to all of the sockets at a certain time with node.js.

How would I go about getting this to work? Should I have the sound clips on the app.js and somehow emit them? Or should I have them stored in the client Side HTML and a flag to play them emitted to the users?

Could I see examples of how to do the prefered method also? Thank you

Shane_S
  • 119
  • 2
  • 2
  • 9

1 Answers1

0

I suggest you to make the 3 audio files public (for example /public/audio/1.mp3 and relative node routes) and then to split the problem in 2 sub-problems:

  • The first is HOW to play the audio in JavaScript? example
  • The second is WHEN to play the audio?

For example if you're using socket.io I suggest you this simple code (server side):

io.emit('play', { audio: '/public/audio/1.mp3'});

And, for example, this can be the client side code needed:

var socket = io.connect('/');
socket.on('play', function (data) {
    // Here goes the 'HOW' piece of code
    // to play the data.audio track
});
Community
  • 1
  • 1
matteospampani
  • 596
  • 4
  • 12