Video Player
Minimalist custom video player with scrubber, playback toggle, volume control, and time counter.
ReactTailwind CSSLucide React
Dependencieslucide-react
npm install lucide-reactPreview
0:00 / 0:00
Source Code
video-player.tsxtsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"use client";
import React, { useState, useRef, useEffect } from "react";
import { Play, Pause, Volume2, VolumeX, Maximize2, RotateCcw } from "lucide-react";
export interface VideoPlayerProps {
src?: string;
poster?: string;
}
export function VideoPlayer({
src = "/service-total-revamp.webm",
}: VideoPlayerProps) {
const videoRef = useRef<HTMLVideoElement>(null);
const [isPlaying, setIsPlaying] = useState(false);
const [progress, setProgress] = useState(0);
const [isMuted, setIsMuted] = useState(true);
const togglePlay = () => {
if (!videoRef.current) return;
if (isPlaying) {
videoRef.current.pause();
setIsPlaying(false);
} else {
videoRef.current.play().catch(() => {});
setIsPlaying(true);
}
};
return (
<div className="relative w-full max-w-xl aspect-video rounded-2xl overflow-hidden bg-black border border-zinc-200 dark:border-zinc-800 shadow-xl group">
<video
ref={videoRef}
src={src}
muted={isMuted}
playsInline
onClick={togglePlay}
className="w-full h-full object-cover cursor-pointer"
/>
</div>
);
}Usage
usage.tsxtsx
1
<VideoPlayer src="/service-total-revamp.webm" />Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
| src | string | Optional | sample video | Direct URL of the video file (mp4, webm). |
Types
types.tstsx
1
2
3
4
export interface VideoPlayerProps {
src?: string;
poster?: string;
}