简体   繁体   English

javascript音频语法可能不正确?

[英]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. 我已经看到了JavaScript音频的不同语法公式,但是现在我不确定什么是对的还是什么错了。 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. 一切正常,您在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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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