diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2020-11-25 21:31:34 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-25 21:31:34 +0900 |
| commit | 014440850014ee86d766bb07467c2970b17a1fc6 (patch) | |
| tree | ffb652fe1db3365d430ed72ec2c62aaacfbe21fb /src/client/scripts/sound.ts | |
| parent | フォントレンダリングを調整 (diff) | |
| download | misskey-014440850014ee86d766bb07467c2970b17a1fc6.tar.gz misskey-014440850014ee86d766bb07467c2970b17a1fc6.tar.bz2 misskey-014440850014ee86d766bb07467c2970b17a1fc6.zip | |
nanka iroiro (#6853)
* 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
Diffstat (limited to 'src/client/scripts/sound.ts')
| -rw-r--r-- | src/client/scripts/sound.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/client/scripts/sound.ts b/src/client/scripts/sound.ts new file mode 100644 index 0000000000..13fd9a80f5 --- /dev/null +++ b/src/client/scripts/sound.ts @@ -0,0 +1,24 @@ +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(); +} |