-
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
Showing
5 changed files
with
40 additions
and
18 deletions.
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
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 |
---|---|---|
@@ -1,8 +1,26 @@ | ||
import countDown from '@/assets/audio/countDown.mp3'; | ||
import soundEffect from '@/assets/audio/soundEffect.mp3'; | ||
export const SOUND_SCORE = 'SCORE'; | ||
export const SOUND_COUNTDOWN = 'COUNTDOWN'; | ||
type SoundEffectType = typeof SOUND_SCORE | typeof SOUND_COUNTDOWN; | ||
|
||
const playSoundEffect = (type: 'SCORE' | 'COUNTDOWN') => { | ||
const src = type === 'SCORE' ? soundEffect : countDown; | ||
return new Audio(src); | ||
const mappedSoundFiles: Record<SoundEffectType, () => Promise<string>> = { | ||
SCORE: () => | ||
import('@/assets/audio/soundEffect.mp3').then((module) => module.default), | ||
COUNTDOWN: () => | ||
import('@/assets/audio/countDown.mp3').then((module) => module.default), | ||
}; | ||
|
||
const playSoundEffect = async (type: SoundEffectType) => { | ||
const src = await mappedSoundFiles[type](); | ||
const audio = new Audio(src); | ||
return audio; | ||
}; | ||
export default playSoundEffect; | ||
|
||
// import countDown from '@/assets/audio/countDown.mp3'; | ||
// import soundEffect from '@/assets/audio/soundEffect.mp3'; | ||
|
||
// const playSoundEffect = (type: 'SCORE' | 'COUNTDOWN') => { | ||
// const src = type === 'SCORE' ? soundEffect : countDown; | ||
// return new Audio(src); | ||
// }; | ||
// export default playSoundEffect; |