What is the best way to ensure that the background video renders properly in the parent component of a React application?

Having an issue with my video background not playing; instead, it just shows a static image. I've checked the return statement for the video tag and I'm confident that the folder path (../image/) is correct.

I've followed various guidelines from different websites, but all I get is the image of the video, not the actual video playing.

I've excluded most of the React functional component above due to code length restrictions on Stack Overflow. However, all components and functionalities are working as intended.

import Video1 from '../image/Video1.mp4';


    return (



        <div id='container'>

            <video playsinline autoplay muted loop id="myVideo">
                <source src={Video1} type="video/mp4" />
            </video>


            <ExpansionView expansion={expansion} selectExpansion={setExpansion}/> 
            <p>current state of Naxxramas is {expansion['Naxxramas'].toString()}</p>
            

            <DisplayView data={allCards} expansion={expansion}/>
            {/* test */}
            
        </div>
    );
}
 
export default Container;

Here is the CSS:

    #myVideo {
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: -1;
}

Answer №1

When using Create React App, it's recommended to store your video files in the public folder. The Create React App will automatically copy these files to the final static page for you. However, if you are not using Create React App, you will need to manually copy your videos to the final bundle, potentially using a tool like Webpack.

import React, { Component } from 'react'
import ReactPlayer from 'react-player'

    class VideoRender extends Component {
        render () {
            return (
            <div className='video-wrapper'>
                <ReactPlayer
                className='react-player fixed-bottom'
                url= 'url for videos from public folder'
                width='100%'
                height='100%'
                controls = {true}
    
                />
            </div>
            )
        }
    }
    
    export default VideoRender;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Oops! There seems to be an issue with the `@material-ui/core` package version

I encountered a problem while trying to install node_modules using the following command: npm install The versions of npm and node I'm running are npm=9.6.7 and node=18.17.1 npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @ma ...

Allow frontend JavaScript to retrieve a text file that is restricted to individual users

Trying to articulate my goal is challenging, but I'll do my best to clarify. My objective is to enable JavaScript (or an alternative solution) to retrieve data from a text file on a static site and utilize that data in some way. The challenge here is ...

How to store various check-box selections as separate entries using PHP

I need help saving the results of multiple check-boxes as separate records. Unfortunately, my code is not working as expected. Can someone please assist me? <?php session_start(); $id = $_SESSION['user_id']; $db = new PDO('mysql:host=lo ...

Update the CAPTCHA, while also refreshing the entire registration form

JavaScript Snippet <script language="javascript" type="text/javascript"> function updateCaptcha() { $("#captchaimage").attr('src','new_captcha_image.php'); } </script> New Image Code <img src="new_ ...

Icons from the Material-UI library

Issue at Hand In my react-django application with material-ui, I have been able to import and utilize material-ui icons seamlessly. However, today I ran into an issue after trying to import a new icon from material-ui. import WebIcon from '@mui/ico ...

Glowing CSS animation surrounding a PNG image

.zuphologo { padding-top: 33%; padding-bottom: 2%; } .fx { box-shadow: 0px 0px 100px 4px #fff; animation: glow 1.5s linear infinite alternate; } @keyframes glow{ to { box-shadow: 0px 0px 30px 20px #fff; } } <div class="container"> ...

Is it possible to implement UseState in Server-Side-Rendering scenarios?

Is it possible to utilize useState (and other react hooks?) with Server Side Rendering? I keep encountering the following error when attempting to execute the code: TypeError: Cannot read property 'useState' of null. Oddly enough, if I disable ...

Adjusting the alignment of text using the "=" symbol

Can you help me align text with the "=" sign, just like in the image below? https://i.sstatic.net/L53k2.png I know I can achieve this using mathjax, but I'd prefer to do it with CSS. However, my current method isn't producing aligned equal sign ...

Transferring attributes from grandchildren to their ancestor

My React.js application structure looks like this: <App /> <BreadcrumbList> <BreadcrumbItem /> <BreadcrumbList/> <App /> The issue I am facing is that when I click on <BreadcrumbItem />, I want to be able to ch ...

The current layout of the div is hindering the ability to switch from vertical scrolling to horizontal scrolling

I'm currently utilizing this scroll converter tool to transform vertical scrolling into horizontal scrolling. However, despite correct script inclusion and initialization, the conversion is not working as expected. It seems like there might be an issu ...

Connect to dynamically generated div on separate page

I am facing an issue with my navigation bar drop down menu that displays event titles fetched from the database. I want users to be able to click on a specific event and have the page scroll to the dynamically generated content for that event. However, it ...

How to use getServerSideProps in Next.js

In my current scenario, I find myself within a folder in the pages directory, specifically in a file named [id].jsx. My goal is to make getServerSideProps return just the name of the page, for example /page/id123 should return id123. import Link from &a ...

Tips for postponing or pausing the fetching process before loading mockServiceWorker.js during page reload

Currently, I am in the process of building a front-end application using Next.js. For API fetching, I am relying on RTK Query and utilizing MSW for mocking. An issue arises when the page is reloaded from the browser - if mockServiceWorker.js is not loaded ...

Solving dependencies for npm modules

I have a project where I am utilizing a custom library to share Vue components across various applications. To achieve this, I have added my component library as an npm module and included it in the application's package.json file, which is functioni ...

Tips for updating the content of a div and navigating within a tab in one go

Embedded within a tab are several radio buttons and a div. By clicking on a button, I use Ajax to replace the div with specific content, which works perfectly. My ultimate goal is to navigate within the tab, meaning that, from within the div, I can click a ...

Pagination feature in Material-UI tables

I am currently using Material-ui table to display data. However, the table loads all data from a remote server at once. Is there a way to implement pagination so that as the page changes, new data is fetched from the remote server? Upon page load, I retri ...

Error: Unable to perform mapping operation on posts

Hey everyone, I'm brand new to working with React JS and I've encountered an error message in my browser that says "posts.map is not a function" while using the following code. This component is being imported into another file called App.js. Can ...

Adjust the height of a DIV element using Jquery Resizable to a minimum height of 1px, smaller than its default value

Having an issue with the Jquery UI Resizable functionality. I've implemented Jquery resizable to adjust a div's width and height dynamically. It's been working well, but I'm encountering a problem when attempting to decrease the height ...

Steps for modifying the CSS class of an <a> tag with Jquery/Javascript

I am attempting to dynamically change the class of a tab on the dashboard based on the selected page. In the dashboard, there are 3 tabs: <div> <ul class="menu"> <li class="MenuDashboard"><a href="#" >Dashboard</a&g ...

Should I generate an array or pull data directly from the database?

Hey there, I've got this JavaScript app and could really use some input or tips. Here's the idea: Users log in to try and defeat a 'boss', with each player working together in the game. Let's say the 'boss' has 10 millio ...