Video does not appear when I build the project

Asked

Viewed 55 times

-1

I created a site using Reactjs, and in the initial part I put a background video and a text in front, when I open the site Reactjs in my machine the video appears normally without any problem, when I deploy the site to Heroku, Everything is working normally except the video that does not appear. Both the video and the images on the site are in the same directory, and only the video that does not appear.

Because when I build my project, the video does not appear on my machine.

npm run build
npm install -g serve
serve -s build

Sample images:

O video é essa logo da apple de fundo, na mihna maquina aparece deste jeito The video is this background apple logo, in the machine mihna appears like this

Quando dou deploy no Heroku fica desse jeito, sem o video When I deploy in Heroku is like this, without the video

Parte do código onde esta implementado Part of the code where it is implemented

EDIT: I found that the error was in the video id, for some reason the id field was not working, so I switched to classname and it worked normally.

EDIT2: And also that the opacity field in css was in percentage, the browsers support this, but when it goes through the compiler it doesn’t work right, so I switched to decimal.

  • I edited my reply, after downloading your project and checking what was happening.

1 answer

-2


Static media files should be imported as if they were Javascript files. For example, the following works in the production build:

// nos imports:
import videoFile from '../assets/video.mp4'

// no seu componente:
<video controls muted loop>
    <source src={videoFile} type="video/mp4" />
    Desculpe... seu navegador não suporta vídeos.
</video>

See more in https://create-react-app.dev/docs/adding-images-fonts-and-files/

EDIT:

Your video is actually showing, but with 1% opacity. Strangely, the compiler is changing the original value. See this answer for a solution. Change opacity: 40%; for opacity: 0.4;.

https://stackoverflow.com/questions/58853844/the-opacity-value-was-changed-to-1-after-building-the-reacjs-project

  • I found where the error was, I don’t know why but the 'id' field wasn’t working right, so I switched to classname and changed in css also to be a class. Now it’s working perfectly. Thanks for the help friend.

  • Did not know... apparently, percent opacity is supported by browsers but is not part of the specification. Hence the bundler does not take this into account and changes to 1%. https://www.w3.org/TR/2018/REC-css-color-3-20180619/#Transparency

  • Yes, strange that, here I left in percentage, when running the build on my PC looked like it should be, but when sending to Heroku he did not appear. Then I did what you said to change to decimal and it’s perfect in both cases now.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.