-
Notifications
You must be signed in to change notification settings - Fork 15
Using AudioHub
Adding sounds to the watch is relatively easy using the framework's AudioHub. Sounds can be particularly useful when you want to add effects such as alarms or notification sound effects.
Let's add an existing sound to one of the buttons on the watch.
-
Navigate to
./client/src/sounds
. In this directory, you should see the mp3 fileplop.mp3
. Now let's make this sound play whenever the left button is pressed from the homepage. -
AudioHub has one function called
playSound()
which takes two parameters. The first parameter takes the file path for the sound you want to use (In our case, it is./client/src/sounds
.) The second parameter is optional and controls the volume and if left blank, the volume will default to 100%. -
Navigate to
./client/src/js/pages/homePage/homePage.js
. In theleftButtonEvent()
function, add the lineAudioHub.playSound("./client/src/sounds/plop.mp3")
. -
Now when you press the left button from the homepage, it should play a 'plop' sound!
-
Once you're satisfied you've understood this tutorial, feel free to delete this line from the code!
You can add new sound effects to the watch by adding them to the sound
folder.
-
Download any .mp3 file from the Internet. This website is a good source for audio files. For the purpose of this tutorial, we'll say we have an audio file called
demo.mp3
. -
Move your chosen sound effect to
./client/src/sounds
. This is where all your audio files will be stored. -
Follow the same steps as above, but instead of using
plop.mp3
, use your customdemo.mp3
. For the second parameter, the volume control, try using a number between 0 being 0% and 1 being 100%. (For example, 0.5 would be 50% volume). -
Now when you press the left button from the homepage, it should play the sound you downloaded with the volume you have specified!
-
Once you're satisfied you've understood this tutorial, feel free to delete this line from the code!