I have this code that shows a video on mobile. It just shows a play button without the video behind it. When I press on play the video starts normally but I want something behind it.
This is what it looks like:
<div class="flex justify-center sm:mt-[-200px] z-10 relative lg:flex-row pb-12 xl:pb-12 flex-col-reverse items-center bg-gradient-to-l from-yellow-50 to-yellow-100 rounded-xl">
<div class="video-container mt-14 rounded-lg overflow-hidden w-full max-w-[800px]">
<!-- Heading before the video -->
<div class="text-center text-4xl font-bold mb-10">
Learn about
</div>
<!-- Video container -->
<div class="w-[90%] mx-auto">
<!-- Encapsulate video within a div for better control -->
<video class="w-full h-auto rounded-lg>
<source src=" {{ url_for( 'static', filename='home.mp4' ) }} " type="video/mp4 ">
Your browser does not support the video tag.
</video>
</div>
</div>
</div>
2
Answers
To ensure that your video loads efficiently, you can apply
preload="metadata"
to your video tag and specify the second of the first frame#t=0.1
in your video source:If this solution doesn’t work for you, you can alternatively capture the first frame using JavaScript:
If you already have a custom thumbnail, you can simply add the poster attribute to your video tag:
Use autoplay, loop, muted attributes in tag.
Autoplay – Will automatically play the video
loop – video will never end it’ll run on a loop
muted – video will be running without any sound (best for background)