How to autoplay local video with iframe?

There are many solutions out there on how to make youtube/vimeo autoplay a video but they don't seem to work on a local video:

<template>
  <section id="vision" class="vision">
    <iframe src="videos/cgi_neutral.mp4?autoplay=1" allow="autoplay" allowfullscreen="true"></iframe>
  </section>
</template>

This does not autoplay.

Upvotes: 0

Views: 7082

Answers (2)

RomanistHere
RomanistHere

Reputation: 892

For all those for whom autoplay attribute doesn't work, it shouldn't. Your video should be either muted as well, or there should be any registered action from user before (lick "click"). Otherwise browser won't allow your video to autoplay - which is good, actually.

So your code should like something like that:

            <video
                controls
                autoplay
                muted
                width="860"
                height="490"
            >
                <source
                    src="path.mp4"
                    type="video/mp4"
                />

Upvotes: 1

Marcus
Marcus

Reputation: 113

First, instead of using an iframe, use a <video> tag. (Because its self-hosted on your website, no need to use an iframe) To make it autoplay, just add the "autoplay" attribute.

For Example:

<video width="320" height="240" controls autoplay>
 <source src="movie.mp4" type="video/mp4">
</video>

Upvotes: 2

Related Questions