gpt4 book ai didi

javascript - 将youtube视频嵌入网络获取 `Failed to load resource: net::ERR_CONNECTION_CLOSED`

转载 作者:行者123 更新时间:2023-12-03 06:11:43 24 4
gpt4 key购买 nike

// 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();
}
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>


将youtube视频嵌入到获取 Failed to load resource: net::ERR_CONNECTION_CLOSED的网络中。我从youtube开发人员文档 link复制了代码。但是我不知道为什么我会出错。但是我看到了正在播放的演示 link,我不明白为什么。还看到了这样的问题 link,它在 link中有一个演示,但也无法正常工作。

我能指出我应该去哪里吗?

最佳答案

您已将代码括在左括号和右括号之间,如下所示,对吗?找不到错误。应该可以...

<script type="text/javascript">
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag =
document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag,
firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '270',
width: '480',
videoId: 'nM82jzoJfjA',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.playVideo();
}
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done)
{
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
<div id="player"></div>

关于javascript - 将youtube视频嵌入网络获取 `Failed to load resource: net::ERR_CONNECTION_CLOSED`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51961309/

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