mirror of
https://github.com/remvze/moodist.git
synced 2025-09-29 15:30:49 -04:00
fix: remove media session
This commit is contained in:
parent
f311ec114e
commit
8d01d74bd3
@ -18,7 +18,6 @@ import { FADE_OUT } from '@/constants/events';
|
||||
|
||||
import type { Sound } from '@/data/types';
|
||||
import { subscribe } from '@/lib/event';
|
||||
import { useMediaSession } from '@/hooks/use-media-session';
|
||||
|
||||
export function App() {
|
||||
const categories = useMemo(() => sounds.categories, []);
|
||||
@ -86,30 +85,18 @@ export function App() {
|
||||
return [...favorites, ...categories];
|
||||
}, [favoriteSounds, categories]);
|
||||
|
||||
const audio = useMediaSession();
|
||||
|
||||
return (
|
||||
<>
|
||||
<SnackbarProvider>
|
||||
<StoreConsumer>
|
||||
<Container>
|
||||
<div id="app" />
|
||||
<Buttons />
|
||||
<Categories categories={allCategories} />
|
||||
</Container>
|
||||
<SnackbarProvider>
|
||||
<StoreConsumer>
|
||||
<Container>
|
||||
<div id="app" />
|
||||
<Buttons />
|
||||
<Categories categories={allCategories} />
|
||||
</Container>
|
||||
|
||||
<Toolbar />
|
||||
<SharedModal />
|
||||
</StoreConsumer>
|
||||
</SnackbarProvider>
|
||||
|
||||
<audio
|
||||
aria-hidden={true}
|
||||
loop
|
||||
muted
|
||||
ref={audio}
|
||||
src="/sounds/2-seconds-of-silence.mp3"
|
||||
/>
|
||||
</>
|
||||
<Toolbar />
|
||||
<SharedModal />
|
||||
</StoreConsumer>
|
||||
</SnackbarProvider>
|
||||
);
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
import { useSoundStore } from '@/store';
|
||||
|
||||
export function useMediaSession() {
|
||||
const ref = useRef<HTMLAudioElement | null>(null);
|
||||
|
||||
const isPlaying = useSoundStore(state => state.isPlaying);
|
||||
|
||||
useEffect(() => {
|
||||
if (ref.current) {
|
||||
ref.current.addEventListener('play', () => {
|
||||
console.log('hi');
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: 'Moodist',
|
||||
});
|
||||
|
||||
navigator.mediaSession.playbackState = 'playing';
|
||||
});
|
||||
|
||||
ref.current.addEventListener('pause', () => {
|
||||
navigator.mediaSession.playbackState = 'paused';
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (isPlaying) {
|
||||
ref.current?.play();
|
||||
} else {
|
||||
ref.current?.pause();
|
||||
}
|
||||
}, [isPlaying]);
|
||||
|
||||
return ref;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user