在谷歌浏览器中:
播放一个 .wav 文件,循环播放。不时播放另一个 .wav 文件作为声音效果。
播放音效时,循环声音的音量会自动降低。音量会在大约 15 秒内再次逐渐增加。
(我猜它会自动闪避http://en.wikipedia.org/wiki/Ducking)
我不希望在播放音效时降低循环的音量。我怎样才能防止这种行为?
示例: http: //www.matthewgatland.com/games/takedown/play/web/audiofail.html
window.AudioContext = window.AudioContext||window.webkitAudioContext;
var context = new AudioContext();
var play = function (buffer, loop) {
var source = context.createBufferSource();
source.buffer = buffer;
if (loop) source.loop = true;
source.connect(context.destination);
source.start(0);
};
var load = function (url, callback) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
request.onload = function() {
context.decodeAudioData(request.response, function(buffer) {
callback(buffer);
}, null);
};
request.send();
};
var musicSound;
var thudSound;
load("res/snd/music0.wav", function (buffer) {
musicSound = buffer;
});
load("res/snd/thud0.wav", function (buffer) {
thudSound = buffer;
});
加载声音后,调用:
play(musicSound, true); //start the music looping
//each time you call this, the music becomes quiet for a few seconds
play(thudSound, false);