How to add Video Player in Next.js ?
Last Updated :
25 Jul, 2024
Adding a video player in a Next.js application enhances the user experience by enabling video playback. The react-player
library simplifies integrating various video sources such as YouTube, Vimeo, and local files. In this article, we are going to learn how we can add Video Player in NextJS.
Approach
To add a Video Player in Next.js, we will use the react-player
package. This package allows us to easily embed a video player anywhere in our app. First, install the react-player
package using npm install react-player
. Then, import and use the ReactPlayer
component on your homepage to add a video player.
Steps to Create NextJS App
Step 1: Initialize a new Next.js project using the below command:
npx create-next-app gfg
Step 2: Install the required package:
Now we will install the react-player package using the below command:
npm i react-player
Project Structure: It will look like this.

The updated dependencies in the package.json file are:
"dependencies": {
"next": "14.2.4",
"react": "^18",
"react-dom": "^18",
"react-player": "^2.16.0",
}
Example: This example demonstrates add a video player in the next.js application with the help of react-play npm package.
JavaScript
// Filename - index.js
import React from 'react'
import ReactPlayer from 'react-player'
export default function VideoPlayer(){
return (
<div>
<h2>NextJs VideoPlayer - GeeksforGeeks</h2>
<ReactPlayer url='https://www.youtube.com/watch?v=wWgIAphfn2U' />
</div>
)
}
Explanation: In the above example first, we are importing our ReactPlayer component from the installed package. After that, we are using the ReactPlayer component inside a new function. We can enter the link of the video that we want to play.
Steps to run the application: Run the below command in the terminal to run the app.
npm run dev
Output:
Similar Reads
How to add Web Share in Next.js ? The Web Share API enables web applications to share content (like URLs, text, or files) to other apps installed on a user's device, such as social media platforms, messaging apps, or email clients. Integrating the Web Share API into a Next.js project enhances user experience by providing a seamless
2 min read
How to add Youtube Videos in Next.js ? In this article, we are going to learn how we can add Youtube Video in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components condit
2 min read
How to Add Tweets in Next.js ? Adding tweets in Next.js involves using Twitter's embed feature or API to display tweets. You can embed tweets directly in components or fetch and display them using server-side rendering or client-side data fetching. In this article, we are going to learn how we can add Tweets in NextJs.ApproachTo
2 min read
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 Video Player in ReactJS ? 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:React JSPhases of JavaScript Event
2 min read