mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 08:54:13 +00:00
fix: remove media session
This commit is contained in:
parent
34d3f07581
commit
9338b1d30a
1 changed files with 12 additions and 57 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { useMemo, useEffect, useRef } from 'react';
|
||||
import { useMemo, useEffect } from 'react';
|
||||
import { useShallow } from 'zustand/react/shallow';
|
||||
import { BiSolidHeart } from 'react-icons/bi/index';
|
||||
import { Howler } from 'howler';
|
||||
|
|
@ -85,63 +85,18 @@ export function App() {
|
|||
return [...favorites, ...categories];
|
||||
}, [favoriteSounds, categories]);
|
||||
|
||||
const audioElement = useRef<HTMLAudioElement | null>(null);
|
||||
|
||||
const play = useSoundStore(state => state.play);
|
||||
const isPlaying = useSoundStore(state => state.isPlaying);
|
||||
|
||||
useEffect(() => {
|
||||
const dest = Howler.ctx.createMediaStreamDestination();
|
||||
|
||||
Howler.masterGain.connect(dest);
|
||||
|
||||
if (audioElement.current) {
|
||||
audioElement.current.volume = 0;
|
||||
audioElement.current.srcObject = dest.stream;
|
||||
}
|
||||
}, []);
|
||||
|
||||
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) {
|
||||
audioElement.current?.play().then(() => {
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: 'Moodist',
|
||||
});
|
||||
|
||||
navigator.mediaSession.playbackState = 'playing';
|
||||
});
|
||||
} else {
|
||||
audioElement.current?.pause();
|
||||
navigator.mediaSession.playbackState = 'paused';
|
||||
}
|
||||
}, [isPlaying]);
|
||||
|
||||
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} ref={audioElement} src="" />
|
||||
</>
|
||||
<Toolbar />
|
||||
<SharedModal />
|
||||
</StoreConsumer>
|
||||
</SnackbarProvider>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue