gpt4 book ai didi

javascript - YouTube IFrame Player API缩略图未显示

转载 作者:行者123 更新时间:2023-12-03 06:22:04 25 4
gpt4 key购买 nike

我有这段代码可以为我的youtube视频创建iframe
但我不确定如何显示缩略图,就目前而言
显示一个黑框,然后单击它开始播放视频。

我尝试了player.cueVideoById('eJSik6ejkr0',0,'highres'),但还是没有。

知道如何处理才能显示缩略图吗?

谢谢

        player = new YT.Player('player', {
height: '475',
width: '100%',
videoId: 'eJSik6ejkr0',
playerVars: { 'rel': 0, 'modestbranding': 1, 'autoplay': 1, 'controls': 0 },
events: {
'onStateChange': onPlayerStateChange
}
});

最佳答案

这是Youtube Player API中给出的示例,可以正确显示缩略图。但是,某些内容提供商会将Playblack限制在某些网站上,因此您可能会获得缩略图。使用您的videoId,我在中间出现了一条黑框,显示以下消息:This contains content from VEVO. It is restricted from playback on certain sites

< !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>

关于javascript - YouTube IFrame Player API缩略图未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33171680/

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