1
我正在使用這些聲音進行遊戲,所以我在整個播放過程中通過JQuery多次調用它們。在fireFox中,聲音播放良好,但在Chrome和Safari中,每次只播放一次。HTML5音頻無法在某些瀏覽器中工作
<div class="audio-wrapper">
<audio id="successSound" preload="auto">
<source src="sounds/games-sound-fx/cashtill.ogg" type='audio/ogg; codecs="vorbis"'></source>
<source src="sounds/games-sound-fx/cashtill.mp3" type='audio/mpeg; codecs="mp3"'></source>
</audio>
<audio id="failSound" preload="auto">
<source src="sounds/games-sound-fx/electric.ogg" type='audio/ogg; codecs="vorbis"'></source>
<source src="sounds/games-sound-fx/electric.mp3" type='audio/mpeg; codecs="mp3"'></source>
</audio>
<audio id="moveSound" preload="auto">
<source src="sounds/games-sound-fx/throw.ogg" type='audio/ogg; codecs="vorbis"'></source>
<source src="sounds/games-sound-fx/throw.mp3" type='audio/mpeg; codecs="mp3"'></source>
</audio>
<audio id="hitSound" preload="auto">
<source src="sounds/games-sound-fx/hit.ogg" type='audio/ogg; codecs="vorbis"'></source>
<source src="sounds/games-sound-fx/hit.mp3" type='audio/mpeg; codecs="mp3"'></source>
</audio>
<audio id="missSound" preload="auto">
<source src="sounds/games-sound-fx/miss.ogg" type='audio/ogg; codecs="vorbis"'></source>
<source src="sounds/games-sound-fx/miss.mp3" type='audio/mpeg; codecs="mp3"'></source>
</audio>
<audio id="audio-bg">
<source src="sounds/games-sound-fx/BGmusic.ogg" type='audio/ogg; codecs="vorbis"'></source>
<source src="sounds/games-sound-fx/BGmusic.mp3" type='audio/mpeg; codecs="mp3"'></source>
</audio>
</div>
在劇本我把我的大部分的聲音是這樣..
var successSound = $("#successSound")[0];
successSound.play();
但他們中的一些對他們的超時功能。有沒有更好的方法來支持所有瀏覽器?
我已經嘗試過了,仍然沒有喜悅@Lee西奧博爾德 –
我有一個去這裏使用的代碼從文章中,我掛:HTTP://的jsfiddle .net/zXxGZ/11 /和它似乎工作。笛聲持續幾秒鐘。如果您重複按播放鏈接,它會再次播放(反正最多10次)。如果您仍然無法使用它,您是否可以編輯您的答案以包含更全面的代碼示例。 –
謝謝隊友!你知道我會如何淡化聲音嗎? @ Lee Theobald –