Function
playSound
(src: string | undefined)
Source from the content-addressed store, hash-verified
| 87 | } |
| 88 | |
| 89 | export function playSound(src: string | undefined) { |
| 90 | if (typeof Audio === "undefined") return |
| 91 | if (!src) return |
| 92 | const audio = new Audio(src) |
| 93 | audio.play().catch(() => undefined) |
| 94 | return () => { |
| 95 | audio.pause() |
| 96 | audio.currentTime = 0 |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | export function playSoundById(id: string | undefined) { |
| 101 | return soundSrc(id).then((src) => playSound(src)) |
Tested by
no test coverage detected