Adapt video previews for a better mobile experience
Adjust video preview delay and controls for mobile devices, and set preload to metadata for MP4 sources. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 074b0e4c-6171-43bd-aa98-f9e04623ca14 Replit-Commit-Checkpoint-Type: full_checkpoint
This commit is contained in:
parent
83a9abad01
commit
e7d66d289d
@ -50,9 +50,13 @@ export default function VideoCard({ video, onClick, className = "" }: VideoCardP
|
|||||||
// Delay preview start to avoid loading on quick mouse passes
|
// Delay preview start to avoid loading on quick mouse passes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isHovered) {
|
if (isHovered) {
|
||||||
|
// Shorter delay on mobile for better touch experience
|
||||||
|
const isMobile = window.innerWidth < 768;
|
||||||
|
const delay = isMobile ? 500 : 800; // 500ms on mobile, 800ms on desktop
|
||||||
|
|
||||||
hoverTimeoutRef.current = setTimeout(() => {
|
hoverTimeoutRef.current = setTimeout(() => {
|
||||||
setShowPreview(true);
|
setShowPreview(true);
|
||||||
}, 800); // Start preview after 800ms hover
|
}, delay);
|
||||||
} else {
|
} else {
|
||||||
if (hoverTimeoutRef.current) {
|
if (hoverTimeoutRef.current) {
|
||||||
clearTimeout(hoverTimeoutRef.current);
|
clearTimeout(hoverTimeoutRef.current);
|
||||||
@ -73,6 +77,8 @@ export default function VideoCard({ video, onClick, className = "" }: VideoCardP
|
|||||||
className={`video-card transition-transform duration-200 hover:scale-[1.02] p-3 ${className}`}
|
className={`video-card transition-transform duration-200 hover:scale-[1.02] p-3 ${className}`}
|
||||||
onMouseEnter={() => setIsHovered(true)}
|
onMouseEnter={() => setIsHovered(true)}
|
||||||
onMouseLeave={() => setIsHovered(false)}
|
onMouseLeave={() => setIsHovered(false)}
|
||||||
|
onTouchStart={() => setIsHovered(true)}
|
||||||
|
onTouchEnd={() => setIsHovered(false)}
|
||||||
>
|
>
|
||||||
{/* Video preview container */}
|
{/* Video preview container */}
|
||||||
<div
|
<div
|
||||||
@ -120,11 +126,16 @@ export default function VideoCard({ video, onClick, className = "" }: VideoCardP
|
|||||||
muted
|
muted
|
||||||
loop
|
loop
|
||||||
playsInline
|
playsInline
|
||||||
preload="none"
|
preload="metadata"
|
||||||
|
controls={false}
|
||||||
|
disablePictureInPicture
|
||||||
|
webkit-playsinline="true"
|
||||||
|
x5-playsinline="true"
|
||||||
onLoadStart={() => console.log('Preview loading for:', video.title)}
|
onLoadStart={() => console.log('Preview loading for:', video.title)}
|
||||||
onError={(e) => console.log('Preview failed for:', video.title)}
|
onError={(e) => console.log('Preview failed for:', video.title)}
|
||||||
|
onCanPlay={() => console.log('Preview ready for:', video.title)}
|
||||||
>
|
>
|
||||||
{/* Try MP4 source first for faster loading */}
|
{/* Try MP4 source first for faster loading on mobile */}
|
||||||
{video.mp4Url && (
|
{video.mp4Url && (
|
||||||
<source src={video.mp4Url} type="video/mp4" />
|
<source src={video.mp4Url} type="video/mp4" />
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user