7

I am trying to have have video in my web page using HTML <video> tag using ReactJS and JSX. Right now nothing is playing even though my component has the path to the file

IntroVideo this.props:

{
  introVideo: "assets/media/Cherngloong_website_intro_Uz921bT.mp4",
  muted: "true"
}

Component:

class IntroVideo extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
        };
    }

    render() {
        return(
            <div>
                <video className="video-container video-container-overlay" autoPlay="true" loop muted={ this.props.muted }>
                    <source src={ this.props.introVideo } type="video/mp4" />
                </video>
            </div>
        );
    }
}

Here is what I see in the developer tools:

<video class="video-container video-container-overlay" autoplay="" loop="" muted="" data-reactid=".0.1.0.0">
    <source type="video/mp4" data-reactid=".0.1.0.0.0" src="assets/media/Cherngloong_website_intro_Uz921bT.mp4">
</video>

In the developer tools, if I right click the src value and click on "Open link in new tab", the video would play in the new tab. So I believe it the path to the file is correct.

I am doing the same thing for another Component but it is for an image and it works fine:

About this.props:

{
  aboutImg: "assets/media/The_Lion_Dances_Celebrate_Happy_New_Year_Clipart.jpg"
}

Component:

class About extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
        };
    }

    render() {
        return(
            <div id="about-container">
                <div id="about-img-container">
                    <img src={ this.props.aboutImg } alt="about_img"/>
                </div>
                <div id="about-text-container">
                    <p>
                        Message
                    </p>
                </div>
            </div>
        );
    }
}

Developer Tools:

<div id="about-container" data-reactid=".0.1.1">
    <div id="about-img-container" data-reactid=".0.1.1.0">
        <img alt="about_img" data-reactid=".0.1.1.0.0" src="assets/media/The_Lion_Dances_Celebrate_Happy_New_Year_Clipart.jpg">
    </div>
    <div id="about-text-container" data-reactid=".0.1.1.1">
        <p data-reactid=".0.1.1.1.0">Message</p>
    </div>
</div>
6
  • What specifically isn't working? Have you tried autoplay="autoplay" instead, or added controls="controls" so that you can click the video to start it? Commented Apr 30, 2016 at 1:10
  • Looks like in JSX it's supposed to be autoplay with no value, or autoplay={true} Commented Apr 30, 2016 at 2:47
  • @loganfsmyth tried autoPlay and autoPlay={true} no luck =[ Commented Apr 30, 2016 at 8:18
  • So what specifically isn't working? Can you see the preview image, but it won't play? Did you try my first set of suggestions? Commented Apr 30, 2016 at 16:15
  • @loganfsmyth I tried your suggestions and no success =[ I cannot see any video at all. As if there is no src Here is what I see on my browser and dev tools: postimg.org/image/b0u3swswh postimg.org/image/ccg3pz9ld Commented May 1, 2016 at 6:37

4 Answers 4

2

It looks like a bad path. The generated html seems to be fine. I tested it here:

http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_video

The video rendered fine, and all I did was change the src.

<video className="video-container video-container-overlay" autoPlay="" loop="" muted="" data-reactid=".0.1.0.0">
  <source type="video/mp4" data-reactid=".0.1.0.0.0" src="mov_bbb.mp4">
</video>
Sign up to request clarification or add additional context in comments.

Comments

0

Video React

a Component for playing video would be a better option as it has lots of customisation

Comments

0

In that case, I add the "?" at the end of the video url and it acts well. I got the same case with the url by using the video in aws s3 bucket. So I used the url as "assets/media/Cherngloong_website_intro_Uz921bT.mp4?"

Comments

0

put the video in the public/videos folder and write the src as below

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.