Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play videos with iframe in html

Tags:

html

iframe

video

I want to play a video, but it is only downloading.

Here is my code:

<iframe src="videos/1.mp4" width="540" height="310"></iframe>

The Result when the page load is:

image when i load page

How can I play the video with iframe and not with the video tag?

like image 787
predactor Avatar asked Jun 06 '16 18:06

predactor


People also ask

Can I use iframe for video in HTML?

Playing a YouTube Video in HTMLDefine an <iframe> element in your web page. Let the src attribute point to the video URL. Use the width and height attributes to specify the dimension of the player. Add any other parameters to the URL (see below)

How do I autoplay a video in iframe?

Allowing iframes to autoplay video content You should also note the need to use the allowfullscreen attribute in complement to the allow attribute in order to support browsers that do not support allow attribute. If you are using amp-iframe and autoplay you need to add allow="autoplay" to your amp-iframe element.

How do I play a video from a website in HTML?

HTML allows playing video in the web browser by using <video> tag. To embed the video in the webpage, we use src element for mentioning the file address and width and height attributes are used to define its size. Example: In this example, we are using <video> tag to add video into the web page.


1 Answers

Although some browsers might support this way of importing a video(Using an <iframe>) some browsers will act towards the video as a file and attempt to download it. The correct way to display a video is using the <video> tag:

<video width="540" height="310" controls>
  <source src="videos/1.mp4" type="video/mp4">
</video>

See W3Schools tutorial here: video tag simple tutorial

like image 132
Bubble Hacker Avatar answered Sep 28 '22 00:09

Bubble Hacker