mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 08:54:13 +00:00
feat: add media session (wip)
This commit is contained in:
parent
df1b05f7ce
commit
f311ec114e
2 changed files with 14 additions and 4 deletions
|
|
@ -105,6 +105,8 @@ export function App() {
|
||||||
|
|
||||||
<audio
|
<audio
|
||||||
aria-hidden={true}
|
aria-hidden={true}
|
||||||
|
loop
|
||||||
|
muted
|
||||||
ref={audio}
|
ref={audio}
|
||||||
src="/sounds/2-seconds-of-silence.mp3"
|
src="/sounds/2-seconds-of-silence.mp3"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ export function useMediaSession() {
|
||||||
const isPlaying = useSoundStore(state => state.isPlaying);
|
const isPlaying = useSoundStore(state => state.isPlaying);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isPlaying) {
|
if (ref.current) {
|
||||||
ref.current?.play().then(() => {
|
ref.current.addEventListener('play', () => {
|
||||||
console.log('hi');
|
console.log('hi');
|
||||||
navigator.mediaSession.metadata = new MediaMetadata({
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
title: 'Moodist',
|
title: 'Moodist',
|
||||||
|
|
@ -17,10 +17,18 @@ export function useMediaSession() {
|
||||||
|
|
||||||
navigator.mediaSession.playbackState = 'playing';
|
navigator.mediaSession.playbackState = 'playing';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ref.current.addEventListener('pause', () => {
|
||||||
|
navigator.mediaSession.playbackState = 'paused';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isPlaying) {
|
||||||
|
ref.current?.play();
|
||||||
} else {
|
} else {
|
||||||
ref.current?.pause();
|
ref.current?.pause();
|
||||||
|
|
||||||
navigator.mediaSession.playbackState = 'paused';
|
|
||||||
}
|
}
|
||||||
}, [isPlaying]);
|
}, [isPlaying]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue