我們正在撰寫HTML5/JavaScript中的Canvas演示實時策略(RTS)遊戲,並且所有工作都非常有效。但是,在Chrome(最新版本)中,聲音會一直停頓並最終放棄。代碼在最新的Firefox,IE9和Safari中運行得很好(雖然在iOS4 iPhone/iPad上沒有任何聲音,但顯然這是Apple的商業決定)。您可以在下面的鏈接中看到自己,只是一次獲得更多的聲音來解決問題。RTS遊戲Chrome5中的HTML5音頻MP3和OGG口吃和停止
http://www.enterprisewarfare.com/Play.aspx
簡化聲音播放代碼如下,請注意每個聲音存在4次(AUDIO_CHANELS_PER_FILE)來模擬一個以上的信道。調整此數字不會導致任何聲音丟失,因此它不會與到達陣列末尾或再次播放相同的音頻對象有關。我們已經嘗試了OGG和MP3文件格式,並且一切都可以在IE9(MP3)和Firefox(OGG)中正常使用。我們也嘗試將文件追溯到開始無濟於事。
this.PlaySound = function(sId)
{
var iSoundMapIndex;
var asoundChannels;
if(sId == null || sId.length == 0) return;
// Grab sound channels array
iSoundMapIndex = this.SoundMap[sId];
asoundChannels = this.Sounds[iSoundMapIndex];
if(asoundChannels == null)
{
this.World.AddMessage("Unable to find sound \"" + sId + "\".");
return;
}
// play the next in sequence
asoundChannels[this.SoundChannel[iSoundMapIndex]].volume = 1;
asoundChannels[this.SoundChannel[iSoundMapIndex]].play();
this.SoundChannel[iSoundMapIndex]++;
if(this.SoundChannel[iSoundMapIndex] == this.AUDIO_CHANNELS_PER_FILE) this.SoundChannel[iSoundMapIndex] = 0;
}
向下投票,因爲您沒有麻煩回答*錯誤是如何修復的。 – John 2016-07-06 22:45:05