mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 07:29:07 +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
|
||||
|
||||
- **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
|
||||
- **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
|
||||
|
||||
@@ -103,6 +103,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
const [pan, setPan] = useState<{ x: number; y: number } | null>(null)
|
||||
|
||||
const [isPlaying, setIsPlaying] = useState(false)
|
||||
const [hasStartedPlaying, setHasStartedPlaying] = useState(false)
|
||||
const [isLooping, setIsLooping] = useState(false)
|
||||
const [playbackRate, setPlaybackRate] = useState(1)
|
||||
const [buffered, setBuffered] = useState(0)
|
||||
@@ -163,6 +164,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
setCurrentResolution(res?.resolution ?? '')
|
||||
setIsCurrentHdr(res?.hdr)
|
||||
currentSrcRef.current = res?.url
|
||||
setHasStartedPlaying(false)
|
||||
}, [file.id])
|
||||
|
||||
// Initialize video.js
|
||||
@@ -195,6 +197,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
|
||||
player.on('play', () => {
|
||||
setIsPlaying(true)
|
||||
setHasStartedPlaying(true)
|
||||
onPlay?.()
|
||||
})
|
||||
player.on('pause', () => setIsPlaying(false))
|
||||
@@ -365,12 +368,19 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
player.pause()
|
||||
}
|
||||
},
|
||||
seekToFrame: (frame) => seekToFrame(clampFrame(frame)),
|
||||
seekToFrame: (frame) => {
|
||||
setHasStartedPlaying(true)
|
||||
return seekToFrame(clampFrame(frame))
|
||||
},
|
||||
seekToSecond: (second) => {
|
||||
setHasStartedPlaying(true)
|
||||
const frame = Math.floor(second * frameRate + 0.45)
|
||||
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),
|
||||
setVolume: (v) => {
|
||||
const player = playerRef.current
|
||||
@@ -502,8 +512,8 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
)
|
||||
)}
|
||||
|
||||
{!isPlaying && !isDrawing && (
|
||||
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-black/20">
|
||||
{!hasStartedPlaying && !isDrawing && (
|
||||
<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">
|
||||
<Play className="ml-1 h-8 w-8 fill-white text-white" />
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { cleanup, render } from '@testing-library/react'
|
||||
import { act, cleanup, render } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import VideoViewer from './video-viewer'
|
||||
@@ -304,4 +304,69 @@ describe('VideoViewer', () => {
|
||||
|
||||
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 ?? '',
|
||||
isCurrentHdr: initialRes?.hdr ?? false,
|
||||
})
|
||||
const [hasStartedPlaying, setHasStartedPlaying] = useState(false)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const rootRef = useRef<HTMLDivElement>(null)
|
||||
const controlsTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
@@ -124,6 +125,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
}
|
||||
},
|
||||
seekTo: (second: number) => {
|
||||
setHasStartedPlaying(true)
|
||||
if (localPlayerRef.current) {
|
||||
localPlayerRef.current.currentTime(second)
|
||||
}
|
||||
@@ -160,6 +162,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
setIsPlayerReady(false)
|
||||
setBuffered(0)
|
||||
lastProcessedStartTimeRef.current = null
|
||||
setHasStartedPlaying(false)
|
||||
}, [data.id, Boolean(initialRes?.url)])
|
||||
|
||||
const vidW = data.media?.metadata?.originalWidth || 1920
|
||||
@@ -261,6 +264,14 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
|
||||
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames, isAudio)
|
||||
|
||||
const handleSeekToFrame = useCallback(
|
||||
(frame: number) => {
|
||||
setHasStartedPlaying(true)
|
||||
return seekToFrame(frame)
|
||||
},
|
||||
[seekToFrame],
|
||||
)
|
||||
|
||||
const currentTime = currentFrame / frameRate
|
||||
const duration = totalFrames / frameRate
|
||||
const progress = duration > 0 ? (currentTime / duration) * 100 : 0
|
||||
@@ -362,6 +373,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
|
||||
player.on('play', () => {
|
||||
setState((p) => ({ ...p, isPlaying: true }))
|
||||
setHasStartedPlaying(true)
|
||||
onPlay?.()
|
||||
})
|
||||
player.on('pause', () => {
|
||||
@@ -427,6 +439,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
if (startTime !== lastProcessedStartTimeRef.current) {
|
||||
lastProcessedStartTimeRef.current = startTime
|
||||
const targetFrame = Math.floor(startTime * frameRate + 0.45)
|
||||
setHasStartedPlaying(true)
|
||||
seekToFrame(targetFrame)
|
||||
}
|
||||
}
|
||||
@@ -834,10 +847,10 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
)
|
||||
)}
|
||||
|
||||
{/* Big Play Button Overlay (when paused) */}
|
||||
{!state.isPlaying && !isDrawing && (
|
||||
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10">
|
||||
<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">
|
||||
{/* Initial Big Play Button Overlay (shown only before playback starts) */}
|
||||
{!hasStartedPlaying && !isDrawing && (
|
||||
<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">
|
||||
<Play className="w-10 h-10 text-white ml-1 fill-white" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -866,7 +879,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
frameRate={frameRate}
|
||||
totalFrames={totalFrames}
|
||||
currentFrame={currentFrame}
|
||||
seekToFrame={seekToFrame}
|
||||
seekToFrame={handleSeekToFrame}
|
||||
onMouseEnter={handleControlsMouseEnter}
|
||||
onMouseLeave={handleControlsMouseLeave}
|
||||
allowDownload={allowDownload}
|
||||
@@ -892,7 +905,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
frameRate={frameRate}
|
||||
totalFrames={totalFrames}
|
||||
currentFrame={currentFrame}
|
||||
seekToFrame={seekToFrame}
|
||||
seekToFrame={handleSeekToFrame}
|
||||
onMouseEnter={handleControlsMouseEnter}
|
||||
onMouseLeave={handleControlsMouseLeave}
|
||||
allowDownload={allowDownload}
|
||||
|
||||
Reference in New Issue
Block a user