Sun Mar 8 08:27:26 AM CST 2026
This commit is contained in:
@@ -12,7 +12,7 @@ import { getCurrentIndex } from "./subtitleParser";
|
||||
|
||||
export default function SRTPlayerPage() {
|
||||
const videoRef = useRef<HTMLVideoElement>(null);
|
||||
const { setVideoRef, currentSrc, loadVideo, loaded, getCurrentTime, getDuration, play, setOnTimeUpdate } = useVideoStore();
|
||||
const { setVideoRef, pause, currentSrc, isPlaying, loadVideo, loaded, getCurrentTime, getDuration, play, setOnTimeUpdate } = useVideoStore();
|
||||
const {
|
||||
uploadVideo,
|
||||
uploadSubtitle,
|
||||
@@ -81,7 +81,9 @@ export default function SRTPlayerPage() {
|
||||
/* 控制面板 */
|
||||
sub.length > 0 && loaded &&
|
||||
<HStack gap={2} className="mx-auto mt-4 w-[85%]" justify={"center"} wrap>
|
||||
<LightButton onClick={play}>play</LightButton>
|
||||
{isPlaying() ?
|
||||
LightButton({ children: "pause", onClick: () => pause() }) :
|
||||
LightButton({ children: "play", onClick: () => play() })}
|
||||
<LightButton>previous</LightButton>
|
||||
<LightButton>next</LightButton>
|
||||
<LightButton>restart</LightButton>
|
||||
|
||||
@@ -16,6 +16,7 @@ interface VideoStore {
|
||||
setVolume: (vol: number) => void;
|
||||
getCurrentTime: () => number | undefined;
|
||||
getDuration: () => number | undefined;
|
||||
isPlaying: () => boolean;
|
||||
}
|
||||
|
||||
export const useVideoStore = create<VideoStore>()(
|
||||
@@ -102,5 +103,10 @@ export const useVideoStore = create<VideoStore>()(
|
||||
},
|
||||
getCurrentTime: () => get().videoRef?.current?.currentTime,
|
||||
getDuration: () => get().videoRef?.current?.duration,
|
||||
isPlaying: () => {
|
||||
const video = get().videoRef?.current;
|
||||
if (!video) return false;
|
||||
return !video.paused && !video.ended && video.readyState > 2;
|
||||
}
|
||||
}))
|
||||
);
|
||||
Reference in New Issue
Block a user