How can I add a mp4 video here?

Repl link:

https://replit.com/@S4IL/S4IL#games/cool_game/index.html


image

Please help
I really want to do that, i tryed lots of things but none work :sob:

Are you embedding a YouTube video or a manually uploaded one? I don’t see a video file in your code.

2 Likes

manually, i removed it, now that i notice, ive been 2 hours on this and i still coulnt do it…

1 Like

@CoderElijah just added it back!

it is inside the games/cool-game folder

Adding this to games/cool_game/index.html works:

 <video width="320" height="240" controls autoplay muted>
  <source src="rickroll.mp4" type="video/mp4">
Your browser does not support the video tag.
</video> 

S4IL is a dev! (my fork with a working Rick Roll, note that I may delete the Repl some day so when this post is two months old, the link may be a 404)

So, in order to autoplay on some browsers, it must be muted. You can take autoplay muted out, and then it will not autoplay, but when played there will be sound. Or you could put autoplay without muted, and it may not autoplay on every browser, but it might on some. Regardless, that embeds your video. See this article for more information on video embedding.

2 Likes

so, it cannot autoplay and not be muted?

In some browsers, it cannot autoplay with sound. I’m using Firefox and it did not autoplay until I added muted.

ohhhh, so that was the problem… is there a way to remove the pause controls?

and if you make an mp3 file sound then would it sound?

1 Like

You can remove the controls by taking controls out of the video element.

According to w3schools, an audio file will have the same issue where many browsers will block autoplay unless it’s muted (and who wants a muted audio file?).

ohhh, thanks a LOT!!!
how can i add the mp3 file (even if it doesnt autoplay)

1 Like

This should play audio if the browser will let you. As with video, you should be able to take out the controls attribute.

 <audio controls autoplay>
  <source src="rickroll.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

Souce

thank you A LOT! You helped me a lot, i love to program but i’m not really pro at the moment, but thanks a lot

2 Likes

You’re welcome! I’m glad I could help.

2 Likes

@CoderElijah wait! also, is there a way to make that if the browser allows, the video autoplays with audio, but if not, then muted?

I’m not sure. You could autoplay an MP3 with audio and the video without audio and that would work, but I’m not sure about the video by itself doing that. Note if you use MP3 and MP4, make sure the audio lines up with the video (I’d recommend converting your MP4 to MP3 to ensure this).

ok, thanks! but idk how to make detect if the browser allows or not…

1 Like

how could i do that?

oh… so you are gone…

PS: nvm :slight_smile: