Html 强制 HTML5 youtube 视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5845484/
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 08:20:16  来源:igfitidea点击:

Force HTML5 youtube video

htmlvideoyoutube

提问by Kami

Regarding the Youtube API Blogthey are experimenting with their new HTML5Video Player.

关于Youtube API 博客,他们正在试验新的HTML5视频播放器。

Apparently to play a video in html5, you have to use the iframe embedding code :

显然要在 html5 中播放视频,您必须使用 iframe 嵌入代码:

<iframe class="youtube-player" type="text/html" width="640" height="385"
  src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0">
</iframe>

But if the client has not joined the HTML5 Trial, the player will automatically fall back into the flash player even if the client's browser is HTML5 video capable.

但是如果客户端没有加入HTML5 试用版,即使客户端的浏览器支持 HTML5 视频,播放器也会自动回退到 Flash 播放器。

How to force the HTML5 video playback if the browser supports it, even if the users are not yet involved in the HTML5 Trial?

如果浏览器支持,如何强制播放 HTML5 视频,即使用户尚未参与 HTML5 试用?

Otherwise how to disable the flash fallback?

否则如何禁用闪存回退?

EDIT:

编辑:

It's possible to force HTML player through links to Youtube Video, but I need this kind of feature for embedded videos.

可以通过指向 Youtube Video 的链接强制 HTML 播放器,但我需要这种嵌入视频的功能。

回答by Kami

I've found the solution :

我找到了解决方案:

You have to add the html5=1in the src attribute of the iframe :

您必须html5=1在 iframe 的 src 属性中添加:

<iframe src="http://www.youtube.com/embed/dP15zlyra3c?html5=1"></iframe>

The video will be displayed as HTML5 if available, or fallback into flash player.

如果可用,视频将显示为 HTML5,或回退到 Flash 播放器。

回答by Vacilando

Whether or not YouTube videos play in HTML5 format depends on the setting at https://www.youtube.com/html5, per browser. Chrome prefers HTML5 playback automatically, but even the latest Firefox and Internet Explorer still use Flash if it is installed on the machine.

YouTube 视频是否以 HTML5 格式播放取决于每个浏览器在https://www.youtube.com/html5上的设置。Chrome 更喜欢自动播放 HTML5,但即使是最新的 Firefox 和 Internet Explorer,如果安装在机器上,仍然会使用 Flash。

The parameter html5=1 does not do anything (anymore) now. (Note it is not even listed at https://developers.google.com/youtube/player_parameters.)

参数 html5=1 现在不做任何事情(不再)。(请注意,它甚至未在https://developers.google.com/youtube/player_parameters 中列出。)

回答by alejandro

I tried using the iframe embed code and the HTML5 player appeared, however, for some reason the iframe was completely breaking my site.

我尝试使用 iframe 嵌入代码并且出现了 HTML5 播放器,但是,由于某种原因,iframe 完全破坏了我的网站。

I messed around with the old object embed code and it works perfectly fine. So if you're having problems with the iframe here's the code i used:

我把旧的对象嵌入代码弄乱了,它工作得很好。因此,如果您在使用 iframe 时遇到问题,请使用我使用的代码:

<object width="640" height="360">
<param name="movie" value="http://www.youtube.com/embed/VIDEO_ID?html5=1&amp;rel=0&amp;hl=en_US&amp;version=3"/>
<param name="allowFullScreen" value="true"/>
<param name="allowscriptaccess" value="always"/>
<embed width="640" height="360" src="http://www.youtube.com/embed/VIDEO_ID?html5=1&amp;rel=0&amp;hl=en_US&amp;version=3" class="youtube-player" type="text/html" allowscriptaccess="always" allowfullscreen="true"/>
</object>

hope this is useful for someone

希望这对某人有用

回答by samson

If you're using the iframe embed api, you can put html5:1as one of the playerVarsarguments, like so:

如果您使用的是 iframe embed api,则可以将其html5:1作为playerVars参数之一,如下所示:

player = new YT.Player('player', {
    height: '390',
    width: '640',
    videoId: '<VIDEO ID>',
    playerVars: {
        html5: 1
    },
});

Totally works.

完全有效。

回答by ashwinrishipj

Inline tag is used to add another src of document to the current html element.

内联标签用于将文档的另一个 src 添加到当前 html 元素。

In your case an video of a youtube and we need to specify the html type(4 or 5) to the browser externally to the link

在您的情况下是 youtube 的视频,我们需要在链接的外部为浏览器指定 html 类型(4 或 5)

so add ?html=5 to the end of the link.. :)

所以将 ?html=5 添加到链接的末尾.. :)