在 html 中使用 iframe 播放视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37664896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:22:09  来源:igfitidea点击:

Play videos with iframe in html

htmlvideoiframe

提问by predactor

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?

如何使用 iframe 而不是 video 标签播放视频?

采纳答案by M03

Actually there's nothing wrong with your code! But the problem is with IDM (Internet Download Manager) as it hooks every link that your browser is requesting and finds whether the destination you're trying to access matches what is in IDM's extensions list, so the first thing would execute after the file being requested is IDM as it has higher priority than your browser and its anyway serving as a listener inside your browser.

实际上,您的代码没有任何问题!但问题在于 IDM(Internet 下载管理器),因为它会挂钩浏览器请求的每个链接,并查找您尝试访问的目标是否与 IDM 的扩展列表中的内容匹配,因此在文件被加载后执行第一件事请求的是 IDM,因为它比您的浏览器具有更高的优先级,并且无论如何它都充当浏览器内的侦听器。

you either have to exclude "localhost" from the hook or you have to remove the mp4 extension from IDM's extension list (which isnt efficient)

您要么必须从钩子中排除“localhost”,要么必须从 IDM 的扩展列表中删除 mp4 扩展(效率不高)

回答by Bubble Hacker

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:

尽管某些浏览器可能支持这种导入视频的方式(使用<iframe>),但某些浏览器会将视频作为文件处理并尝试下载。显示视频的正确方法是使用<video>标签:

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

See W3Schools tutorial here: video tag simple tutorial

在此处查看 W3Schools 教程:视频标记简单教程

回答by Danilkalmykov

Just use the <video><source src="..." type="video/mp4"></video>tags.

只需使用<video><source src="..." type="video/mp4"></video>标签。

回答by Jhoedram

An iframe tag is used to display another page, not used to play video. You can not play a video with that tag, whether or vimeo youtube or any other company lets you add video using a "iframe" is because they have previously configured some options on that page and have put a video. And that's why you can insert a video through an iframe.

iframe 标签用于显示另一个页面,而不是用于播放视频。您无法播放带有该标签的视频,无论 vimeo youtube 或任何其他公司是否允许您使用“iframe”添加视频,都是因为他们之前已在该页面上配置了一些选项并已放置视频。这就是您可以通过 iframe 插入视频的原因。

Now if you want to force this, you should do the following:

现在,如果要强制执行此操作,则应执行以下操作:

  1. Create a html-and in that html implement a video with the

  2. Then from the other page write the <iframe src = "yourwebcontentvideo.html" />

  1. 创建一个 html-并在该 html 中实现一个带有

  2. 然后从另一页写 <iframe src = "yourwebcontentvideo.html" />

And that would be it.

就是这样。