2023-01-08 15:37:16 +01:00
|
|
|
import { useCallback } from "react";
|
|
|
|
import { useVideoPlayerState } from "../VideoContext";
|
2023-01-08 13:15:32 +01:00
|
|
|
|
|
|
|
export function PauseControl() {
|
2023-01-08 15:37:16 +01:00
|
|
|
const { videoState } = useVideoPlayerState();
|
2023-01-08 13:15:32 +01:00
|
|
|
|
|
|
|
const handleClick = useCallback(() => {
|
2023-01-08 15:37:16 +01:00
|
|
|
if (videoState?.isPlaying) videoState.pause();
|
|
|
|
else videoState.play();
|
|
|
|
}, [videoState]);
|
2023-01-08 13:15:32 +01:00
|
|
|
|
|
|
|
let text = "paused";
|
2023-01-08 15:37:16 +01:00
|
|
|
if (videoState?.isPlaying) text = "playing";
|
2023-01-08 13:15:32 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<button type="button" onClick={handleClick}>
|
|
|
|
{text}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|