hermes-web/lib/audio/hooks.ts

28 lines
565 B
TypeScript
Raw Normal View History

2023-12-30 05:56:40 -05:00
import { useState, useEffect } from 'react';
import player from './player';
export const usePlayerState = () => {
const [state, setState] = useState(player.getState());
useEffect(() => {
const unsubscribe = player.subscribe(setState);
return unsubscribe;
}, []);
return state;
};
export const useCurrentTime = () => {
const [currentTime, setCurrentTime] = useState(player.getCurrentTime());
useEffect(() => {
const unsubscribe = player.onChangeCurrentTime(setCurrentTime);
return unsubscribe;
}, []);
return currentTime;
};