I have added Howler.js to add background music to my story. However, I want to also add a music button that can mute and unmute the music if you click it. How can I do that?
I have read the documentation of Howler.js, but I'm still pretty confused.
Something like this:
In your JavaScript:
window.muteSound = window.muteSound || { isMuted : false, muteButton : function () { muteSound.isMuted = !muteSound.isMuted; Howler.mute(muteSound.isMuted); } }
Then, in passage:
<tw-link onclick='muteSound.muteButton()'>Mute Sound</tw-link>
You can also use the controls system from my howler-for-harlowe repo, which includes a slightly more full-featured mute button and a volume control.
Yep.
<img id="mute-button" src="url to your image" onclick="muteSound.muteButton()" />
Optional CSS for the pointer-style cursor:
#mute-button { cursor: pointer; }
If you wanted to change the symbol when it's muted, I would recommend using my controls script from the repo (but if that's not an option let me know) and then you can use classes and set the image as a background and swap between them using the .muted class.
After testing the code I gave you, the problem isn't on my end.
Test html file I made. (Note: may take a minute to load / cache. The file is currently hosted on my domain, it will get deleted eventually, so grab it now if you want to see it.)
If you want to look at the code to compare it to yours, save the webpage (right click -> save as on Windows; file -> save as on Mac) and import it into Twine.