HTML5、Javascript:音频结束时不工作
嘿,伙计们,我为我的游戏建立了一个音频队列,但不知怎么的,它不起作用,代码:HTML5、Javascript:音频结束时不工作,javascript,html,audio,browser,Javascript,Html,Audio,Browser,嘿,伙计们,我为我的游戏建立了一个音频队列,但不知怎么的,它不起作用,代码: handleAction: function ( src ) { var oAudio = document.getElementById('voice'); if(this.lastSoundPlayed == undefined || src != this.lastSoundPlayed.src) // checks if there is an actual new s
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)
}
实际上的问题是,他认为声音马上就结束了。我记下了我的声音的持续时间,还有所有的声音吗?我已经用console.log(oAudio.duration)检查过了。我不知道为什么会这样。我也有背景音乐,我用与这些声音相同的方式播放,背景音乐没有什么问题
有人能帮我吗
编辑:这是我的音频的音频标签:
<audio id="voice" src="mySound.mp3" controls preload="auto" ></audio>
几周前找到了它,当我调用它时,声音还没有完全加载。oAudio.com。但我认为它还没有满载,这就是为什么。。。谢谢你!你能添加返回NaN的代码吗?我到处都找不到oAudio。