Get YouTube video embed code with getVideoData().video_id <p>I have a page that loads <strong>several</strong> youtube videos and should do something when a video is paused.</p> <p>So I have a test function that catches the pause event...</p> <p>I need to make it <strong>dynamic</strong> (the function should by itself recuperate the ids of frame and the video that calls that function).</p> <p><a href="http://codepen.io/serhio/pen/pyRYNP" rel="nofollow">HERE THE WORKING CODEPEN</a></p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var player; function floaded(iframe) { // how to recuperate the video ID? player = new YT.Player(iframe.id, { videoId: 'amDMGIyyrlw', events: { 'onStateChange': function(event) { if (event.data == YT.PlayerState.PLAYING) { alert("Playing.."); } else if (event.data == YT.PlayerState.PAUSED) { alert("Paused.."); } } } }); }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;h2&gt;Pause this video: &lt;/h2&gt; &lt;div style="width:250px"&gt; &lt;div class="video-container"&gt; &lt;iframe id="test456" src="https://www.youtube.com/embed/amDMGIyyrlw?enablejsapi=1" onload="floaded(this)"&gt; &lt;/iframe&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>The frame id is easy to recuperate from the iframe object: <code>iframe.id</code></p> <p>But the main problem is the video id... From the <strong>onStateChange</strong> event is very easy to recuperate the video embeded code: </p> <pre><code>?event.target.getVideoData().video_id "amDMGIyyrlw" </code></pre> <p>However is too late in the event, cause I need it before, when only creating the player object...</p> <p>I know there is ways to recuperate the video embedded code by a regular expression. </p> <p><strong>However is there a way to use the <code>getVideoData().video_id</code> to recuperate the video id dynamically?</strong></p>