mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-06-23 04:42:29 +08:00
prevent same sound from playing multiple times
This commit is contained in:
@@ -51,9 +51,21 @@ var AudioEngine = {
|
|||||||
},
|
},
|
||||||
_playSound: function (buffer) {
|
_playSound: function (buffer) {
|
||||||
if (!AudioEngine._canPlayAudio()) return;
|
if (!AudioEngine._canPlayAudio()) return;
|
||||||
|
if (AudioEngine._currentSoundEffectAudio &&
|
||||||
|
AudioEngine._currentSoundEffectAudio.source.buffer == buffer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var source = AudioEngine._audioContext.createBufferSource();
|
var source = AudioEngine._audioContext.createBufferSource();
|
||||||
source.buffer = buffer;
|
source.buffer = buffer;
|
||||||
|
source.onended = function(event) {
|
||||||
|
// dereference current sound effect when finished
|
||||||
|
if (AudioEngine._currentSoundEffectAudio &&
|
||||||
|
AudioEngine._currentSoundEffectAudio.source.buffer == buffer) {
|
||||||
|
AudioEngine._currentSoundEffectAudio = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
source.connect(AudioEngine._master);
|
source.connect(AudioEngine._master);
|
||||||
source.start();
|
source.start();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user