如何跳过Youtube iframe生成的播放列表中不可用的视频



我正在尝试制作一个简单的全窗口HTML文档,它可以一个接一个地播放来自一个频道的所有视频。有时,iframe中会有一个视频不可用,它位于"上;视频不可用,在youtube上观看";。如何使播放列表跳过这些视频并继续?我正在努力获得电视频道效果,为壁纸引擎。整个代码是:(旧版本(

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Layout</title>
<style type="text/css">
body, html
{
margin: 0; padding: 0; height: 100%; overflow: hidden;
}
</style>
</head>
<body>
<iframe id="ytplayer" type="text/html" width="100%" height="100%"
src="https://www.youtube.com/embed?listType=user_uploads&list=GameTrailers&autoplay=1&loop=1&showinfo=0&fs=0&color=white&disablekb=1&modestbranding=1&controls=1&rel=0&mute=1"
frameborder="0"></iframe>
</body>
</html>

以下是Benjamin Loison的更新版本链接:

<html>
<head>
<title>Test Layout</title>
<style type="text/css">
body, html
{
margin: 0; padding: 0; height: 100%; overflow: hidden;
}
</style>
</head>
<body>
<div class="container">
<div id="muteYouTubeVideoPlayer"></div>
<script async src="https://www.youtube.com/iframe_api"></script>
<script>
function onYouTubeIframeAPIReady() {
var player;
player = new YT.Player('muteYouTubeVideoPlayer', {
width: 1366,               // Player width (in px)
height: 768,              // Player height (in px)
playerVars: {
listType:'user_uploads',
list: 'GameTrailers',
autoplay: 1,        // Auto-play the video on load
controls: 1,        // Show pause/play buttons in player
showinfo: 0,        // Hide the video title
modestbranding: 1,  // Hide the Youtube Logo
loop: 1,            // Run the video in a loop
fs: 0,              // Hide the full screen button
cc_load_policy: 0, // Hide closed captions
iv_load_policy: 3,  // Hide the Video Annotations
autohide: 1         // Hide video controls when playing
},
events: {
onReady: function(e) {
e.target.mute();
},
onError: function(e){
e.target.nextVideo();
e.target.playVideo();
}
}
});
}
</script>
</div>
</body>
</html>

我现在只需要弄清楚如何使这个窗口100%适合,而不是设置像素宽度,这是我正在努力解决的问题。

width值切换为window.innerWidth(而不是1366(,将height切换为window.innerHeight(而不是768(。下次请你自己加深更多,我在StackOverflow上搜索得到了你所有的答案。。。

最新更新