How to get the embed HTML code for a video hosted in youtube programmatically. What Java API is available
Advanced users: Pressing F3 will also show you the source code. In Chrome, the short-key for Inspect is CTRL+SHIFT+I.
You can find the embed code by going to the YouTube play page, clicking "Share" and then "Embed." You can then copy the embed code, as well as customize a few options.
Use the YouTube Data API (there's pre-built GData client libraries, or you can do the HTTP/XML stuff yourself).
One of the <media:content/>
entries will contain a URL for the embeddable SWF, if the video is embeddable.
Assuming you have the URL of the video, it's fairly simple to generate one. You need the end of the URL (the part after the /watch?v=, let's call it ID). To generate the iframe embed html, just place it in the appropriate place (in the src attribute, don't include the brackets):
<iframe title="YouTube video player" class="youtube-player" type="text/html" width="640"
height="390" src="http://www.youtube.com/embed/{ID}" frameborder="0"
allowFullScreen></iframe>
There are a couple of ways to get the v parameter from the URL. A regular expression would work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With