-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #481 from Rajgupta36/Feature_Video_Autoplay_on_Hover
Added Feature video autoplay on hover #480
- Loading branch information
Showing
4 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use server"; | ||
import db from '@/db'; | ||
|
||
export default async function VideoPreview({ contentId }: { contentId: number }) { | ||
const videoMetadata = await db.videoMetadata.findFirst({ | ||
where: { contentId }, | ||
select: { video_360p_1: true } | ||
}); | ||
|
||
if (videoMetadata) { | ||
return videoMetadata.video_360p_1; | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { useState } from 'react'; | ||
import VideoPreview from '@/actions/videopreview/videoPreview'; | ||
import { useEffect } from 'react'; | ||
|
||
const VideoThumbnail = ({ imageUrl, contentId }: { imageUrl: string , contentId: number }) => { | ||
const [videoUrl, setVideoUrl] = useState<string | null>(null); | ||
const [hover,setHover] = useState(false); | ||
|
||
useEffect(() => { | ||
async function fetchVideoUrl() { | ||
const url = await VideoPreview({ contentId }); | ||
setVideoUrl(url); | ||
} | ||
fetchVideoUrl(); | ||
}, [contentId]); | ||
const handleMouseEnter = () => { | ||
setHover(true); | ||
}; | ||
|
||
const handleMouseLeave = () => { | ||
setHover(false); | ||
}; | ||
return ( | ||
<div className="m max-h-[573px] max-w-[1053px] relative" onMouseEnter={handleMouseEnter} | ||
onMouseLeave={handleMouseLeave}> | ||
<div className=" w-full h-full relative"> | ||
{hover && videoUrl ? ( | ||
<div className='w-full h-full'> | ||
<video muted autoPlay width="100%" height="100%"> | ||
<source src={videoUrl} type="video/mp4"/> | ||
</video> | ||
</div> | ||
) : ( | ||
<img | ||
src={imageUrl} | ||
alt="Video Thumbnail" | ||
className=" w-full h-full object-cover" | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default VideoThumbnail; |