How to create Video Player in ReactJS ?
Last Updated :
26 Jul, 2024
We are going to learn how we can create a Video Player in React JS. A video player is a kind of media player for playing back digital video data. React is a free and open-source front-end JavaScript library for building user interfaces or UI components.
Prerequisite:
Approach to create Video Player:
To create our video player we are going to use the react-loading package because it is powerful, lightweight, and fully customizable. After that, we will add our video player to our homepage using the installed package. Subsequently, we'll integrate our video player onto our homepage using this installed package.
Steps to Create React Application:
Step 1: Create a react project folder and install locally by npm i create-react-app.
npm create-react-app project
Step 2: After creating your project folder, move to it by using the following command.
cd project
Step 3: Install the required package
npm i react-video-js-player
Project Structure:

The updated dependencies in package.json file will look like:
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"react-video-js-player": "^1.1.1",
"web-vitals": "^2.1.4",
}
Example: In the below example first, we are importing the VideoPlayer component from the react-video-js-player package. After that, we are creating our onPlayerReady and state function. Then we are adding our Video Player using the VideoPlayer component of the installed package. Now add the below code in the App.js file to create the video player.
JavaScript
import React, { Component } from 'react';
import VideoPlayer from 'react-video-js-player';
class VideoApp extends Component {
player = {}
state = {
video: {
src: "/video.mp4",
poster: "/1.png"
}
}
onPlayerReady(player) {
this.player = player;
}
render() {
return (
<div>
<VideoPlayer
controls={true}
src={this.state.video.src}
poster={this.state.video.poster}
width="720"
height="420"
onReady={this.onPlayerReady.bind(this)}
/>
</div>
);
}
}
export default VideoApp;
Steps to Run the application: Run the below command in the terminal to run the app.
npm start
Output:
Similar Reads
How to Play/Pause video or Audio in ReactJS ? Adding multimedia elements, such as videos and audios, to your ReactJS applications can enhance the overall user experience. One common requirement is to provide controls for playing and pausing these media files. In this article, we'll explore how to implement play/pause functionality for videos an
3 min read
How to create Image Slider in ReactJS ? Image Slider is a dynamic web element that displays a collection of images and has a slider to switch between the Images. It is the most common feature to show image collection in web applications or mobile apps.Websites like Amazon.com, Flipkart.com, and many e-commerce sites use image sliders to s
4 min read
How to use Popper Component in ReactJS ? A Popper is used to show the part of the content on top of another. It's an alternative feature for react-popper. Material UI for React has this component available for us, and it is simple and very easy to integrate. For perfect positioning, it uses 3rd party library which is Popper.js.Prerequisite
3 min read
How to create Loading Screen in ReactJS ? Loading screen plays a major role in enhancing UX development. In this article, we are going to learn how we can create a Loading Screen in ReactJs. A loading screen is a picture shown by a computer program, often a video game, while the program is loading or initializing.PrerequisitesJavaScript and
2 min read
Create a Video Player App using React-Native React-Native is an open-source JavaScript framework used to broaden cross-platform packages i.e., you may write code in React-Native and publish it as an Android or IOS app. In this article, we will build a Video Player app with the usage of React-Native. The app will run on both Android and IOS.Pre
4 min read