All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

HTML Video Autoplay Not Working

Last Updated : Mar 11, 2024

HTML Video Autoplay Not Working

In this tutorial we will show you the solution of HTML video autoplay not working, in our previous tutorials, we already covered the topics like HTML video autoplay, html video in iframe, how to make video autoplay with muted, etc.

After, that our developers come across with a problem that autoplay is not working in some browsers like safari, chrome, etc.

For the solution of their problem today we will learn about how to solve the issue of autoplay not working in html videos. Let us understand:

Step By Step Guide On HTML Video Autoplay Not Working :-

Now, today we have to give solution of problem from our developers that autoplay is not working. And we have to provide the solution of this problem.

Here below we show you code example with the help of which error gets resolved. Let us see codes:

<!DOCTYPE html>
      <html>
        <head>
        <title>
            video
        </title>
    <script src="js/jquery.js"></script>
<script>
        document.getElementById('video').play();
        document.getElementById('movie').play();
    </script>
</head>
<body>
   <video autoplay id="video">
        <source type="video/mp4" src="https://www.youtube.com/embed/YhvdaNa2oSU?rel=0?autoplay=1&&showinfo=0&loop=1">
        <source type="video/ogg" src="https://www.youtube.com/embed/YhvdaNa2oSU?rel=0?autoplay=1&&showinfo=0&loop=1">
    </video>
    <video autoplay id="movie">
        <source type="video/mp4" src="video.mp4 ">
        <source type="video/ogg" src="video.ogg ">
    </video>
</body>
</html>
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title.
  4. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively. Here, is some CSS codes which we will discuss in next point.
  5. Here, we create body tag, which is a paired tag. And all the contents that are being to be displayed on browser screen are written here.
  6. Here, in body tag we create two video tags. The first one is for online source of video whereas the other or next one is for video from local drive or directory. Let us understand them one by one.
  7. In first video tag, we use autoplay with id attribute, the value of id is video. And inside this video we create two source tags. First is for mp4 whereas other is for ogg format.
  8. In second case, we again create video tag with autoplay and id having value movie. And in video tag, we create two source tags for different video formats. In this video tag, we use local videos to play. Inside source tag we give values of videos which we want to play as above.
  9. Now, the main concept is here of JavaScript, for this we have to add a js file into head tag. Whereas in script, we use inbuilt play to make videos autoplay. For reference of video, we use document.getElementById here.
  10. At last, the <body> and <html> tags are closed with </body> and </html> respectively.

Conclusion :-

In conclusion, here we can say that after reading this article we are able to make video autoplay in html that is not working with the help of autoplay attribute.

I hope this tutorial on HTML video autoplay not working helps you.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪