Iframe youtube always continues the video from the time it was last viewed #130607
Unanswered
DanDiaborn
asked this question in
Programming Help
Replies: 2 comments
This comment was marked as off-topic.
This comment was marked as off-topic.
-
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.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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