A Next.js demo showing production-ready autoplay video components that work across all modern browsers. Uses ImageKit for video optimization. Check out the companion blog here.
- Autoplay videos with three attributes:
autoPlay,muted,playsInline - Uses
playsInlineto prevent iOS fullscreen hijacking - Plays videos on scroll, pauses when hidden
- Reduces 64MB videos to under 1MB with ImageKit transformations
git clone https://github.com/gitpichardo/nextjs-video-autoplay.git
cd nextjs-video-autoplay
npm install
npm run devOpen http://localhost:3000. You'll see three demo patterns:
- Hero background video
- Scroll-triggered video playback
- Before/after optimization comparison
To use your own videos and account:
- Sign up for ImageKit for free
- Create
.env.localin the project root:
NEXT_PUBLIC_IMAGEKIT_URL_ENDPOINT=https://ik.imagekit.io/YOUR_IMAGEKIT_ID
- Update
DEMO_VIDEO_PATHinlib/imagekit.tsto point to your video.
| Parameter | Effect |
|---|---|
w-1280 |
Resize to 1280px width |
q-50 |
50% quality |
ac-none |
Strip audio (required for autoplay) |
This repository accompanies the blog post: How to fix Autoplay Video in Next.js