mirror of
https://github.com/misskey-dev/misskey
synced 2024-12-26 20:48:30 +09:00
0144408500
* wip * Update maps.ts * wip * wip * wip * wip * Update base.vue * wip * wip * wip * wip * Update link.vue * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update privacy.vue * wip * wip * wip * wip * Update range.vue * wip * wip * wip * wip * Update profile.vue * wip * Update a.vue * Update index.vue * wip * Update sidebar.vue * wip * wip * Update account-info.vue * Update a.vue * wip * wip * Update sounds.vue * wip * wip * wip * wip * wip * wip * wip * wip * Update account-info.vue * Update account-info.vue * wip * wip * wip * Update d-persimmon.json5 * wip
25 lines
652 B
TypeScript
25 lines
652 B
TypeScript
import { device } from '@/cold-storage';
|
|
|
|
const cache = new Map<string, HTMLAudioElement>();
|
|
|
|
export function play(type: string) {
|
|
const sound = device.get('sound_' + type as any);
|
|
if (sound.type == null) return;
|
|
playFile(sound.type, sound.volume);
|
|
}
|
|
|
|
export function playFile(file: string, volume: number) {
|
|
const masterVolume = device.get('sound_masterVolume');
|
|
if (masterVolume === 0) return;
|
|
|
|
let audio: HTMLAudioElement;
|
|
if (cache.has(file)) {
|
|
audio = cache.get(file);
|
|
} else {
|
|
audio = new Audio(`/assets/sounds/${file}.mp3`);
|
|
cache.set(file, audio);
|
|
}
|
|
audio.volume = masterVolume - ((1 - volume) * masterVolume);
|
|
audio.play();
|
|
}
|