Merge branch 'develop' into enhance/input_form_reaction_picker

This commit is contained in:
おさむのひと 2023-11-15 19:53:20 +09:00 committed by GitHub
commit a696a0f019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 12 deletions

View File

@ -23,6 +23,7 @@
- Enhance: プラグインでエラーが発生した場合のハンドリングを強化 - Enhance: プラグインでエラーが発生した場合のハンドリングを強化
- Enhance: 細かなUIのブラッシュアップ - Enhance: 細かなUIのブラッシュアップ
- Enhance: 投稿フォームの絵文字ピッカーをリアクション時に使用するものと同じのを使用するように #12336 - Enhance: 投稿フォームの絵文字ピッカーをリアクション時に使用するものと同じのを使用するように #12336
- Fix: 効果音が再生されるとデバイスで再生している動画や音声が停止する問題を修正 #12339
- Fix: デッキに表示されたチャンネルの表示先チャンネルを切り替えた際、即座に反映されない問題を修正 #12236 - Fix: デッキに表示されたチャンネルの表示先チャンネルを切り替えた際、即座に反映されない問題を修正 #12236
- Fix: プラグインでノートの表示を書き換えられない問題を修正 - Fix: プラグインでノートの表示を書き換えられない問題を修正
- Fix: アイコンデコレーションが見切れる場合がある問題を修正 - Fix: アイコンデコレーションが見切れる場合がある問題を修正

View File

@ -5,7 +5,8 @@
import { defaultStore } from '@/store.js'; import { defaultStore } from '@/store.js';
const cache = new Map<string, HTMLAudioElement>(); const ctx = new AudioContext();
const cache = new Map<string, AudioBuffer>();
export const soundsTypes = [ export const soundsTypes = [
null, null,
@ -60,15 +61,20 @@ export const soundsTypes = [
'noizenecio/kick_gaba7', 'noizenecio/kick_gaba7',
] as const; ] as const;
export function getAudio(file: string, useCache = true): HTMLAudioElement { export async function getAudio(file: string, useCache = true) {
let audio: HTMLAudioElement;
if (useCache && cache.has(file)) { if (useCache && cache.has(file)) {
audio = cache.get(file); return cache.get(file)!;
} else {
audio = new Audio(`/client-assets/sounds/${file}.mp3`);
if (useCache) cache.set(file, audio);
} }
return audio;
const response = await fetch(`/client-assets/sounds/${file}.mp3`);
const arrayBuffer = await response.arrayBuffer();
const audioBuffer = await ctx.decodeAudioData(arrayBuffer);
if (useCache) {
cache.set(file, audioBuffer);
}
return audioBuffer;
} }
export function setVolume(audio: HTMLAudioElement, volume: number): HTMLAudioElement { export function setVolume(audio: HTMLAudioElement, volume: number): HTMLAudioElement {
@ -84,8 +90,17 @@ export function play(type: 'noteMy' | 'note' | 'antenna' | 'channel' | 'notifica
playFile(sound.type, sound.volume); playFile(sound.type, sound.volume);
} }
export function playFile(file: string, volume: number) { export async function playFile(file: string, volume: number) {
const audio = setVolume(getAudio(file), volume); const masterVolume = defaultStore.state.sound_masterVolume;
if (audio.volume === 0) return; if (masterVolume === 0 || volume === 0) {
audio.play(); return;
}
const gainNode = ctx.createGain();
gainNode.gain.value = masterVolume * volume;
const soundSource = ctx.createBufferSource();
soundSource.buffer = await getAudio(file);
soundSource.connect(gainNode).connect(ctx.destination);
soundSource.start();
} }