Skip to content

Commit

Permalink
fix: resume audio
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Jan 28, 2024
1 parent cd05704 commit 8e4d053
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/components/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo } from 'react';
import { useMemo, useEffect } from 'react';
import { useShallow } from 'zustand/react/shallow';
import { BiSolidHeart } from 'react-icons/bi/index';
import { Howler } from 'howler';

import { useSoundStore } from '@/store';

Expand Down Expand Up @@ -36,6 +37,22 @@ export function App() {
);
}, [favorites, categories]);

useEffect(() => {
const onChange = () => {
const { ctx } = Howler;

if (ctx && !document.hidden) {
setTimeout(() => {
ctx.resume();
}, 100);
}
};

document.addEventListener('visibilitychange', onChange, false);

return () => document.removeEventListener('visibilitychange', onChange);
}, []);

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

Expand Down

0 comments on commit 8e4d053

Please sign in to comment.