Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image placeholder for video loading in NextJS 14

I have next js 14 project. I have three videos for slider. I used swiper js. On one first slide, video sometime take times to load, it shows red background image.

I am trying to put image placeholder before video loading, but image placeholder is showing but video is not. How can i solve it?

  <SwiperSlide>
                
                <div className="relative w-full h-full">
                    <Image src='/placeholder-image.png' 
                    fill
                    alt='placeholder image'/>
                    
                    {/* Video element */}
                    <video
                        id="background-video"
                        preload="auto"
                        
                        autoPlay
                        loop
                        muted
                        playsInline
                        className="w-full h-full object-cover rounded-lg"
                    >
                        <source src="/SlideNew_1.webm" type="video/webm" />
                        Your browser does not support the video tag.
                    </video>
                </div></SwiperSlide>
like image 274
Umer Nasar Avatar asked Dec 29 '25 10:12

Umer Nasar


1 Answers

What you can do is to use poster attribute for the <video/> tag.

<SwiperSlide>  
  <div className="relative w-full h-full">
     <video
       poster="/placeholder-image.png"
       id="background-video"
       preload="auto"
       autoPlay
       loop
       muted
       playsInline
       className="w-full h-full object-cover rounded-lg"
     >
       <source src="/SlideNew_1.webm" type="video/webm" />
       Your browser does not support the video tag.
     </video>
   </div>
</SwiperSlide>
like image 67
Iaroslav Sobolev Avatar answered Jan 01 '26 03:01

Iaroslav Sobolev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!