ActivePresenter Saola Animate Pricing Download

AP - pause youtube video with button

Hello,
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:
document.getElementsByClassName(‘ytp-play-button’)[0].click();
and this
document.getElementsByTagName(‘YouTube_3’)[0].pause()

but I guess I need something more like the below?
var Saola = prez.object(‘Web Object_7’).frameNode.contentWindow.AtomiSaola;
var saolaDoc = Saola.topDocs[0];
saolaDoc.getTimeline(‘Timeline’).pause();

I will keep trying but any help is welcome!
Thanks
Michael

Hi Michael,

Unfortunately, there is no way for you to do that.

Regards,
Hang

Hi,

Thanks.
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?
Reagrds,
Michael

Hi Michael,

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
  ytPlayer.pauseVideo();
else if (playerState == 2) // paused
  ytPlayer.playVideo();

Regards

Hi,

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!!
Michael