{"id":28457,"date":"2023-06-02T07:00:00","date_gmt":"2023-06-02T14:00:00","guid":{"rendered":"http:\/\/Autoplay-a-Video-on-a-Next.js-Landing-page"},"modified":"2025-02-08T18:01:33","modified_gmt":"2025-02-09T02:01:33","slug":"autoplay-a-video-on-a-next-js-landing-page","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page","title":{"rendered":"Autoplay a Video on a Next.js Landing page"},"content":{"rendered":"<div class=\"wp-block-cloudinary-markdown \"><p>In modern web pages and platforms, a less than stellar user experience could lead to a significant drop in conversion. This can be said for media content, including videos and images.<\/p>\n<p>So how do you improve the user experience of video content on your application?<\/p>\n<p>This article outlines how to autoplay video content when a user scrolls to the video on a Next.js page. We\u2019ll use the <a href=\"https:\/\/cloudinary.com\/documentation\/cloudinary_video_player\">Cloudinary video player<\/a> to render the video.<\/p>\n<p>\nNext.js is a React framework that enables server-rendered and static web applications to be built. It&#8217;s used by renowned companies such as Netflix, Uber, and Airbnb. This framework is not just about enhancing the user experience with media content but offers a comprehensive solution for building both dynamic and static websites. Some of its standout features include server-side rendering, which can significantly boost the performance of your website, especially for pages that aren&#8217;t updated frequently. Additionally, Next.js supports hot reloading, ensuring that changes to your code are instantly visible in the browser without a server restart. This feature is particularly beneficial during the development phase. Furthermore, with built-in routing, creating and managing website navigation becomes a breeze. For those who prefer using TypeScript, Next.js has got you covered, enhancing the maintainability of your code.\n<\/p>\n<p><a href=\"https:\/\/cloudinary.com\/\">Cloudinary<\/a> provides a robust media experience for any media type, covering image and video uploads, storage, and optimizations. With Cloudinary, you can store and render your video assets on a Next.js landing page.<\/p>\n<h2>Sandbox<\/h2>\n<p>You can find a complete version of the application on <a href=\"https:\/\/codesandbox.io\/s\/cloudinary-video-player-app-899ro\">Codesandbox.<\/a><\/p>\n<!--\n[Bilal] Please use this instead. Fill the ID and Title.\nEdit- William: Done \n-->\n<\/div>\n\n\n  <div class=\"wp-block-cloudinary-code-sandbox \">\n    <iframe\n      src=\"https:\/\/codesandbox.io\/embed\/cloudinary-video-player-app-899ro?theme=dark&amp;codemirror=1&amp;highlights=&amp;editorsize=50&amp;fontsize=14&amp;expanddevtools=0&amp;hidedevtools=0&amp;eslint=0&amp;forcerefresh=0&amp;hidenavigation=0&amp;initialpath=%2F&amp;module=&amp;moduleview=0&amp;previewwindow=&amp;view=&amp;runonclick=1\"\n      height=\"500\"\n      style=\"width: 100%;\"\n      title=\"Autoplay a video on a Next.js Landing page\"\n      loading=\"lazy\"\n      allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n      sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n    ><\/iframe>\n  <\/div>\n\n\n<div class=\"wp-block-cloudinary-markdown \"><h2>Prerequisites and Installation<\/h2>\n<p>To get the most out of this article, you should have basic knowledge of JavaScript and React and understand Next.js.<\/p>\n<p>\n<strong>Getting Started with Next.js: <\/strong>Installing and setting up Next.js is straightforward. With just a single command, you can have Next.js installed and ready to go. Once installed, you can kick off your website development by creating a new React project. For beginners or those looking for a quick start, Next.js offers several starter projects. These projects can serve as a foundation, allowing you to build upon them and customize as per your requirements.\n<\/p>\n<p>To get started, we\u2019ll install the Next.js CLI, and create a new Next application using NPX \u2014 a node package runner. You can also use yarn to install packages and create a new project. Next.js ships with starters, and we\u2019ll use the Next.js defaulter starter in our application.<\/p>\n<p>To get a Next.js project started, navigate to your desired directory and run the command below:<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">    npx create-next-app \n<\/code><\/span><\/pre>\n<p>The command above will return an input, asking you for the project name. You can use your desired project name. Once done, it will create a Next.js project using the default starter.<\/p>\n<p>We\u2019ll use the Cloudinary video player shipped in the <code>cloudinary-react<\/code> package. The video player is efficient because we can use a public ID that\u2019s a unique identifier of the video on Cloudinary. We\u2019ll use this ID to fetch our uploaded video asset and build dynamic delivery. Also, robust video transformations from Cloudinary are available when using the video player.<\/p>\n<p>Proceed to install the following dependencies using the command below:<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">    npm install Cloudinary-react react-intersection-observer \n<\/code><\/span><\/pre>\n<p><code>cloudinary-react<\/code>  is a Software Development Kit (SDK) that allows us to seamlessly utilize Cloudinary\u2019s image and video features in a React app.<\/p>\n<p><a href=\"https:\/\/github.com\/researchgate\/react-intersection-observer\">react-intersection-observer<\/a> tells us when an element enters or leaves a particular viewport. This is essential to know when our video player is in view.<\/p>\n<h2>Creating the Video Player<\/h2>\n<p>First, we\u2019ll create a new directory called <code>Videoplayer<\/code> in our app\u2019s src\/components directory. Next, we\u2019ll create a file called <code>VideoPlayer.jsx<\/code> that will house the video player component. Then, we\u2019ll import the required dependencies using in the component with:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">    <span class=\"hljs-comment\">\/\/ src\/components\/Videoplayer\/VideoPlayer.jsx<\/span>\n    <span class=\"hljs-keyword\">import<\/span> React, { useEffect, useref } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"react\"<\/span>;\n    <span class=\"hljs-keyword\">import<\/span> { Video, CloudinaryContext } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"Cloudinary-react\"<\/span>;\n    <span class=\"hljs-keyword\">import<\/span> { useInView } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"react-intersection-observer\"<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Intersection_Observer_API\">Intersection observer API<\/a> provides a way to asynchronously observe changes in the intersection of a target element with a parent element, or viewport, in the browser.<\/p>\n<p><a href=\"https:\/\/github.com\/researchgate\/react-intersection-observer\">react-intersection-observer<\/a> is a declarative wrapper component for Intersection observer API.<\/p>\n<p>We\u2019ll create a function component for the video player, which takes in a video ref. The component will return a Cloudinary <code>Video<\/code> component wrapped in a Cloudinary Context component. <code>CloudinaryContext<\/code> allows you to define shared parameters that apply to all child elements.<\/p>\n<p>Let\u2019s add the snippet below to our <code>VideoPlayer<\/code> component:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">    <span class=\"hljs-keyword\">const<\/span> VidPlayer = React.memo(<span class=\"hljs-function\">(<span class=\"hljs-params\">{ videoref }<\/span>) =&gt;<\/span> {\n      <span class=\"hljs-keyword\">return<\/span> (\n        <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">CloudinaryContext<\/span> <span class=\"hljs-attr\">cloud_name<\/span>=<span class=\"hljs-string\">\"codedog\"<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Video<\/span>\n            <span class=\"hljs-attr\">publicId<\/span>=<span class=\"hljs-string\">\"videoplayer-demo\"<\/span>\n            <span class=\"hljs-attr\">width<\/span>=<span class=\"hljs-string\">\"100%\"<\/span>\n            <span class=\"hljs-attr\">controls<\/span>\n            <span class=\"hljs-attr\">innerref<\/span>=<span class=\"hljs-string\">{videoref}<\/span>\n          \/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">CloudinaryContext<\/span>&gt;<\/span><\/span>\n      );\n    });\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>In the code above, our component is wrapped in <code>React.memo<\/code>.<\/p>\n<p><code>[React.memo()](https:\/\/reactjs.org\/docs\/hooks-reference.html#usememo)<\/code> is a higher-order component (HOC) that takes a component as a prop, and returns a component, preventing a component from re-rendering if the props haven\u2019t changed. <code>React.memo()<\/code> implements <a href=\"https:\/\/en.wikipedia.org\/wiki\/Memoization#:~:text=In%20computing%2C%20memoization%20or%20memoisation,the%20same%20inputs%20occur%20again.\">memoization<\/a> on React components, and prevents our Video player from rerendering even if its parent component rerenders.<\/p>\n<p>The Cloudinary context specifies the cloud_name, with which we fetch media assets from Cloudinary. To obtain your cloud_name, you need to <a href=\"https:\/\/cloudinary.com\/users\/register_free\">create an account on Cloudinary<\/a>, and get the cloud name value from your Cloudinary dashboard.<\/p>\n<p>We also specified options for our video player, including the <code>publicId<\/code> of our video on Cloudinary.<\/p>\n<h2>Handling Video Interaction With Intersection-observer<\/h2>\n<p>In src\/components\/VideoPlayer.jsx, we\u2019ll create a function component named <code>VideoPlayer<\/code>. Inside it, we\u2019ll use the <code>useInView<\/code> hook, imported from <code>react-intersection-observer<\/code> to track a DOM element for when it gets in view.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">    <span class=\"hljs-keyword\">const<\/span> VideoPlayer = <span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n      <span class=\"hljs-keyword\">const<\/span> videoref = useref();\n      <span class=\"hljs-keyword\">const<\/span> { ref, inView } = useInView({\n        <span class=\"hljs-attr\">threshold<\/span>: <span class=\"hljs-number\">0<\/span>\n      });\n      useEffect(<span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n        <span class=\"hljs-keyword\">if<\/span> (inView === <span class=\"hljs-literal\">true<\/span>) {\n          videoref.current.play();\n        }\n      });\n      <span class=\"hljs-keyword\">return<\/span> (\n        <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">ref<\/span>=<span class=\"hljs-string\">{ref}<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">VidPlayer<\/span> <span class=\"hljs-attr\">videoref<\/span>=<span class=\"hljs-string\">{videoref}<\/span> \/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span><\/span>\n      );\n    };\n    <span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">default<\/span> VideoPlayer;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>We assigned the <code>ref<\/code> value, destructured from the <code>useInView<\/code> hook, to the DOM element we want to monitor. In this case, it\u2019s the div enclosing the rendered <code>VidPlayer<\/code> component.<\/p>\n<p>In the <code>VideoPlayer<\/code> component\u2019s <code>useEffect<\/code> function, we\u2019ll play the video when in view.<\/p>\n<p>The <code>videoRef<\/code> reference is created using React\u2019s <code>useRef()<\/code> hook, and is assigned to the ref prop of video player. This ref value will be used to access the video player methods in our <code>VideoPlayer<\/code> component. The HTML video element\u2019s <code>.play()<\/code> method is then used to play the video when it\u2019s in view.<\/p>\n<p><code>refs<\/code> are references to objects. They can include DOM nodes or values. <code>useRef<\/code> returns a mutable object with a <code>.current<\/code> property set to the initial value we passed to the hook. The code below should be added to our <code>VideoPlayer.jsx<\/code> file.<\/p>\n<h2>Rendering the Video Player<\/h2>\n<p>In the site\u2019s home page, located in the <code>src\/pages<\/code>, we\u2019ll create a new file named <code>index.jsx<\/code>. This is the home page of the website. In this file, we\u2019ll render the <code>VideoPlayer<\/code> component in the parent <code>Home<\/code> component along with other page content. The code snippet below should be copied into our newly created <code>index.jsx<\/code> file in <code>src\/pages<\/code> directory.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\">    import Head from \"next\/head\";\n    import styles from \"..\/styles\/Home.module.css\";\n    import VideoPlayer from \"..\/components\/VideoPlayer\/VideoPlayer\";\n    \n    const Home = () =&gt; {\n      return (\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">{styles.container}<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Head<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">title<\/span>&gt;<\/span>Video Player with Cloudinary<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">title<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"icon\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"\/favicon.ico\"<\/span> \/&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Head<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">header<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">{styles.header}<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span>&gt;<\/span>Video Player<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">header<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">main<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">{styles.main}<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">section<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">{styles.intro}<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>NOW EASILY<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">{styles.title}<\/span>&gt;<\/span>\n                Render Your Videos with Cloudinary, <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">br<\/span> \/&gt;<\/span> And Observer Intersection\n                Library.\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">section<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>In the code block above, we created a <code>Home<\/code> component, with the <code>title<\/code> and icons for our landing page. Next, we\u2019ll add content and render the <code>VideoPlayer<\/code> component. The code block below will be added to our <code>index.jsx<\/code> file above.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\">            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">section<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">{styles.img_wrapper}<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"\/assets\/video.svg\"<\/span> <span class=\"hljs-attr\">alt<\/span>=<span class=\"hljs-string\">\"illustration\"<\/span> \/&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">section<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">main<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">section<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">{styles.description}<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n            There is no one who loves pain itself, who seeks after it, and wants to have it, simply because it is pain.\n            There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain.\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">section<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">section<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">{styles.video_player}<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">VideoPlayer<\/span> \/&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">section<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n      );\n    };\n    export default Home;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>The home page should look like this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cloudinary-marketing-res.cloudinary.com\/image\/upload\/c_limit,w_2000\/f_auto\/q_auto\/media_jams\/s_1274B757EB25F908DAF96D76F5158206B2443945AE63F4CFFC5F247A81B841A3_1617147378403_-downsized.gif\" alt=\"cloudinary video player\" loading=\"lazy\" class=\"c-transformed-asset\"  width=\"480\" height=\"225\"\/><\/p>\n<h2>Summary<\/h2>\n<p>In this article, we created a Next.js landing page and made a video player using the Cloudinary video player. We also added <a href=\"https:\/\/cloudinary.com\/glossary\/video-autoplay\">autoplay<\/a> when in the video is in view, using React Observer Intersection. You can improve the application by utilizing other video player events.<\/p>\n<p>\nAs we&#8217;ve seen, Next.js is a versatile React framework that offers a plethora of features, making it a top choice for web developers. From server-side rendering to static site generation, it provides tools that can significantly enhance the performance and SEO of your website. Furthermore, with features like hot reloading and built-in routing, development becomes a breeze. Its compatibility with TypeScript ensures that your code remains maintainable and robust. Whether you&#8217;re building a dynamic web application or a static portfolio site, Next.js has got you covered.\n<\/p>\n<p>Check out these other useful resources:<\/p>\n<ul>\n<li>\n<a href=\"https:\/\/cloudinary.com\/documentation\/video_player_api_reference\">Cloudinary<\/a> <a href=\"https:\/\/cloudinary.com\/documentation\/video_player_api_reference\">video player<\/a> <a href=\"https:\/\/cloudinary.com\/documentation\/video_player_api_reference\">ref<\/a><a href=\"https:\/\/cloudinary.com\/documentation\/video_player_api_reference\">erence<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/nextjs.org\/learn\/basics\/create-nextjs-app\">Nextjs: Getting started<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/dev.to\/producthackers\/intersection-observer-using-react-49ko\">React intersection observer<\/a>\n<\/li>\n<\/ul>\n<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":87,"featured_media":29402,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[134,212,382,246,303],"class_list":["post-28457","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-guest-post","tag-next-js","tag-player-video","tag-react","tag-video"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.6 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Autoplay a Video on a Next.js Landing page<\/title>\n<meta name=\"description\" content=\"Learn to autoplay a video when scrolled into view on a Next.js landing page.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Autoplay a Video on a Next.js Landing page\" \/>\n<meta property=\"og:description\" content=\"Learn to autoplay a video when scrolled into view on a Next.js landing page.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-02T14:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-09T02:01:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs-jpg?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"1100\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"melindapham\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"NewsArticle\",\"@id\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page\"},\"author\":{\"name\":\"melindapham\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/0d5ad601e4c3b5be89245dfb14be42d9\"},\"headline\":\"Autoplay a Video on a Next.js Landing page\",\"datePublished\":\"2023-06-02T14:00:00+00:00\",\"dateModified\":\"2025-02-09T02:01:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page\"},\"wordCount\":9,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs.jpg?_i=AA\",\"keywords\":[\"Guest Post\",\"Next.js\",\"Player Video\",\"React\",\"Video\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2023\",\"copyrightHolder\":{\"@id\":\"https:\/\/cloudinary.com\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page\",\"url\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page\",\"name\":\"Autoplay a Video on a Next.js Landing page\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs.jpg?_i=AA\",\"datePublished\":\"2023-06-02T14:00:00+00:00\",\"dateModified\":\"2025-02-09T02:01:33+00:00\",\"description\":\"Learn to autoplay a video when scrolled into view on a Next.js landing page.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs.jpg?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs.jpg?_i=AA\",\"width\":2000,\"height\":1100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Autoplay a Video on a Next.js Landing page\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"name\":\"Cloudinary Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudinary.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\",\"name\":\"Cloudinary Blog\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"width\":312,\"height\":60,\"caption\":\"Cloudinary Blog\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/0d5ad601e4c3b5be89245dfb14be42d9\",\"name\":\"melindapham\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e6f989fa97fe94be61596259d8629c3df65aec4c7da5c0000f90d810f313d4f4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e6f989fa97fe94be61596259d8629c3df65aec4c7da5c0000f90d810f313d4f4?s=96&d=mm&r=g\",\"caption\":\"melindapham\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Autoplay a Video on a Next.js Landing page","description":"Learn to autoplay a video when scrolled into view on a Next.js landing page.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page","og_locale":"en_US","og_type":"article","og_title":"Autoplay a Video on a Next.js Landing page","og_description":"Learn to autoplay a video when scrolled into view on a Next.js landing page.","og_url":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page","og_site_name":"Cloudinary Blog","article_published_time":"2023-06-02T14:00:00+00:00","article_modified_time":"2025-02-09T02:01:33+00:00","og_image":[{"width":2000,"height":1100,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs-jpg?_i=AA","type":"image\/jpeg"}],"author":"melindapham","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page"},"author":{"name":"melindapham","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/0d5ad601e4c3b5be89245dfb14be42d9"},"headline":"Autoplay a Video on a Next.js Landing page","datePublished":"2023-06-02T14:00:00+00:00","dateModified":"2025-02-09T02:01:33+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page"},"wordCount":9,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs.jpg?_i=AA","keywords":["Guest Post","Next.js","Player Video","React","Video"],"inLanguage":"en-US","copyrightYear":"2023","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page","url":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page","name":"Autoplay a Video on a Next.js Landing page","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs.jpg?_i=AA","datePublished":"2023-06-02T14:00:00+00:00","dateModified":"2025-02-09T02:01:33+00:00","description":"Learn to autoplay a video when scrolled into view on a Next.js landing page.","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs.jpg?_i=AA","width":2000,"height":1100},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/autoplay-a-video-on-a-next-js-landing-page#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Autoplay a Video on a Next.js Landing page"}]},{"@type":"WebSite","@id":"https:\/\/cloudinary.com\/blog\/#website","url":"https:\/\/cloudinary.com\/blog\/","name":"Cloudinary Blog","description":"","publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudinary.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudinary.com\/blog\/#organization","name":"Cloudinary Blog","url":"https:\/\/cloudinary.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","width":312,"height":60,"caption":"Cloudinary Blog"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/0d5ad601e4c3b5be89245dfb14be42d9","name":"melindapham","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e6f989fa97fe94be61596259d8629c3df65aec4c7da5c0000f90d810f313d4f4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e6f989fa97fe94be61596259d8629c3df65aec4c7da5c0000f90d810f313d4f4?s=96&d=mm&r=g","caption":"melindapham"}}]}},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1684790770\/Blog-autoplay-video-nextjs\/Blog-autoplay-video-nextjs.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/comments?post=28457"}],"version-history":[{"count":20,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28457\/revisions"}],"predecessor-version":[{"id":36759,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28457\/revisions\/36759"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/29402"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=28457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=28457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=28457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}