mirror of
https://github.com/remvze/moodist.git
synced 2025-12-18 17:34:17 +00:00
feat: add media session (wip)
This commit is contained in:
parent
1547b0a436
commit
4f752bb6d0
1 changed files with 12 additions and 0 deletions
|
|
@ -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…
Add table
Reference in a new issue