mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 23:24:21 +00:00
fix(webui): show play button and darken tint only before initial playback (#425)
* fix(webui): remove paused play button overlay and darken cover from video players * fix(webui): show play button and darken tint only before initial playback
This commit is contained in:
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- **webui**: Only show the center play button and darkened tint on initial video open before playback starts; once played, pausing or scrubbing back to start keeps the video canvas clean and unobstructed for review
|
||||||
- **transcode**: Fix an issue where videos with orientation or rotation metadata (such as smartphone vertical videos) were incorrectly displayed with stretched aspect ratios in the video player
|
- **transcode**: Fix an issue where videos with orientation or rotation metadata (such as smartphone vertical videos) were incorrectly displayed with stretched aspect ratios in the video player
|
||||||
- **docker**: Fix an issue where the bundled PostgreSQL container published port 5432 on the host, causing deployment to fail on machines where that port was already in use; the database is now only reachable by Shumai itself
|
- **docker**: Fix an issue where the bundled PostgreSQL container published port 5432 on the host, causing deployment to fail on machines where that port was already in use; the database is now only reachable by Shumai itself
|
||||||
- **cli**: Only manage and check PID files in daemon mode, preventing stale PID files, crash-loop conflicts, or spurious process checks during normal foreground and Docker execution
|
- **cli**: Only manage and check PID files in daemon mode, preventing stale PID files, crash-loop conflicts, or spurious process checks during normal foreground and Docker execution
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
|||||||
const [pan, setPan] = useState<{ x: number; y: number } | null>(null)
|
const [pan, setPan] = useState<{ x: number; y: number } | null>(null)
|
||||||
|
|
||||||
const [isPlaying, setIsPlaying] = useState(false)
|
const [isPlaying, setIsPlaying] = useState(false)
|
||||||
|
const [hasStartedPlaying, setHasStartedPlaying] = useState(false)
|
||||||
const [isLooping, setIsLooping] = useState(false)
|
const [isLooping, setIsLooping] = useState(false)
|
||||||
const [playbackRate, setPlaybackRate] = useState(1)
|
const [playbackRate, setPlaybackRate] = useState(1)
|
||||||
const [buffered, setBuffered] = useState(0)
|
const [buffered, setBuffered] = useState(0)
|
||||||
@@ -163,6 +164,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
|||||||
setCurrentResolution(res?.resolution ?? '')
|
setCurrentResolution(res?.resolution ?? '')
|
||||||
setIsCurrentHdr(res?.hdr)
|
setIsCurrentHdr(res?.hdr)
|
||||||
currentSrcRef.current = res?.url
|
currentSrcRef.current = res?.url
|
||||||
|
setHasStartedPlaying(false)
|
||||||
}, [file.id])
|
}, [file.id])
|
||||||
|
|
||||||
// Initialize video.js
|
// Initialize video.js
|
||||||
@@ -195,6 +197,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
|||||||
|
|
||||||
player.on('play', () => {
|
player.on('play', () => {
|
||||||
setIsPlaying(true)
|
setIsPlaying(true)
|
||||||
|
setHasStartedPlaying(true)
|
||||||
onPlay?.()
|
onPlay?.()
|
||||||
})
|
})
|
||||||
player.on('pause', () => setIsPlaying(false))
|
player.on('pause', () => setIsPlaying(false))
|
||||||
@@ -365,12 +368,19 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
|||||||
player.pause()
|
player.pause()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
seekToFrame: (frame) => seekToFrame(clampFrame(frame)),
|
seekToFrame: (frame) => {
|
||||||
|
setHasStartedPlaying(true)
|
||||||
|
return seekToFrame(clampFrame(frame))
|
||||||
|
},
|
||||||
seekToSecond: (second) => {
|
seekToSecond: (second) => {
|
||||||
|
setHasStartedPlaying(true)
|
||||||
const frame = Math.floor(second * frameRate + 0.45)
|
const frame = Math.floor(second * frameRate + 0.45)
|
||||||
seekToFrame(clampFrame(frame))
|
seekToFrame(clampFrame(frame))
|
||||||
},
|
},
|
||||||
stepFrame: (delta) => seekToFrame(clampFrame(currentFrameRef.current + delta)),
|
stepFrame: (delta) => {
|
||||||
|
setHasStartedPlaying(true)
|
||||||
|
return seekToFrame(clampFrame(currentFrameRef.current + delta))
|
||||||
|
},
|
||||||
setMuted: (m) => playerRef.current?.muted(m),
|
setMuted: (m) => playerRef.current?.muted(m),
|
||||||
setVolume: (v) => {
|
setVolume: (v) => {
|
||||||
const player = playerRef.current
|
const player = playerRef.current
|
||||||
@@ -502,8 +512,8 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isPlaying && !isDrawing && (
|
{!hasStartedPlaying && !isDrawing && (
|
||||||
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-black/20">
|
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-black/20 transition-opacity duration-200">
|
||||||
<div className="flex h-16 w-16 items-center justify-center rounded-full border-2 border-white/30 bg-white/10 backdrop-blur-sm">
|
<div className="flex h-16 w-16 items-center justify-center rounded-full border-2 border-white/30 bg-white/10 backdrop-blur-sm">
|
||||||
<Play className="ml-1 h-8 w-8 fill-white text-white" />
|
<Play className="ml-1 h-8 w-8 fill-white text-white" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// @vitest-environment happy-dom
|
// @vitest-environment happy-dom
|
||||||
import { cleanup, render } from '@testing-library/react'
|
import { act, cleanup, render } from '@testing-library/react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import VideoViewer from './video-viewer'
|
import VideoViewer from './video-viewer'
|
||||||
@@ -304,4 +304,69 @@ describe('VideoViewer', () => {
|
|||||||
|
|
||||||
window.matchMedia = originalMatchMedia
|
window.matchMedia = originalMatchMedia
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('shows play button and darkened overlay initially, but never again after playing (even when paused or scrubbed back to start)', () => {
|
||||||
|
const listeners: Record<string, () => void> = {}
|
||||||
|
videojsMock.mockImplementation(() => ({
|
||||||
|
on: vi.fn((event: string, cb: () => void) => {
|
||||||
|
listeners[event] = cb
|
||||||
|
}),
|
||||||
|
volume: vi.fn(),
|
||||||
|
duration: vi.fn(() => 10),
|
||||||
|
currentTime: vi.fn(() => 0),
|
||||||
|
bufferedEnd: vi.fn(() => 0),
|
||||||
|
playbackRate: vi.fn(() => 1),
|
||||||
|
ready: vi.fn(),
|
||||||
|
dispose: vi.fn(),
|
||||||
|
isDisposed: vi.fn(() => false),
|
||||||
|
}))
|
||||||
|
|
||||||
|
const testVideo: AssetInfo = {
|
||||||
|
id: 'test-video-lifecycle',
|
||||||
|
name: 'test.mp4',
|
||||||
|
proxyType: 'video',
|
||||||
|
media: {
|
||||||
|
metadata: {
|
||||||
|
originalWidth: 1920,
|
||||||
|
originalHeight: 1080,
|
||||||
|
duration: 10,
|
||||||
|
frameRate: 30,
|
||||||
|
totalFrames: 300,
|
||||||
|
},
|
||||||
|
videoTranscodes: [
|
||||||
|
{
|
||||||
|
resolution: '1080p',
|
||||||
|
url: 'https://cdn.example.com/test-1080p.mp4',
|
||||||
|
width: 1920,
|
||||||
|
height: 1080,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
} as unknown as AssetInfo
|
||||||
|
|
||||||
|
const { container } = render(<VideoViewer file={testVideo} />)
|
||||||
|
const videoArea = container.querySelector('[data-testid="video-area"]')
|
||||||
|
expect(videoArea).toBeTruthy()
|
||||||
|
|
||||||
|
// 1. Initially (before playing): play button & 20% black tint are present
|
||||||
|
expect(videoArea?.querySelector('.bg-black\\/20')).not.toBeNull()
|
||||||
|
|
||||||
|
// 2. Start playback
|
||||||
|
act(() => {
|
||||||
|
listeners['play']?.()
|
||||||
|
})
|
||||||
|
expect(videoArea?.querySelector('.bg-black\\/20')).toBeNull()
|
||||||
|
|
||||||
|
// 3. Pause video: overlay must NOT show again
|
||||||
|
act(() => {
|
||||||
|
listeners['pause']?.()
|
||||||
|
})
|
||||||
|
expect(videoArea?.querySelector('.bg-black\\/20')).toBeNull()
|
||||||
|
|
||||||
|
// 4. Drag seekbar / time back to 0: overlay must STILL NOT show
|
||||||
|
act(() => {
|
||||||
|
listeners['timeupdate']?.()
|
||||||
|
})
|
||||||
|
expect(videoArea?.querySelector('.bg-black\\/20')).toBeNull()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
currentSrc: initialRes?.url ?? '',
|
currentSrc: initialRes?.url ?? '',
|
||||||
isCurrentHdr: initialRes?.hdr ?? false,
|
isCurrentHdr: initialRes?.hdr ?? false,
|
||||||
})
|
})
|
||||||
|
const [hasStartedPlaying, setHasStartedPlaying] = useState(false)
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
const containerRef = useRef<HTMLDivElement>(null)
|
||||||
const rootRef = useRef<HTMLDivElement>(null)
|
const rootRef = useRef<HTMLDivElement>(null)
|
||||||
const controlsTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
const controlsTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||||
@@ -124,6 +125,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
seekTo: (second: number) => {
|
seekTo: (second: number) => {
|
||||||
|
setHasStartedPlaying(true)
|
||||||
if (localPlayerRef.current) {
|
if (localPlayerRef.current) {
|
||||||
localPlayerRef.current.currentTime(second)
|
localPlayerRef.current.currentTime(second)
|
||||||
}
|
}
|
||||||
@@ -160,6 +162,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
setIsPlayerReady(false)
|
setIsPlayerReady(false)
|
||||||
setBuffered(0)
|
setBuffered(0)
|
||||||
lastProcessedStartTimeRef.current = null
|
lastProcessedStartTimeRef.current = null
|
||||||
|
setHasStartedPlaying(false)
|
||||||
}, [data.id, Boolean(initialRes?.url)])
|
}, [data.id, Boolean(initialRes?.url)])
|
||||||
|
|
||||||
const vidW = data.media?.metadata?.originalWidth || 1920
|
const vidW = data.media?.metadata?.originalWidth || 1920
|
||||||
@@ -261,6 +264,14 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
|
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
|
||||||
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames, isAudio)
|
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames, isAudio)
|
||||||
|
|
||||||
|
const handleSeekToFrame = useCallback(
|
||||||
|
(frame: number) => {
|
||||||
|
setHasStartedPlaying(true)
|
||||||
|
return seekToFrame(frame)
|
||||||
|
},
|
||||||
|
[seekToFrame],
|
||||||
|
)
|
||||||
|
|
||||||
const currentTime = currentFrame / frameRate
|
const currentTime = currentFrame / frameRate
|
||||||
const duration = totalFrames / frameRate
|
const duration = totalFrames / frameRate
|
||||||
const progress = duration > 0 ? (currentTime / duration) * 100 : 0
|
const progress = duration > 0 ? (currentTime / duration) * 100 : 0
|
||||||
@@ -362,6 +373,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
|
|
||||||
player.on('play', () => {
|
player.on('play', () => {
|
||||||
setState((p) => ({ ...p, isPlaying: true }))
|
setState((p) => ({ ...p, isPlaying: true }))
|
||||||
|
setHasStartedPlaying(true)
|
||||||
onPlay?.()
|
onPlay?.()
|
||||||
})
|
})
|
||||||
player.on('pause', () => {
|
player.on('pause', () => {
|
||||||
@@ -427,6 +439,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
if (startTime !== lastProcessedStartTimeRef.current) {
|
if (startTime !== lastProcessedStartTimeRef.current) {
|
||||||
lastProcessedStartTimeRef.current = startTime
|
lastProcessedStartTimeRef.current = startTime
|
||||||
const targetFrame = Math.floor(startTime * frameRate + 0.45)
|
const targetFrame = Math.floor(startTime * frameRate + 0.45)
|
||||||
|
setHasStartedPlaying(true)
|
||||||
seekToFrame(targetFrame)
|
seekToFrame(targetFrame)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -834,10 +847,10 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Big Play Button Overlay (when paused) */}
|
{/* Initial Big Play Button Overlay (shown only before playback starts) */}
|
||||||
{!state.isPlaying && !isDrawing && (
|
{!hasStartedPlaying && !isDrawing && (
|
||||||
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10">
|
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10 transition-opacity duration-200">
|
||||||
<div className="w-20 h-20 bg-white/10 backdrop-blur-sm rounded-full flex items-center justify-center border-2 border-white/30 animate-pulse">
|
<div className="w-20 h-20 bg-white/10 backdrop-blur-sm rounded-full flex items-center justify-center border-2 border-white/30">
|
||||||
<Play className="w-10 h-10 text-white ml-1 fill-white" />
|
<Play className="w-10 h-10 text-white ml-1 fill-white" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -866,7 +879,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
frameRate={frameRate}
|
frameRate={frameRate}
|
||||||
totalFrames={totalFrames}
|
totalFrames={totalFrames}
|
||||||
currentFrame={currentFrame}
|
currentFrame={currentFrame}
|
||||||
seekToFrame={seekToFrame}
|
seekToFrame={handleSeekToFrame}
|
||||||
onMouseEnter={handleControlsMouseEnter}
|
onMouseEnter={handleControlsMouseEnter}
|
||||||
onMouseLeave={handleControlsMouseLeave}
|
onMouseLeave={handleControlsMouseLeave}
|
||||||
allowDownload={allowDownload}
|
allowDownload={allowDownload}
|
||||||
@@ -892,7 +905,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
frameRate={frameRate}
|
frameRate={frameRate}
|
||||||
totalFrames={totalFrames}
|
totalFrames={totalFrames}
|
||||||
currentFrame={currentFrame}
|
currentFrame={currentFrame}
|
||||||
seekToFrame={seekToFrame}
|
seekToFrame={handleSeekToFrame}
|
||||||
onMouseEnter={handleControlsMouseEnter}
|
onMouseEnter={handleControlsMouseEnter}
|
||||||
onMouseLeave={handleControlsMouseLeave}
|
onMouseLeave={handleControlsMouseLeave}
|
||||||
allowDownload={allowDownload}
|
allowDownload={allowDownload}
|
||||||
|
|||||||
Reference in New Issue
Block a user