Skip to content

Commit

Permalink
reduce flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Sep 3, 2024
1 parent a2d7961 commit 67cecb3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/renderer/src/MediaSourcePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,15 @@ function MediaSourcePlayer({ rotate, filePath, playerTime, videoStream, audioStr
return () => undefined;
}

const onCanPlay = () => setLoading(false);
const clearCanvas = () => {
if (canvasRef.current == null) return;
canvasRef.current.getContext('2d')?.clearRect(0, 0, canvasRef.current.width, canvasRef.current.height);
};

const onCanPlay = () => {
clearCanvas();
setLoading(false);
};
const getTargetTime = () => masterVideoRef.current!.currentTime - debouncedState.startTime;

const abortController = new AbortController();
Expand Down Expand Up @@ -347,9 +355,11 @@ function MediaSourcePlayer({ rotate, filePath, playerTime, videoStream, audioStr
const { videoStyle, canvasStyle } = useMemo(() => {
const sharedStyle: CSSProperties = { position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, display: 'block', width: '100%', height: '100%', objectFit: 'contain', transform: rotate ? `rotate(${rotate}deg)` : undefined };

const shouldShowCanvas = !debouncedState.playing;

return {
videoStyle: { ...sharedStyle, visibility: loading || !debouncedState.playing ? 'hidden' : undefined },
canvasStyle: { ...sharedStyle, visibility: loading || debouncedState.playing ? 'hidden' : undefined },
canvasStyle: { ...sharedStyle, visibility: shouldShowCanvas ? undefined : 'hidden' },
} as { videoStyle: CSSProperties, canvasStyle: CSSProperties };
}, [loading, debouncedState.playing, rotate]);

Expand Down

0 comments on commit 67cecb3

Please sign in to comment.