From 42bede0340285432caca917372d0731c283261a3 Mon Sep 17 00:00:00 2001 From: Iskandar Zulkarnaien Date: Fri, 13 Sep 2019 13:23:36 +0800 Subject: [PATCH] Add early return for zero duration sounds (#932) * Add early return for zero duration sounds * Change guard clause to include all non-positive durations --- public/externalLibs/sound/sounds.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/externalLibs/sound/sounds.js b/public/externalLibs/sound/sounds.js index dc85cd6548..95ece0048b 100644 --- a/public/externalLibs/sound/sounds.js +++ b/public/externalLibs/sound/sounds.js @@ -202,6 +202,8 @@ function play_unsafe(sound) { // If a sound is already playing, terminate execution } else if (_playing || _safeplaying) { throw new Error("play: audio system still playing previous sound"); + } else if (get_duration(sound) <= 0) { + return sound; } else { // Declaring duration and wave variables var wave = get_wave(sound); @@ -308,6 +310,8 @@ function play(sound) { // If a sound is already playing, terminate execution. if (_safeplaying || _playing) { throw new Error("play: audio system still playing previous sound"); + } else if (get_duration(sound) <= 0) { + return sound; } else { // Discretize the input sound var data = discretize(get_wave(sound), get_duration(sound));