mirror of
https://github.com/remvze/moodist.git
synced 2025-09-29 15:30:49 -04:00
feat: add media session (wip)
This commit is contained in:
parent
1547b0a436
commit
4f752bb6d0
@ -86,6 +86,8 @@ export function App() {
|
|||||||
}, [favoriteSounds, categories]);
|
}, [favoriteSounds, categories]);
|
||||||
|
|
||||||
const audioElement = useRef<HTMLAudioElement | null>(null);
|
const audioElement = useRef<HTMLAudioElement | null>(null);
|
||||||
|
|
||||||
|
const play = useSoundStore(state => state.play);
|
||||||
const isPlaying = useSoundStore(state => state.isPlaying);
|
const isPlaying = useSoundStore(state => state.isPlaying);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -96,6 +98,16 @@ export function App() {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
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(() => {
|
useEffect(() => {
|
||||||
if (isPlaying) {
|
if (isPlaying) {
|
||||||
audioElement.current?.play().then(() => {
|
audioElement.current?.play().then(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user