HTML 视频标签显示 Youtube 视频
HTML video tag display Youtube video
我得到了一些 youtube 网址,例如 https://www.youtube.com/embed/LaXGkW_-Nvc?list=RDTDDDvaoGiDg。当我把它放到 html 视频标签时,它说 "Invalid source"。
如何解决这个问题?
当我使用 iframe 显示视频时,我遇到了另一个问题,如下所述:Video not showing in iframe on IE, but showing on firefox and chrome。
这是我的 HTML:
<video width="300" height="auto" autoplay="" controls="" name="media"><source src="https://www.youtube.com/embed/LaXGkW_-Nvc?list=RDTDDDvaoGiDg"></video>
youtube 视频不能使用 HTML5 视频标签,它只支持 MP4、WebM 和 Ogg 文件。 W3C Schools
Youtube 已经在其页面上为您提供了一个 "embed" 功能,可以自动为您生成 iFrame。 Youtube Embed There are a few other methods but they are no longer used (deprecated). Youtube API
关于 IE 的问题,也许可以看看这个类似的问题:YouTube iframe embed code not working in IE
如果您想使用 HTML5 视频标签,解决此问题的唯一方法是以指定格式之一下载 Youtube 视频。
您需要使用 <iframe>
标签来嵌入 YouTube。请阅读以下代码:
<iframe src="https://www.youtube.com/embed/5L3wKniOnro?autoplay=1" width="600" height="400" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
我得到了一些 youtube 网址,例如 https://www.youtube.com/embed/LaXGkW_-Nvc?list=RDTDDDvaoGiDg。当我把它放到 html 视频标签时,它说 "Invalid source"。
如何解决这个问题?
当我使用 iframe 显示视频时,我遇到了另一个问题,如下所述:Video not showing in iframe on IE, but showing on firefox and chrome。
这是我的 HTML:
<video width="300" height="auto" autoplay="" controls="" name="media"><source src="https://www.youtube.com/embed/LaXGkW_-Nvc?list=RDTDDDvaoGiDg"></video>
youtube 视频不能使用 HTML5 视频标签,它只支持 MP4、WebM 和 Ogg 文件。 W3C Schools
Youtube 已经在其页面上为您提供了一个 "embed" 功能,可以自动为您生成 iFrame。 Youtube Embed There are a few other methods but they are no longer used (deprecated). Youtube API
关于 IE 的问题,也许可以看看这个类似的问题:YouTube iframe embed code not working in IE
如果您想使用 HTML5 视频标签,解决此问题的唯一方法是以指定格式之一下载 Youtube 视频。
您需要使用 <iframe>
标签来嵌入 YouTube。请阅读以下代码:
<iframe src="https://www.youtube.com/embed/5L3wKniOnro?autoplay=1" width="600" height="400" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>