Design Converter
Education
Frontend Engineer
Last updated on Jan 2, 2025
Last updated on Nov 6, 2023
Next Video is a React component that allows you to add videos to your Next.js applications easily. It extends both the <video>
element and your Next.js app with features for automatic video optimization. Support app router, too.
1import Video from 'next-video'; 2import myVideo from '/videos/my-video.mp4'; 3 4export default function Page() { 5 return <Video src={myVideo} />; 6} 7
Navigate to your Next.js app directory and install the next-video using your preferred package manager.
1# Using NPM 2npm install next-video 3 4# Using Yarn 5yarn add next-video 6 7# Using pnpm 8pnpm add next-video 9
1npx next-video init 2
This command will:
By default, next-video uses Mux for video storage and optimization. To use Mux, sign up for an account, create an access token, and add the following environment variables to your .env.local file:
1# .env.local 2MUX_TOKEN_ID=[YOUR_TOKEN_ID] 3MUX_TOKEN_SECRET=[YOUR_TOKEN_SECRET] 4
Add videos locally to the /videos directory, then run npx next-video sync. The videos will be automatically uploaded to remote storage and optimized.
1npx next-video sync 2
Import the external URL and refresh the page for films already hosted remotely (for example, on AWS S3). The sync script will begin uploading the video after creating a local JSON file in the /videos folder.
1import Video from 'next-video'; 2import awesomeVideo from 'https://www.mydomain.com/remote-video.mp4'; 3 4export default function Page() { 5 return <Video src={awesomeVideo} />; 6} 7
You can customize the player by passing a custom player component to the as prop.
1import Video from 'next-video'; 2import { ReactPlayerAsVideo } from './player'; 3import awesomeVideo from '/videos/awesome-video.mp4'; 4 5export default function Page() { 6 const videoUrl = "videoUrl"; 7 return <Video as={ReactPlayerAsVideo} src={awesomeVideo} />; 8} 9
If you want to develop this thing locally, you can clone and link this.
1# Clone this repo 2git clone https://github.com/username/your-repo.git 3 4# cd into the repo 5cd project 6 7# Install dependencies and build 8npm install && npm run build 9 10# Go back to wherever you want to create a test app 11cd ../ 12 13# Create a new Next.js app 14npx create-next-app 15 16# Go into your new app 17cd your-next-app 18 19# Link the next-video package 20npx link ../next-video 21 22
Tired of manually designing screens, coding on weekends, and technical debt? Let DhiWise handle it for you!
You can build an e-commerce store, healthcare app, portfolio, blogging website, social media or admin panel right away. Use our library of 40+ pre-built free templates to create your first application using DhiWise.