<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Henrique Magalhães</title>
    <description>The latest articles on DEV Community by Henrique Magalhães (@autotelico).</description>
    <link>https://dev.to/autotelico</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1256476%2F5c956293-5190-4a9e-9f78-9fe4da6025ab.jpeg</url>
      <title>DEV Community: Henrique Magalhães</title>
      <link>https://dev.to/autotelico</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/autotelico"/>
    <language>en</language>
    <item>
      <title>How to add a video into your website in Next.js 14</title>
      <dc:creator>Henrique Magalhães</dc:creator>
      <pubDate>Tue, 14 May 2024 22:05:43 +0000</pubDate>
      <link>https://dev.to/autotelico/how-to-add-a-video-into-your-website-in-nextjs-14-2mi3</link>
      <guid>https://dev.to/autotelico/how-to-add-a-video-into-your-website-in-nextjs-14-2mi3</guid>
      <description>&lt;p&gt;Next.js 14 has come with many interesting changes, introducing the App Router as the main source where the program unwraps from.&lt;/p&gt;

&lt;p&gt;When you want to add a video to your website, you should start by creating a component. Let's make our own &lt;code&gt;Video&lt;/code&gt; component to be added to the page, where our video &lt;code&gt;test.mp4&lt;/code&gt; will be inserted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Video&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ReactNode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;video&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"1200"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"720"&lt;/span&gt; &lt;span class="na"&gt;controls&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;source&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"test.mp4"&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"video/mp4"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;video&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The video you are referencing must be placed inside the &lt;code&gt;public&lt;/code&gt; directory. The &lt;code&gt;public&lt;/code&gt; directory is where all of your static assets should be placed: images, videos, icons, and whatnot. Next.js 14 has been assembled to read src files straight from that directory. If it is, you can pass the &lt;code&gt;src&lt;/code&gt; attribute a simple string with the exact video file's name, and it will be displayed on your website.&lt;/p&gt;

&lt;p&gt;After building and exporting your &lt;code&gt;Video&lt;/code&gt; component, import it from the &lt;code&gt;app&lt;/code&gt; directory's &lt;code&gt;page.tsx&lt;/code&gt; file, where your website is displayed from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Video&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./components/Video&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Video&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see in the &lt;code&gt;import&lt;/code&gt; statement at the top of the file, I am importing from the &lt;code&gt;app/components&lt;/code&gt; directory. It is good practice to organize your files that way so that it is easier to maintain and expand upon your previous code.&lt;/p&gt;

&lt;p&gt;After doing the above, your video should be displayed successfully on the website.&lt;/p&gt;

&lt;p&gt;Hope it is of use to anyone! I struggled to find documentation on how to set the &lt;code&gt;src&lt;/code&gt; attribute correctly, and wanted to share this after figuring it out to save someone else's brains some neurons. 🧠&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
