Html youtube嵌入带有对象标记的全屏视频
我知道youtube现在使用Html youtube嵌入带有对象标记的全屏视频,html,youtube,youtube-api,html4,Html,Youtube,Youtube Api,Html4,我知道youtube现在使用标签来嵌入视频,而不是。我有一些旧式代码,它需要全屏模式和标记实现。是否可以使用标记强制本机全屏模式 <object width="560" height="350" data="http://www.youtube.com/v/B8IIyYpqb5w&fs=1" type="application/x-shockwave-flash"> <param name="wmode" value
标签来嵌入视频,而不是
。我有一些旧式代码,它需要全屏模式和
标记实现。是否可以使用
标记强制本机全屏模式
<object
width="560"
height="350"
data="http://www.youtube.com/v/B8IIyYpqb5w&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&fs=1" />
</object>
我还在URL中尝试了
&fs=1
和&fullscreen=1
参数,但没有成功。不幸的是,您必须使用
。由于从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按预期运行时,object标签会持续出现“全屏不可用”的情况
或者你可以用这个:
<!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>
// 2. 此代码异步加载IFrame播放器API代码。
var tag=document.createElement('script');
tag.src=”https://www.youtube.com/iframe_api";
var firstScriptTag=document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(标记,firstScriptTag);
// 3. 此函数用于创建(和YouTube播放器)
//API代码下载后。
var播放器;
函数onyoutubeiframeapiredy(){
player=新的YT.player('player'{
高度:“390”,
宽度:“640”,
videoId:'M7lc1UVf VE',
活动:{
“onReady”:onPlayerReady,
“onStateChange”:onPlayerStateChange
}
});
}
// 4. 当视频播放器准备就绪时,API将调用此函数。
函数onPlayerReady(事件){
event.target.playVideo();
}
// 5. 当播放器的状态改变时,API调用此函数。
//该功能指示播放视频时(状态=1),
//玩家应该玩六秒钟,然后停下来。
var done=false;
函数onPlayerStateChange(事件){
如果(event.data==YT.PlayerState.PLAYING&&!done){
设置超时(停止视频,6000);
完成=正确;
}
}
函数stopVideo(){
player.stopVideo();
}
下面的示例HTML页面创建了一个嵌入式播放器,该播放器将加载视频,播放六秒钟,然后停止播放
希望对您有所帮助。不幸的是,您必须改用
。由于从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按预期运行时,object标签会持续出现“全屏不可用”的情况
或者你可以用这个:
<!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>
// 2. 此代码异步加载IFrame播放器API代码。
var tag=document.createElement('script');
tag.src=”https://www.youtube.com/iframe_api";
var firstScriptTag=document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(标记,firstScriptTag);
// 3. 此函数用于创建(和YouTube播放器)
//API代码下载后。
var播放器;
函数onyoutubeiframeapiredy(){
player=新的YT.player('player'{
高度:“390”,
宽度:“640”,
videoId:'M7lc1UVf VE',
活动:{
“onReady”:onPlayerReady,
“onStateChange”:onPlayerStateChange
}
});
}
// 4. 当视频播放器准备就绪时,API将调用此函数。
函数onPlayerReady(事件){
event.target.playVideo();
}
// 5. 当播放器的状态改变时,API调用此函数。
//该功能指示播放视频时(状态=1),
//玩家应该玩六秒钟,然后停下来。
var done=false;
函数onPlayerStateChange(事件){
如果(event.data==YT.PlayerState.PLAYING&&!done){
设置超时(停止视频,6000);
完成=正确;
}
}
函数stopVideo(){
player.stopVideo();
}
下面的示例HTML页面创建了一个嵌入式播放器,该播放器将加载视频,播放六秒钟,然后停止播放
希望这有帮助