javascript音频语法可能有误?

时间:2016-04-02 23:53:03

标签: javascript audio

它不播放声音。我已经看到了javascript音频的不同语法配方,现在我对什么是正确的和什么是错的有点不确定。我猜这个问题与新的Audio位有关,因为我不确定这是不对的。谢谢你的帮助。

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();
                        }

1 个答案:

答案 0 :(得分:1)

一切正常,你在URL中有语法问题。

来自:

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

对此:

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