From 755ca9785779eaa120c7e4372b61979362e7ceb5 Mon Sep 17 00:00:00 2001 From: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 26 Nov 2023 13:20:46 +0900 Subject: fix(frontend): 通知音がほぼ同時に鳴った場合は再生をブロックするように(音割れ防止) (#12433) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * (fix) 通知音がダブって音割れしないように * Update Changelog --- packages/frontend/src/scripts/sound.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'packages/frontend/src/scripts') diff --git a/packages/frontend/src/scripts/sound.ts b/packages/frontend/src/scripts/sound.ts index 4d7ef9bdee..47ec4171af 100644 --- a/packages/frontend/src/scripts/sound.ts +++ b/packages/frontend/src/scripts/sound.ts @@ -7,6 +7,7 @@ import { defaultStore } from '@/store.js'; const ctx = new AudioContext(); const cache = new Map(); +let canPlay = true; export const soundsTypes = [ null, @@ -82,8 +83,15 @@ export async function loadAudio(file: string, useCache = true) { export function play(type: 'noteMy' | 'note' | 'antenna' | 'channel' | 'notification' | 'reaction') { const sound = defaultStore.state[`sound_${type}`]; if (_DEV_) console.log('play', type, sound); - if (sound.type == null) return; - playFile(sound.type, sound.volume); + if (sound.type == null || !canPlay) return; + + canPlay = false; + playFile(sound.type, sound.volume).then(() => { + // ごく短時間に音が重複しないように + setTimeout(() => { + canPlay = true; + }, 25); + }); } export async function playFile(file: string, volume: number) { -- cgit v1.2.3-freya