Iframe youtube always continues the video from the time it was last viewed #130607
Replies: 2 comments
-
Hi Dan, <iframe id="youtube-video" width="560" height="315" src="https://www.youtube.com/embed/Y-P9tNkTLXw?si=1VXDflMvbTApKwhg&start=300&autoplay=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>In this example, the video will start playing from 300 seconds (5 minutes) and will not rewind back to the previous playback position. Have a good day! |
Beta Was this translation helpful? Give feedback.
-
If you want your YouTube video to always start playing from a certain moment, you can leverage the YouTube IFrame Player API. You can ensure that it always starts at the specified time by initializing the player and setting its start time programmatically. <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube Video Player</title>
<script src="https://www.youtube.com/iframe_api"></script>
</head>
<body>
<div id="player"></div>
<script>
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '315',
width: '560',
videoId: 'XXXXX',
playerVars: {
'start': 300,
'autoplay': 1,
'controls': 1,
'rel': 0
},
events: {
'onReady': onPlayerReady
}
});
}
function onPlayerReady(event) {
event.target.seekTo(300);
event.target.playVideo();
}
</script>
</body>
</html> |
Beta Was this translation helpful? Give feedback.
-
Body
When loading for a second, playback starts from 300 seconds and then rewinds back to the moment at which you finished watching the last time.
How can I make it play from a certain second?
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions