diff --git a/docs/assets/js/sounds/soundcontext.js b/docs/assets/js/sounds/soundcontext.js index 9804973..f9dd3da 100644 --- a/docs/assets/js/sounds/soundcontext.js +++ b/docs/assets/js/sounds/soundcontext.js @@ -12,9 +12,12 @@ * // ... * }); * - * // Play a sound + * // Play a sound using channels * globalSoundContext.playSound(globalSoundContext.channels., sounds.); * + * // Just play a sound now + * globalSoundContext.playSoundNow(sounds.); + * * // Stop a channel * globalSoundContext.mute(globalSoundContext.channels.); */ @@ -39,10 +42,12 @@ class _SoundChannel { */ enqueue(snippet) { + console.log(this.sound_queue) + // If the queue is full, cut out the next sound in the queue to make room - if (this.sound_queue.length >= this.max_size) { - this.sound_queue.splice(1, 1); - } + // if (this.sound_queue.length > this.max_size) { + // this.sound_queue.splice(1, 1); + // } // Append the sound to the queue this.sound_queue.push(snippet); @@ -66,7 +71,7 @@ class _SoundChannel { // Spawn a clean action for that time in the future setTimeout(() => { this._cleanQueue(snippet); - }, length); + }, length * 1000); } /** @@ -92,7 +97,6 @@ class _SoundChannel { } - // Spawn a watcher for the next sound & play it if (this.sound_queue.length > 0) { this.sound_queue[0].play(); @@ -124,7 +128,7 @@ class _SoundContext { // Define all sound channels this.channels = { - bgm: new _SoundChannel(2) + bgm: new _SoundChannel(3) } } @@ -138,6 +142,14 @@ class _SoundContext { channel.enqueue(snippet); } + /** + * Play a sound right now + * @param {SoundSnippet} snippet + */ + playSoundNow(snippet) { + snippet.play(); + } + /** * Stop all sounds in a channel * @param {*} channel diff --git a/docs/assets/js/sounds/soundsnippet.js b/docs/assets/js/sounds/soundsnippet.js index af03267..3aeb74e 100644 --- a/docs/assets/js/sounds/soundsnippet.js +++ b/docs/assets/js/sounds/soundsnippet.js @@ -62,7 +62,7 @@ class SoundSnippet { * Get the sound length in seconds */ getLengthSeconds() { - return 0; + return this.audio.duration; } /**