feat: add media session (wip)

This commit is contained in:
MAZE 2024-05-11 16:25:14 +03:30
parent 1547b0a436
commit 4f752bb6d0

View File

@ -86,6 +86,8 @@ export function App() {
}, [favoriteSounds, categories]);
const audioElement = useRef<HTMLAudioElement | null>(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(() => {