add
This commit is contained in:
parent
83bb5bb252
commit
74f3893f8c
|
@ -4,22 +4,25 @@ import { PauseIcon, PlayIcon } from "@heroicons/react/24/solid";
|
||||||
|
|
||||||
export default function Play() {
|
export default function Play() {
|
||||||
const { isPlaying, videoRef } = useContext(VideoPlayerContext);
|
const { isPlaying, videoRef } = useContext(VideoPlayerContext);
|
||||||
|
const handleClick = (event) => {
|
||||||
|
event.stopPropagation(); // 阻止事件冒泡
|
||||||
|
if (videoRef.current?.paused) {
|
||||||
|
videoRef.current.play();
|
||||||
|
} else {
|
||||||
|
videoRef.current?.pause();
|
||||||
|
}
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<button
|
<div
|
||||||
onClick={() =>
|
onClick={handleClick}
|
||||||
videoRef.current?.paused
|
|
||||||
? videoRef.current.play()
|
|
||||||
: videoRef.current?.pause()
|
|
||||||
}
|
|
||||||
className="text-white hover:text-primaryHover">
|
className="text-white hover:text-primaryHover">
|
||||||
{isPlaying ? (
|
{isPlaying ? (
|
||||||
<PauseIcon className="w-10 h-10" />
|
<PauseIcon className="w-10 h-10" />
|
||||||
) : (
|
) : (
|
||||||
<PlayIcon className="w-10 h-10" />
|
<PlayIcon className="w-10 h-10" />
|
||||||
)}
|
)}
|
||||||
</button>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue