Skip to content

Commit

Permalink
fix(frontend): 通知音がほぼ同時に鳴った場合は再生をブロックするように(音割れ防止) (misskey-dev#12433)
Browse files Browse the repository at this point in the history
* (fix) 通知音がダブって音割れしないように

* Update Changelog
  • Loading branch information
kakkokari-gtyih authored and anatawa12 committed Nov 27, 2023
1 parent 9e3a63f commit 9a2e2b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
### Client
- Enhance: 絵文字のオートコンプリート機能強化 #12364
- fix: 「設定のバックアップ」で一部の項目がバックアップに含まれていなかった問題を修正
- Fix: 一度に大量の通知が入った際に通知音が音割れする問題を修正

### Server
- Fix: 何もノートしていないユーザーのフィードにアクセスするとエラーになる問題を修正
Expand Down
12 changes: 10 additions & 2 deletions packages/frontend/src/scripts/sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -86,8 +87,15 @@ export function setVolume(audio: HTMLAudioElement, volume: number): HTMLAudioEle
export function play(type: 'noteMy' | 'note' | 'antenna' | 'channel' | 'notification') {
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) {
Expand Down

0 comments on commit 9a2e2b3

Please sign in to comment.