fix(frontend): 通知音がほぼ同時に鳴った場合は再生をブロックするように(音割れ防止) (#12433)

* (fix) 通知音がダブって音割れしないように

* Update Changelog
This commit is contained in:
かっこかり 2023-11-26 13:20:46 +09:00 committed by GitHub
parent 5bdae9f6d0
commit 755ca97857
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -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) {