mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 00:44:14 +00:00
fix: add media session
This commit is contained in:
parent
e422b52436
commit
216b913ccd
1 changed files with 25 additions and 0 deletions
|
|
@ -23,6 +23,9 @@ export function App() {
|
|||
const categories = useMemo(() => sounds.categories, []);
|
||||
|
||||
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 = categories
|
||||
|
|
@ -58,6 +61,28 @@ export function App() {
|
|||
unmuteAudio();
|
||||
}, []);
|
||||
|
||||
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 favorites = [];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue