简体   繁体   中英

javascript audio syntax might be wrong?

It doesn't play the sound. I've seen different syntax formulations for javascript audio and now I'm a little unsure about what is right and what is wrong. I'm guessing the issue is with the new Audio bit since I'm not sure if that's right. Thanks for the help.

var greenSound = new Audio('<https://s3.amazonaws.com/freecodecamp/simonSound1.mp3>');
    var redSound = new Audio('<https://s3.amazonaws.com/freecodecamp/simonSound2.mp3>');
    var blueSound = new Audio('<https://s3.amazonaws.com/freecodecamp/simonSound3.mp3>');
    var yellowSound = new Audio('<https://s3.amazonaws.com/freecodecamp/simonSound4.mp3>');
    var sounds = [greenSound, redSound, blueSound, yellowSound];
    var soundNums = [];


num = Math.floor(4*Math.random());
                    simon.push(moves[num]);
                    soundNums.push(num);
                    for(var i = 0; i < simon.length; i++)
                        {
                            $(simon[i]).fadeOut(200).fadeIn(200);
                            (sounds[soundNums[i]]).play();
                        }

Everything works fine you have syntax issue in URL.

From this:

var mp3 = new Audio('<https://s3.amazonaws.com/freecodecamp/simonSound1.mp3>');

To this:

var mp3 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM