Solved! with ADDED critical INFO:
Found that the cause is finding the sound when using js
, versus html
(which does! work.)
FINALLY fixed the correct Path ...
/*
Correct PATH:
games
Game_1
Game_1_Support
audio
applause.mp3
js
PlaySound.js
*/
PlaySound("Game_1_Support/audio/applause.mp3");
function PlaySound(id, src) {
var theSound = new Audio();
theSound.src = src;
alert(src);
theSound.play();
}
Thanks! absolutely everyone!
END ADDED INFO
Playing sound with no click interaction within JS doesn't work?
Very old subject based on my research and this research states the user must interact via clicking, e.g., in order for the sound to be played via:
var theSound = new Audio(srcString);
theSound.play();
In the game I am currently developing, upon my clicking a <a>
, the sound does play.
But ... my game also has a ball that moves around the inside of the window and if the ball hits any of the window's sides, I want a sound to play.
No clicking is involved, just my moving the ball around via certain keys, e.g., "r" and "l".
So how do I do this within JS with no clicking?