-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38c2ed3
commit d267f23
Showing
9 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
export type AudioNames = "publish" | "like"; | ||
|
||
export type AudioManifest = Record<AudioNames, { src: string[] }>; | ||
|
||
export const useAudio = (): { | ||
play: (name: AudioNames) => void; | ||
} => { | ||
const audio = new Audio(); | ||
|
||
const play = (name: AudioNames) => { | ||
const audioData = audioManifest.manifest.value?.[name]; | ||
|
||
if (!audioData) { | ||
throw new Error(`Audio not found: ${name}`); | ||
} | ||
|
||
const src = audioData.src[ | ||
Math.floor(Math.random() * audioData.src.length) | ||
] as string; | ||
|
||
audio.src = src; | ||
audio.play(); | ||
}; | ||
|
||
return { play }; | ||
}; | ||
|
||
export const useAudioManifest = () => { | ||
const audioTheme = ref("misskey" as const); | ||
const url = computed(() => `/packs/audio/${audioTheme.value}.json`); | ||
|
||
// Fetch from /packs/audio/:name.json | ||
const manifest = ref(null as null | AudioManifest); | ||
|
||
// Fetch the manifest | ||
watch( | ||
url, | ||
async (url) => { | ||
const response = await fetch(url); | ||
|
||
if (!response.ok) { | ||
throw new Error( | ||
`Failed to fetch audio theme manifest at ${url}`, | ||
); | ||
} | ||
|
||
manifest.value = await response.json(); | ||
|
||
// Preload all audio files | ||
if (manifest.value) { | ||
for (const audioData of Object.values(manifest.value)) { | ||
for (const src of audioData.src) { | ||
new Audio(src); | ||
} | ||
} | ||
} | ||
}, | ||
{ immediate: true }, | ||
); | ||
|
||
return { audioTheme, manifest, url }; | ||
}; | ||
|
||
export const audioManifest = useAudioManifest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"publish": { | ||
"src": [ | ||
"/packs/audio/misskey/n-aec-4va.mp3", | ||
"/packs/audio/misskey/n-aec-4vb.mp3" | ||
] | ||
}, | ||
"like": { | ||
"src": [ | ||
"/packs/audio/misskey/bubble1.mp3", | ||
"/packs/audio/misskey/bubble2.mp3" | ||
] | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.