【发布时间】:2021-11-13 02:04:44
【问题描述】:
我有一个真实访问的网站,我想为 youtube 生成一个机器人视图。
我如何让用户通过点击我网站上的任意位置进入网站并播放 youtube 视频(隐藏)?
例如,我不能使用下面的代码,因为如果我使用自动播放,youtube 不算作视图
<iframe width="420" height="345" src="http://www.youtube.com/embed/oHg5SJYRHA0?autoplay=1" frameborder="0" allowfullscreen></iframe>
我是初学者,试了下面的代码,还是不行。
<html>
<head>
<title>Youtube br</title>
</head>
<style> #botYoutube { opacity: 0; position: absolute; right: 0; top: 0; } </style>
<body onclick="play()">
<div id="botYoutube"></div>
<script async src="https://www.youtube.com/iframe_api"></script>
<script>
var player;
function play(){
player.playVideo();
}
function onYouTubeIframeAPIReady() {
player = new YT.Player('botYoutube', {
videoId: 'x5MhydijWmc', // YouTube Video ID
width: 10, // Player width (in px)
height: 10, // Player height (in px)
playerVars: {
autoplay: 0, // 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: 0 // Hide video controls when playing
},
events: {
onReady: function(e) {
e.target.mute();
}
}
});
}
</script>
</body>
</html>
我用谷歌翻译来问这个问题!
谢谢
【问题讨论】:
-
您的要求违反了 YouTube 的服务条款。
标签: javascript html css youtube