mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 14:04:50 +00:00
fix(webui): immediately use currentTime fallback in useFramePlayer for audio files
This commit is contained in:
@@ -118,7 +118,8 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
|||||||
const [currentResolution, setCurrentResolution] = useState(initialRes?.resolution ?? 'Original')
|
const [currentResolution, setCurrentResolution] = useState(initialRes?.resolution ?? 'Original')
|
||||||
const currentSrcRef = useRef(initialRes?.url)
|
const currentSrcRef = useRef(initialRes?.url)
|
||||||
|
|
||||||
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames)
|
const isAudio = file.mediaType?.startsWith('audio/')
|
||||||
|
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames, isAudio)
|
||||||
|
|
||||||
const zoomRef = useRef(zoom)
|
const zoomRef = useRef(zoom)
|
||||||
zoomRef.current = zoom
|
zoomRef.current = zoom
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export function useFramePlayer(
|
|||||||
videoRef: React.RefObject<HTMLVideoElement | null>,
|
videoRef: React.RefObject<HTMLVideoElement | null>,
|
||||||
frameRate: number,
|
frameRate: number,
|
||||||
totalFrames: number,
|
totalFrames: number,
|
||||||
|
isAudio?: boolean,
|
||||||
): UseFramePlayerResult {
|
): UseFramePlayerResult {
|
||||||
const [currentFrame, setCurrentFrame] = useState<number>(0)
|
const [currentFrame, setCurrentFrame] = useState<number>(0)
|
||||||
const isSeekingRef = useRef<boolean>(false)
|
const isSeekingRef = useRef<boolean>(false)
|
||||||
@@ -113,7 +114,7 @@ export function useFramePlayer(
|
|||||||
const rVfcStalledAfterDelivery = hasDeliveredVfc && sinceLastVfc > stallThreshold
|
const rVfcStalledAfterDelivery = hasDeliveredVfc && sinceLastVfc > stallThreshold
|
||||||
const rVfcNeverDelivered = !hasDeliveredVfc && sinceLastVfc > INITIAL_VFC_GRACE_MS
|
const rVfcNeverDelivered = !hasDeliveredVfc && sinceLastVfc > INITIAL_VFC_GRACE_MS
|
||||||
const useCurrentTimeFallback =
|
const useCurrentTimeFallback =
|
||||||
!rVfcSupported || rVfcStalledAfterDelivery || rVfcNeverDelivered
|
isAudio || !rVfcSupported || rVfcStalledAfterDelivery || rVfcNeverDelivered
|
||||||
|
|
||||||
if (useCurrentTimeFallback) {
|
if (useCurrentTimeFallback) {
|
||||||
const frame = Math.floor(video.currentTime * frameRate + 0.45)
|
const frame = Math.floor(video.currentTime * frameRate + 0.45)
|
||||||
|
|||||||
@@ -194,8 +194,9 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
const dbTotalFrames = metadata?.totalFrames || 0
|
const dbTotalFrames = metadata?.totalFrames || 0
|
||||||
const containerDuration = metadata?.duration || 0
|
const containerDuration = metadata?.duration || 0
|
||||||
|
|
||||||
|
const isAudio = data.mediaType?.startsWith('audio/')
|
||||||
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
|
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
|
||||||
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames)
|
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames, isAudio)
|
||||||
|
|
||||||
const currentTime = currentFrame / frameRate
|
const currentTime = currentFrame / frameRate
|
||||||
const duration = totalFrames / frameRate
|
const duration = totalFrames / frameRate
|
||||||
|
|||||||
Reference in New Issue
Block a user