Pencil
1
How To Make Multiple Background Musics Thats Toggleable
Right Now I Have This:
var music1 = new Sound(“./assets/sound/music1.mp3”, 0.5, 10);
var music2 = new Sound(“./assets/sound/music2.mp3”, 0.5, 10);
var music3 = new Sound(“./assets/sound/music3.mp3”, 0.5, 10);
musicstop = function() {
music1.pause();
music2.pause();
music3.pause();
}
music1 = function() {
music1.play();
music2.pause();
music3.pause();
};
music2 = function() {
music2.play();
music1.pause();
music3.pause();
};
music3 = function() {
music1.play();
music1.pause();
music2.pause();
};
Any Solution
wh0
2
Looking good at a pseudocode level. What’s new Sound
in your snippet?
Pencil
3
Idk What The New Sound Is
tiago
5
Hi! I think new Sound
doesn’t work. Try new Audio
Pencil
6
Nah new Sound Works
I Just Dont Know How To Get Music To Play From A Button
tiago
7
Hi! I’m gonna make a glitch project to test everything for myself
Edit: Actually, quite easy
/*
Your HTML:
<button onclick="toggleAudio()">Toggle background audio</button>
*/
var backgroundAudio = new Audio(
"https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"
);
function toggleAudio() {
return backgroundAudio.paused ? backgroundAudio.play() : backgroundAudio.pause();
}
1 Like
Pencil
8
This Man Is Expert
Edit: Is It Possible To Make It A Checkbox?
1 Like
tiago
9
Hi! Yes it is! Try:
<input type="checkbox" onchange="toggleAudio()">
var backgroundAudio = new Audio(
"https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"
);
backgroundAudio.loop = true;
function toggleAudio() {
return backgroundAudio.paused ? backgroundAudio.play() : backgroundAudio.pause();
}
Click the checkbox to enable and disable the background audio
1 Like
system
Closed
11
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.