Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

where to pass arguments of postMessage command to youtube iframe

$
0
0

Sorry if this looks like a repost of an earlier problem of mine, but it isn't.It's a different problem of a different approach.

I've got this iframe:

<iframe id="video1" width="970" height="546" src="https://youtube.com/embed/9IYRC7g2ICg?enablejsapi=1&autoplay=1&controls=0&loop=1&playlist=9IYRC7g2ICg&showinfo=0&modestbranding=0" frameborder="0" allowfullscreen></iframe>

Now to manually pause the video when clicked on a custom button, this works fine:

<script type="text/javascript">    jQuery(document).ready(function($) {        $('#button1').click(function() {            $('#video1')[0].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');        });    });</script>

pauseVideo is a command listed here https://developers.google.com/youtube/iframe_api_reference.

My question is: i'm somehow completely unable to use commands that expect arguments, for example seekTo(seconds:Number, allowSeekAhead:Boolean).

For jumping to 0:20 in the video, I tried:

$('#video1')[0].contentWindow.postMessage('{"event":"command","func":"seekTo","args":"20, true"}', '*');

but with no success.I'm probably putting the arguments in the wrong place, since this is the first time I'm working with the postMessage function for iframes and I kinda feel a bit newbie-like in that sense.

Could anybody help me? :)


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>