fix: resume audio

This commit is contained in:
MAZE 2024-01-28 14:44:31 +03:30
parent cd05704a73
commit 8e4d0531e0

View file

@ -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';
@ -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 = [];