Skip to content

Commit 657c260

Browse files
iskandarzulkarnaienwltan
authored andcommitted
Add early return for zero duration sounds (source-academy#932)
* Add early return for zero duration sounds * Change guard clause to include all non-positive durations
1 parent b4bc2ac commit 657c260

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

public/externalLibs/sound/sounds.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ function play_unsafe(sound) {
202202
// If a sound is already playing, terminate execution
203203
} else if (_playing || _safeplaying) {
204204
throw new Error("play: audio system still playing previous sound");
205+
} else if (get_duration(sound) <= 0) {
206+
return sound;
205207
} else {
206208
// Declaring duration and wave variables
207209
var wave = get_wave(sound);
@@ -308,6 +310,8 @@ function play(sound) {
308310
// If a sound is already playing, terminate execution.
309311
if (_safeplaying || _playing) {
310312
throw new Error("play: audio system still playing previous sound");
313+
} else if (get_duration(sound) <= 0) {
314+
return sound;
311315
} else {
312316
// Discretize the input sound
313317
var data = discretize(get_wave(sound), get_duration(sound));

0 commit comments

Comments
 (0)