Skip to content

Commit

Permalink
fix(style): add thumbnail for video preview (RSSNext#632)
Browse files Browse the repository at this point in the history
* style: fix the FloatMutedButton mispositioning

* feat: add thumbnail

Signed-off-by: Innei <i@innei.in>

---------

Signed-off-by: Innei <i@innei.in>
Co-authored-by: Innei <i@innei.in>
  • Loading branch information
zhangmo8 and Innei authored Sep 25, 2024
1 parent ae05f1d commit afecb71
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions apps/renderer/src/components/ui/media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const failedList = new Set<string | undefined>()
type BaseProps = {
mediaContainerClassName?: string
showFallback?: boolean
thumbnail?: boolean
}
export type MediaProps = BaseProps &
(
Expand Down Expand Up @@ -45,6 +46,7 @@ const MediaImpl: FC<MediaProps> = ({
proxy,
popper = false,
mediaContainerClassName,
thumbnail,
...props
}) => {
const { src, style, type, previewImageUrl, showFallback, ...rest } = props
Expand Down Expand Up @@ -133,7 +135,7 @@ const MediaImpl: FC<MediaProps> = ({
)}
onClick={handleClick}
>
<VideoPreview src={src!} previewImageUrl={previewImageUrl} />
<VideoPreview src={src!} previewImageUrl={previewImageUrl} thumbnail={thumbnail} />
</span>
)
}
Expand Down Expand Up @@ -222,14 +224,16 @@ const FallbackMedia: FC<MediaProps> = ({ type, mediaContainerClassName, classNam
const VideoPreview: FC<{
src: string
previewImageUrl?: string
}> = ({ src, previewImageUrl }) => {
thumbnail?: boolean
}> = ({ src, previewImageUrl, thumbnail = false }) => {
const [isInitVideoPlayer, setIsInitVideoPlayer] = useState(!previewImageUrl)

const [videoRef, setVideoRef] = useState<VideoPlayerRef | null>(null)
const isPaused = videoRef ? videoRef?.getState().paused : true
const [forceUpdate] = useForceUpdate()
return (
<div
className="size-full"
onMouseEnter={() => {
videoRef?.controls.play()?.then(forceUpdate)
}}
Expand All @@ -248,7 +252,7 @@ const VideoPreview: FC<{
/>
) : (
<VideoPlayer
variant="preview"
variant={thumbnail ? "thumbnail" : "preview"}
controls={false}
src={src}
ref={setVideoRef}
Expand Down
4 changes: 2 additions & 2 deletions apps/renderer/src/components/ui/media/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { VolumeSlider } from "./VolumeSlider"
type VideoPlayerProps = {
src: string

variant?: "preview" | "player"
variant?: "preview" | "player" | "thumbnail"
} & React.VideoHTMLAttributes<HTMLVideoElement> &
PropsWithChildren
export type VideoPlayerRef = {
Expand All @@ -58,7 +58,7 @@ interface VideoPlayerContextValue {
controls: VideoPlayerRef["controls"]
wrapperRef: React.RefObject<HTMLDivElement>
src: string
variant: "preview" | "player"
variant: "preview" | "player" | "thumbnail"
}
const VideoPlayerContext = createContext<VideoPlayerContextValue>(null!)
export const VideoPlayer = forwardRef<VideoPlayerRef, VideoPlayerProps>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export function ListItem({

{withDetails && entry.entries.media?.[0] && (
<Media
thumbnail
src={entry.entries.media[0].url}
type={entry.entries.media[0].type}
previewImageUrl={entry.entries.media[0].preview_image_url}
Expand Down

0 comments on commit afecb71

Please sign in to comment.