From 0a5c963ae81715722513e2a419923f33418e4be3 Mon Sep 17 00:00:00 2001 From: henz Date: Tue, 12 Sep 2023 14:17:15 +0800 Subject: [PATCH] bug fix: zero duration sound --- src/bundles/sound/functions.ts | 4 ++++ src/bundles/stereo_sound/functions.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/bundles/sound/functions.ts b/src/bundles/sound/functions.ts index f1d296e73..50693c23f 100644 --- a/src/bundles/sound/functions.ts +++ b/src/bundles/sound/functions.ts @@ -347,6 +347,8 @@ export function play_in_tab(sound: Sound): Sound { throw new Error(`${play_in_tab.name}: audio system still playing previous sound`); } else if (get_duration(sound) < 0) { throw new Error(`${play_in_tab.name}: duration of sound is negative`); + } else if (get_duration(sound) === 0) { + return sound; } else { // Instantiate audio context if it has not been instantiated. if (!audioplayer) { @@ -417,6 +419,8 @@ export function play(sound: Sound): Sound { ); } else if (get_duration(sound) < 0) { throw new Error(`${play.name}: duration of sound is negative`); + } else if (get_duration(sound) === 0) { + return sound; } else { // Instantiate audio context if it has not been instantiated. if (!audioplayer) { diff --git a/src/bundles/stereo_sound/functions.ts b/src/bundles/stereo_sound/functions.ts index 84ddb23ca..7689708fd 100644 --- a/src/bundles/stereo_sound/functions.ts +++ b/src/bundles/stereo_sound/functions.ts @@ -382,6 +382,8 @@ export function play_in_tab(sound: Sound): Sound { throw new Error(`${play_in_tab.name}: audio system still playing previous sound`); } else if (get_duration(sound) < 0) { throw new Error(`${play_in_tab.name}: duration of sound is negative`); + } else if (get_duration(sound) === 0) { + return sound; } else { // Instantiate audio context if it has not been instantiated. if (!audioplayer) { @@ -478,6 +480,8 @@ export function play(sound: Sound): Sound { throw new Error(`${play.name}: audio system still playing previous sound`); } else if (get_duration(sound) < 0) { throw new Error(`${play.name}: duration of sound is negative`); + } else if (get_duration(sound) === 0) { + return sound; } else { // Instantiate audio context if it has not been instantiated. if (!audioplayer) {