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
c66cddc4c9
commit
11a4514a0f
2 changed files with 22 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ 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, []);
|
||||
|
|
@ -85,6 +86,8 @@ export function App() {
|
|||
return [...favorites, ...categories];
|
||||
}, [favoriteSounds, categories]);
|
||||
|
||||
useMediaSession();
|
||||
|
||||
return (
|
||||
<SnackbarProvider>
|
||||
<StoreConsumer>
|
||||
|
|
|
|||
19
src/hooks/use-media-session.ts
Normal file
19
src/hooks/use-media-session.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { useEffect } from 'react';
|
||||
|
||||
import { useSoundStore } from '@/store';
|
||||
|
||||
export function useMediaSession() {
|
||||
const isPlaying = useSoundStore(state => state.isPlaying);
|
||||
|
||||
useEffect(() => {
|
||||
if ('mediaSession' in navigator) {
|
||||
if (isPlaying) {
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: 'Moodist - Ambient Sounds',
|
||||
});
|
||||
} else {
|
||||
navigator.mediaSession.metadata = null;
|
||||
}
|
||||
}
|
||||
}, [isPlaying]);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue