Skip to content

Commit

Permalink
feat: use HTML5 streaming on sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed Aug 11, 2022
1 parent e407dde commit af49f61
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/components/Sound/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,20 @@ export const Sound: React.FC<ISound> = ({ name, iconFile, audioFile }) => {

const [soundIsActive, setSoundIsActive] = useState(false)
const [howlSoundInstance, setHowlSoundInstance] = useState<Howl | null>(null)
const [soundIsLoading, setSoundIsLoading] = useState(true)
const [currentSoundVolume, setCurrentSoundVolume] = useState(1)

useEffect(() => {
setHowlSoundInstance(
new Howl({
src: `./sounds/${audioFile.name}`,
loop: true,
onload: () => {
setSoundIsLoading(false)
}
html5: true
})
)
}, [])

async function toggleSoundState() {
if (howlSoundInstance && !soundIsLoading) {
if (howlSoundInstance) {
if (soundIsActive) {
howlSoundInstance.fade(currentSoundVolume, 0, FADE_TIME_MS)
await sleep(FADE_TIME_MS)
Expand All @@ -63,8 +60,8 @@ export const Sound: React.FC<ISound> = ({ name, iconFile, audioFile }) => {
<SoundComponent title={name}>
<SoundButton
id={`${name}-button`}
className={`${soundIsActive ? 'selected' : ''} ${
soundIsLoading && 'disabled'
className={`${
soundIsActive ? 'selected' : ''
} umami--click--${name}-sound`}
onClick={() => toggleSoundState()}
>
Expand Down

1 comment on commit af49f61

@vercel
Copy link

@vercel vercel bot commented on af49f61 Aug 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

noisekun – ./

noisekun-mateusfg7.vercel.app
noisekun.vercel.app
noisekun-git-main-mateusfg7.vercel.app

Please sign in to comment.