mirror of
https://github.com/remvze/moodist.git
synced 2025-10-17 20:10:32 -04:00
feat: add media session (wip)
This commit is contained in:
parent
fc1bd07b7d
commit
ea0dfff9c1
@ -3,25 +3,29 @@ import { useEffect } from 'react';
|
|||||||
import { useSoundStore } from '@/store';
|
import { useSoundStore } from '@/store';
|
||||||
|
|
||||||
export function useMediaSession() {
|
export function useMediaSession() {
|
||||||
|
const play = useSoundStore(state => state.play);
|
||||||
|
const pause = useSoundStore(state => state.pause);
|
||||||
const isPlaying = useSoundStore(state => state.isPlaying);
|
const isPlaying = useSoundStore(state => state.isPlaying);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if ('mediaSession' in navigator) {
|
try {
|
||||||
if (isPlaying) {
|
navigator.mediaSession.setActionHandler('play', play);
|
||||||
console.log('hello');
|
navigator.mediaSession.setActionHandler('pause', pause);
|
||||||
navigator.mediaSession.metadata = new MediaMetadata({
|
navigator.mediaSession.setActionHandler('stop', pause);
|
||||||
title: 'Moodist - Ambient Sounds',
|
} catch (error) {
|
||||||
});
|
console.log('Media session is no supported yet');
|
||||||
|
}
|
||||||
|
}, [play, pause]);
|
||||||
|
|
||||||
navigator.mediaSession.playbackState = 'playing';
|
useEffect(() => {
|
||||||
|
if (isPlaying) {
|
||||||
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
|
title: 'Moodist',
|
||||||
|
});
|
||||||
|
|
||||||
navigator.mediaSession.setActionHandler('play', function () {});
|
navigator.mediaSession.playbackState = 'playing';
|
||||||
navigator.mediaSession.setActionHandler('pause', function () {});
|
} else {
|
||||||
navigator.mediaSession.setActionHandler('stop', function () {});
|
navigator.mediaSession.playbackState = 'paused';
|
||||||
} else {
|
|
||||||
navigator.mediaSession.playbackState = 'paused';
|
|
||||||
console.log('bye');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [isPlaying]);
|
}, [isPlaying]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user