Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Video autoplay not working - Trying to find a fix

Tags:

reactjs

video

I have a video background in React. I want it to autoplay. Autoplay does not work.

I have tried:

  1. autoplay
  2. autoPlay
  3. autoPlay="autoplay"

What I find particularly odd is that occasionally, it WILL work. But then it will stop.

Here is the code as it is right now.

<video loop autoPlay>
       <source src={require('../../videos/background.mp4')} type="video/mp4" />
</video>

Here is the entire section of the component. I'm using a transition, but as of last week, it didn't impact it.

<div className="video-background">
    <Transition in={true} timeout={1000} appear={true}>
        {(state) => (
          <div id="banner" className="video-foreground" style={{ 
                            ...transitionStyles[state]
                        }}>
                        <video loop autoPlay>
                            <source src={require('../../videos/background.mp4')} type="video/mp4" />
                        </video>
          </div>
        )}
     </Transition>
  </div>
like image 924
J Seabolt Avatar asked May 09 '18 18:05

J Seabolt


3 Answers

Well in my case added muted property.

Try this:

<video ... autoPlay muted />

Chrome 66 stops autoplay of all video that don't have the muted property.

Hope it helps.

like image 99
Sergio Reis Avatar answered Nov 16 '22 17:11

Sergio Reis


In my case the video in React did not play because I didn't capitalize autoplay. It has to be autoPlay.

like image 33
Ludder Avatar answered Nov 16 '22 16:11

Ludder


Try this (it works): autoPlay={true}

like image 12
Marrix Avatar answered Nov 16 '22 16:11

Marrix