Skip to content

Commit

Permalink
fix: connect audio context to audio element
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Jan 28, 2024
1 parent b77c817 commit 463667c
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/components/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo, useEffect } from 'react';
import { useMemo, useEffect, useRef } from 'react';
import { useShallow } from 'zustand/react/shallow';
import { BiSolidHeart } from 'react-icons/bi/index';
import { Howler } from 'howler';
Expand All @@ -19,6 +19,8 @@ import { sounds } from '@/data/sounds';
import type { Sound } from '@/data/types';

export function App() {
const audio = useRef<HTMLAudioElement | null>(null);

const categories = useMemo(() => sounds.categories, []);

const favorites = useSoundStore(useShallow(state => state.getFavorites()));
Expand Down Expand Up @@ -53,6 +55,15 @@ export function App() {
return () => document.removeEventListener('visibilitychange', onChange);
}, []);

useEffect(() => {
if (audio.current) {
const { ctx } = Howler;
const dest = ctx.createMediaStreamDestination();
audio.current.srcObject = dest.stream;
audio.current.play();
}
}, []);

const allCategories = useMemo(() => {
const favorites = [];

Expand All @@ -69,18 +80,22 @@ export function App() {
}, [favoriteSounds, categories]);

return (
<SnackbarProvider>
<StoreConsumer>
<Container>
<div id="app" />
<Buttons />
<Categories categories={allCategories} />
</Container>

<ScrollToTop />
<Menu />
<SharedModal />
</StoreConsumer>
</SnackbarProvider>
<>
<SnackbarProvider>
<StoreConsumer>
<Container>
<div id="app" />
<Buttons />
<Categories categories={allCategories} />
</Container>

<ScrollToTop />
<Menu />
<SharedModal />
</StoreConsumer>
</SnackbarProvider>

<audio aria-hidden={true} ref={audio} src="" />
</>
);
}

0 comments on commit 463667c

Please sign in to comment.