mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 08:54:13 +00:00
feat: add media session
This commit is contained in:
parent
8e4d0531e0
commit
5e0a84259f
1 changed files with 25 additions and 0 deletions
|
|
@ -22,6 +22,9 @@ export function App() {
|
||||||
const categories = useMemo(() => sounds.categories, []);
|
const categories = useMemo(() => sounds.categories, []);
|
||||||
|
|
||||||
const favorites = useSoundStore(useShallow(state => state.getFavorites()));
|
const favorites = useSoundStore(useShallow(state => state.getFavorites()));
|
||||||
|
const play = useSoundStore(state => state.play);
|
||||||
|
const pause = useSoundStore(state => state.pause);
|
||||||
|
const isPlaying = useSoundStore(state => state.isPlaying);
|
||||||
|
|
||||||
const favoriteSounds = useMemo(() => {
|
const favoriteSounds = useMemo(() => {
|
||||||
const favoriteSounds = categories
|
const favoriteSounds = categories
|
||||||
|
|
@ -53,6 +56,28 @@ export function App() {
|
||||||
return () => document.removeEventListener('visibilitychange', onChange);
|
return () => document.removeEventListener('visibilitychange', onChange);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
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) {
|
||||||
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
|
title: 'Moodist',
|
||||||
|
});
|
||||||
|
|
||||||
|
navigator.mediaSession.playbackState = 'playing';
|
||||||
|
} else {
|
||||||
|
navigator.mediaSession.playbackState = 'paused';
|
||||||
|
}
|
||||||
|
}, [isPlaying]);
|
||||||
|
|
||||||
const allCategories = useMemo(() => {
|
const allCategories = useMemo(() => {
|
||||||
const favorites = [];
|
const favorites = [];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue