我无法在要放到HTML网站上的视频中添加自动播放功能。添加?autoplay = 1或&autoplay = 1无效。 -与循环相同
<div class="videoContainer">
<iframe class="videoContainer__video" width="560" height="315" src="https://www.youtube.com/embed/HWl8XAOQnTg?rel=0&controls=0&showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen> </iframe>
</div>
答案 0 :(得分:0)
您好,我的朋友,您可以找到正确嵌入youtube视频的正确步骤;
要允许视频自动播放,请使用此allow="autoplay; encrypted-media"
并在代码中添加autoplay=1
。按照上述步骤,首先通过youtube嵌入视频,然后将autoplay=1
添加到视频网址中。
我知道您已经说过您已经尝试添加<script>
//var variable = <?php echo json_encode($_SESSION['abc']); ?>;
</script>
,但这可能会帮助您按照我的步骤重试。让我知道你过得怎么样。
答案 1 :(得分:0)
在这里使用: 打开下面的代码笔链接 它也会循环播放您的视频:(运行视频的缓存版本,查看@Turnip Comment)
;&autoplay = 1;&loop = 1;&playlist = HWl8XAOQnTg
https://codepen.io/GAUTAMRAJU15/pen/MqLJRa
<iframe class="videoContainer__video" width="560" height="315" src="https://www.youtube.com/embed/HWl8XAOQnTg?rel=0&&showinfo=0;&autoplay=1;&loop=1;&playlist=HWl8XAOQnTg"> </iframe>
答案 2 :(得分:0)
不依赖似乎不适用于我的参数-2018年9月的解决方法(奖金:通过CSS为#yt-wrap
设置宽度和高度,而不是在JS中对其进行硬编码):
<div id="yt-wrap">
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="ytplayer"></div>
</div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_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 onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
width: '100%',
height: '100%',
videoId: 'VIDEO_ID',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
player.mute(); // comment out if you don't want the auto played video muted
}
// 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.
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
player.seekTo(0);
player.playVideo();
}
}
function stopVideo() {
player.stopVideo();
}
</script>