I use the YouTube API so that the buttons under my video change the start time based on some predefined text. When I call the method player.seekTo
, it works exactly as I expect, but it is not obvious to the user, something has changed. I would like the YouTube status to show the current time in the video in order to pop up in the same way as when changing the time by clicking on the time bar in the video.
Here is the code I'm using, as well as the page on which it works to help understand what I'm talking about.
https://www.siliconvalley-codecamp.com/Session/2017/everything-you-wanted-to-know-about-git-but-were-afraid-to-ask/Video
<script type="text/javascript">
var tag = document.createElement('script');
tag.id = 'iframe-demo';
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
let player;
function onYouTubeIframeAPIReady() {
player = new window.YT.Player('existing-iframe-example', {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onSetStartTime(startTimeInSeconds) {
player.seekTo(startTimeInSeconds);
}
API YouTube: https://developers.google.com/youtube/iframe_api_reference#Playback_controls