diff options
| author | かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> | 2023-11-26 13:20:46 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-26 13:20:46 +0900 |
| commit | 755ca9785779eaa120c7e4372b61979362e7ceb5 (patch) | |
| tree | f796c77520771bab49d0b5a9ecf8fe9bb6f376b9 /packages/frontend/src/scripts | |
| parent | enhance(frontend): リアクション選択時に音を流せるように (#1... (diff) | |
| download | sharkey-755ca9785779eaa120c7e4372b61979362e7ceb5.tar.gz sharkey-755ca9785779eaa120c7e4372b61979362e7ceb5.tar.bz2 sharkey-755ca9785779eaa120c7e4372b61979362e7ceb5.zip | |
fix(frontend): 通知音がほぼ同時に鳴った場合は再生をブロックするように(音割れ防止) (#12433)
* (fix) 通知音がダブって音割れしないように
* Update Changelog
Diffstat (limited to 'packages/frontend/src/scripts')
| -rw-r--r-- | packages/frontend/src/scripts/sound.ts | 12 |
1 files changed, 10 insertions, 2 deletions
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<string, AudioBuffer>(); +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) { |