我有一些YT视频可以在VB Webbrowser中播放,但播放它会给我'这个视频包含来自VEVO的内容。它限制在某些网站上播放或应用程序错误。但是当我尝试使用Youtube链接本身提供的默认嵌入代码来播放它时,它可以很好地播放。例如:
<iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>
在自定义HTML页面上,这是我使用的代码
function main(vidid)
{
// 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;
window.onYouTubeIframeAPIReady = function() {
player = new YT.Player('player', {
height: '200',
width: '300',
playerVars: {
autoplay: 1,
enablejsapi : 1,
origin: "https://www.youtube.com",
vq: 'medium'},
videoId: vidid,
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();
}
}
是否有我遗漏的内容,或者视频是否仅为API用户屏蔽?如果我的问题太糟糕,我道歉。
答案 0 :(得分:1)
找到问题的根源。事实证明我在PC上托管了网页,而Youtube不允许这样做。将我的html页面上传到Web服务器之后,它完美运行。