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 { useShallow } from 'zustand/react/shallow';
|
||||||
import { BiSolidHeart } from 'react-icons/bi/index';
|
import { BiSolidHeart } from 'react-icons/bi/index';
|
||||||
import { Howler } from 'howler';
|
import { Howler } from 'howler';
|
||||||
|
|
@ -85,49 +85,7 @@ export function App() {
|
||||||
return [...favorites, ...categories];
|
return [...favorites, ...categories];
|
||||||
}, [favoriteSounds, 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 (
|
return (
|
||||||
<>
|
|
||||||
<SnackbarProvider>
|
<SnackbarProvider>
|
||||||
<StoreConsumer>
|
<StoreConsumer>
|
||||||
<Container>
|
<Container>
|
||||||
|
|
@ -140,8 +98,5 @@ export function App() {
|
||||||
<SharedModal />
|
<SharedModal />
|
||||||
</StoreConsumer>
|
</StoreConsumer>
|
||||||
</SnackbarProvider>
|
</SnackbarProvider>
|
||||||
|
|
||||||
<audio aria-hidden={true} ref={audioElement} src="" />
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue