gpt4 book ai didi

html - youtube 使用对象标签全屏嵌入视频

转载 作者:行者123 更新时间:2023-12-03 05:35:59 25 4
gpt4 key购买 nike

我知道 youtube 现在使用 <iframe>嵌入视频的标签 <object> .我有一些遗留代码需要使用 <object> 的全屏模式标签实现。是否可以通过 <object> 以某种方式强制 native 全屏模式?标签?

<object
width="560"
height="350"
data="http://www.youtube.com/v/B8IIyYpqb5w&amp;fs=1"
type="application/x-shockwave-flash">

<param name="wmode" value="opaque" />
<param name="allowFullScreen" value="true" />
<param name="src" value="http://www.youtube.com/v/B8IIyYpqb5w&amp;fs=1" />
</object>

我也试过 &fs=1&fullscreen=1 URL中的参数,但没有运气。

最佳答案

不幸的是,您必须使用 <iframe>反而。由于 ,您遇到了此限制<object> <embed> 根据 w3schools 已于 2015 年 1 月弃用.

基于此片段:

<body>

<div>
<object
type="application/x-shockwave-flash"
data="http://www.youtube.com/v/Wd1Iz6j4WC0"
width="425"
height="355">
<param name="movie" value="http://www.youtube.com/v/Wd1Iz6j4WC0">
<param name="allowFullScreen" value="true"></param>
</object>
</div>

<iframe src="//www.youtube.com/embed/Wd1Iz6j4WC0" width="640" height="360" frameborder="0" allowfullscreen="allowfullscreen"></iframe>


</body>

当 iframe 按预期运行时,对象标签不断出现“全屏不可用”。

或者你可以使用这个:
<!DOCTYPE html>
<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>

<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}

// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}

// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>

The sample HTML page below creates an embedded player that will load a video, play it for six seconds, and then stop the playback.



希望这有帮助。

关于html - youtube 使用对象标签全屏嵌入视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44208815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com