Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a video to a ReactJS app and make it visible on the view

I am currently generating a landing page, and I have been trying to figure it out how to add a video in multiple formats (for browser compatibility)

I am new in the ReactJS world, your help will be truly appreciated!

Here is my code:

I generated a component for the video (I'm not sure if this is the best thing I could do)

import React, { Component } from "react";
import video1 from "./video/vd1.mp4";
import video2 from "./video/vd2.ogv";
import video3 from "./video/vd3.webm";

class Video extends Component {
  render() {
    return (
      <div>
        <video src={video1} />
      </div>
    );
  }
}

export default Video;

And I have also this file that is where I want to place the video:

import React, { Component } from "react";
import { PageHeader } from "react-bootstrap";
import Video from "./Video";

class Content extends Component {
  render() {
    return (
      <div>
        <PageHeader className="title">
          <video src={Video} autoPlay="true" />
          <small>Welcome to</small> <br />
          Profile Pulse
        </PageHeader>
      </div>
    );
  }
}

export default Content;

Of course, this way of doing it is giving me zero results, so what would it be the best way to make the video appear on my landing page?


2 Answers

This should work,

Change <video> tag of Video component to

<video src={video1} width="600" height="300" controls="controls" autoplay="true" />

Change <Content>'s <video src={Video} autoPlay="true" /> to

<Video />
like image 128
benjamin c Avatar answered Oct 29 '25 10:10

benjamin c


This should work...Add the different formats as sources in the video-tag

<Video width="320" height="240" controls>
   <source src={video1}>
   <source src={video2}>
   <source src={video2}>
</Video>
like image 21
genio_alfa Avatar answered Oct 29 '25 11:10

genio_alfa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!