I’m embedding a youtube video in a presentation and I would like to pause it when a user clicks an AP button and play again when he clicks another button.
Is there something similar to this command which would work for youtube?
I tried this:
but I guess I need something more like the below?
var Saola = prez.object(‘Web Object_7’).frameNode.contentWindow.AtomiSaola;
var saolaDoc = Saola.topDocs;
I will keep trying but any help is welcome!
Unfortunately, there is no way for you to do that.
Just to be sure:
isn’t there a way I could simulate by code a click on the object? If I manually click the object (anywhere) it pauses/play.
or possibly simulate the “k” key youtube shortcut for pause?
If the object is playing and I hit “k” it pauses… so if I could send a keyinput command via the script?
Youtube doesn’t allow cross-domain access to its content so you can’t simulate a click or key stroke to play/pause the video.
However, I found out that Youtube allows to get the video player from the iframe, so you can get the player and control the video.
var ytIframeId = $(prez.object('YouTube_1').node).find('iframe').attr('id');
var ytPlayer = YT.get(ytIframeId);
var playerState = ytPlayer.getPlayerState();
if (playerState == 1) // playing
else if (playerState == 2) // paused
this works perfectly !
FYI - I added a
if(playerState == 5) ytPlayer.playVideo();
to enable the first start (when the youtube video has not yet been clicked once/started) on the click of another button.
Thanks a lot!!