mirror of
https://github.com/remvze/moodist.git
synced 2026-02-28 00:53:13 +08:00
feat: add media session (wip)
This commit is contained in:
@@ -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(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user