1

嘿伙计们,我为我的游戏构建了一个 AudioQueue,但不知何故它不起作用,代码:

handleAction: function ( src )
    {
        var oAudio = document.getElementById('voice');

        if(this.lastSoundPlayed == undefined || src != this.lastSoundPlayed.src) // checks if there is an actual new sound incoming.
        {
            var self  = this;
            oAudio.src = src; //sets the source
            oAudio.load();
            oAudio.onloadeddata  = oAudio.play(); // when loaded play the sound
            oAudio.onended = self.soundDone( self, oAudio ); //when the sound is finished fire the soundDone function
        }
    }

soundDone() 函数:

soundDone: function( self , oAudio )
    {
        console.log("Finished"); //logs that the sound is finished
        self.lastSoundPlayed = oAudio; //sets the lastSoundPlayed
        self.sendNotification(self.SC_ACTION_COMPLETE); //fires off a notification that the sound is finished (im using pureMVC)
    }

那么实际的问题是他认为声音是立即完成的。我记录了我的声音的持续时间并且所有的都是 NaN?我已经用 console.log(oAudio.duration) 进行了检查。我不知道为什么会这样。我也有背景音乐,我以与这些声音相同的方式播放,并且背景音乐没有错。

有人可以帮助我吗?

编辑:这是我的音频的音频标签:

<audio id="voice" src="mySound.mp3" controls preload="auto" ></audio>
4

1 回答 1

0

几周前发现的,当我打电话给它时,声音并没有完全加载。

于 2012-06-04T09:27:13.223 回答