A simple React video player app with subtitle support, built using plyr-react and NextUI.
- Play any video by URL (MP4 format recommended)
- Upload and display subtitles (
.srtor.vttfiles) - Modern UI with TailwindCSS and NextUI
- Customizable controls (play, pause, volume, captions, fullscreen, etc.)
- Persian (Farsi) UI labels for player controls
-
Video Input:
Enter the URL of your video in the input box. The player will load and display the video. -
Subtitle Upload:
Click the "فایل زیر نویس" button to select a subtitle file (.srtor.vtt). The subtitle will be loaded and shown on the video. -
Play/Pause Button:
Use the "پخش/توقف" button to play or pause the video. The button label changes based on the current state. -
Player Controls:
The player includes controls for play, pause, progress, current time, mute, volume, captions, settings, picture-in-picture, and fullscreen.
- React (with hooks)
- plyr-react for the video player
- NextUI for buttons
- TailwindCSS for styling
src/App.tsx— Main React component containing all logic and UI
const [video, setVideo] = useState("");
const [isPlaying, setIsPlaying] = useState(false);
const playerRef = useRef<any>(null);
const [subtitle, setSubtitle] = useState("");
const fileInputRef = useRef<HTMLInputElement>(null);const videoSrc = {
type: "video",
sources: [{ src: video, type: "video/mp4" }],
tracks: subtitle
? [
{
kind: "subtitles",
label: "زیرنویس",
src: subtitle,
srclang: "fa",
},
]
: [],
};<Plyr
ref={playerRef}
source={videoSrc}
options={{
autoplay: false,
controls: [
"play-large",
"play",
"progress",
"current-time",
"mute",
"volume",
"captions",
"settings",
"pip",
"fullscreen",
],
settings: ["captions"],
i18n: {
// Persian labels for controls
},
}}
/><Button
onPress={() => {
const plyrInstance = playerRef.current?.plyr;
if (plyrInstance) {
if (isPlaying) {
plyrInstance.pause();
} else {
plyrInstance.play();
}
setIsPlaying(!isPlaying);
}
}}
>
<p>{isPlaying ? "توقف" : "پخش"}</p>
</Button>To apply rounded corners to the player, add this to your global CSS:
.plyr--video,
.plyr__video-wrapper,
.plyr__poster {
border-radius: 0.5rem !important;
overflow: hidden;
}-
If you see an error about
prop-typesnot found:
Runnpm install prop-typesin your project directory. -
If the play/pause button doesn't work:
Make sure you are using the correct ref and accessing the Plyr instance as shown above.
MIT
