mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 00:44:14 +00:00
feat: add media session (wip)
This commit is contained in:
parent
df1b05f7ce
commit
f311ec114e
2 changed files with 14 additions and 4 deletions
|
|
@ -105,6 +105,8 @@ export function App() {
|
|||
|
||||
<audio
|
||||
aria-hidden={true}
|
||||
loop
|
||||
muted
|
||||
ref={audio}
|
||||
src="/sounds/2-seconds-of-silence.mp3"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ export function useMediaSession() {
|
|||
const isPlaying = useSoundStore(state => state.isPlaying);
|
||||
|
||||
useEffect(() => {
|
||||
if (isPlaying) {
|
||||
ref.current?.play().then(() => {
|
||||
if (ref.current) {
|
||||
ref.current.addEventListener('play', () => {
|
||||
console.log('hi');
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: 'Moodist',
|
||||
|
|
@ -17,10 +17,18 @@ export function useMediaSession() {
|
|||
|
||||
navigator.mediaSession.playbackState = 'playing';
|
||||
});
|
||||
|
||||
ref.current.addEventListener('pause', () => {
|
||||
navigator.mediaSession.playbackState = 'paused';
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (isPlaying) {
|
||||
ref.current?.play();
|
||||
} else {
|
||||
ref.current?.pause();
|
||||
|
||||
navigator.mediaSession.playbackState = 'paused';
|
||||
}
|
||||
}, [isPlaying]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue