| 21 | } |
| 22 | |
| 23 | export function loadSoundFile(file: string) { |
| 24 | const current = getAudio() |
| 25 | if (!current) return Promise.resolve(null) |
| 26 | const cached = sounds.get(file) |
| 27 | if (cached) return cached |
| 28 | const task = readFile(file) |
| 29 | .then((bytes) => current.loadSound(bytes)) |
| 30 | .catch((error) => { |
| 31 | console.debug("failed to load tui sound", { file, error }) |
| 32 | return null |
| 33 | }) |
| 34 | sounds.set(file, task) |
| 35 | return task |
| 36 | } |
| 37 | |
| 38 | export function play(sound: AudioSound, options?: AudioPlayOptions) { |
| 39 | const current = getAudio() |