I am trying to get users to search for specific videos using YouTube using the following function:
function setCurrentTime(slideNum) {
var object = <?php echo json_encode($matches); ?>;
if ('seekTo' in player.trackingVideoId){
var seekTime = object[0][slideNum];
player.trackingVideoId.seekTo(HHmmssToSeconds(seekTime));
}
}
Where
var object = [["00:00:00","00:01:07"],["00","00"],["00","01"],["00","07"]];
player.trackingVideoId = new YT.Player('trackingVideoId');
<iframe id="trackingVideoId" type="text/html" width="340" height="210" src="https://www.youtube.com/embed/D77wXvwChtU?enablejsapi=1" frameborder="0"></iframe>
<input type="button" value="Seek" onclick="setCurrentTime(1)">
It works fine and sometimes does not work, and the following error appears (in firefox consol):
TypeError: invalid 'in' operand player.trackingVideoId
if ('seekTo' in player.trackingVideoId){
and when commenting on the conditions if ('seekTo' in player.trackingVideoId){
The following error will appear
Uncaught TypeError: Cannot read property 'seekTo' of undefined
update:
I initialized it - as in your link - to onYouTubeIframeAPIReady (). However, I placed setCurrentTime (slideNum) outside the onYouTubeIframeAPIReady () function, I tried to put it inside, there is another error that setCurrentTime is not defined.
I try to find a specific time when the user clicks a button
<input type="button" value="Seek" onclick="setCurrentTime(0)">
You can try @ http://ilstream.com/video_slides/video_slides.php