From 4f752bb6d048c0260ff6b2aada59c227624b2d17 Mon Sep 17 00:00:00 2001 From: MAZE Date: Sat, 11 May 2024 16:25:14 +0330 Subject: [PATCH] feat: add media session (wip) --- src/components/app/app.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/app/app.tsx b/src/components/app/app.tsx index 5772bf2..5eb5aee 100644 --- a/src/components/app/app.tsx +++ b/src/components/app/app.tsx @@ -86,6 +86,8 @@ export function App() { }, [favoriteSounds, categories]); const audioElement = useRef(null); + + const play = useSoundStore(state => state.play); const isPlaying = useSoundStore(state => state.isPlaying); useEffect(() => { @@ -96,6 +98,16 @@ export function App() { } }, []); + useEffect(() => { + try { + navigator.mediaSession.setActionHandler('play', play); + navigator.mediaSession.setActionHandler('pause', pause); + navigator.mediaSession.setActionHandler('stop', pause); + } catch (error) { + console.log('Media session is no supported yet'); + } + }, [play, pause]); + useEffect(() => { if (isPlaying) { audioElement.current?.play().then(() => {