Embedding YouTube videos from Action Streams

The next logical step from displaying a thumbnail of your posted or favourite videos is to actually enable playing of the video in your own webpage.  Thankfully, this is simple with youtube's embed code and your Action Stream.  I've now added this to my video calendar page and i think it looks good and works rather well.  It may be a little to much to add it to the home page, plus we don't want that to slow down any, it's already having to grab resources from all over the place anyway, so adding 9 embedded videos may be a little too much!

Code after the jump..


Simply add the following ot your template to display videos embedded on the page:

<mt:if name="service_type" eq="youtube">
<mt:SetVarBlock name="videoid"><$MTStreamActionURL regex_replace="/http:\/\/www\.youtube\.com\/watch\?v\=/","" $></mt:SetVarBlock>
<object width="320" height="265">
<param name="movie" value="http://www.youtube.com/v/<mt:var name="videoid">&hl=en&fs=1&rel=0"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/<mt:var name="videoid">&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="265"></embed>
</object>
</mt:if>
This grabs the actual video id from the StreamURL and sticks it into the standard embed html that each video provides.  You can adjust the sizes, I find the easiest way to make sure you get it proportional is to actually go to a video on youtube, select the embed and customise options then view the code it outputs.  From this you can work out what to change in the above code to add related videos, changel colours, add a border etc etc.

Leave a comment

Recent Entries

  • YUI Editor in Movabletype v1.3

    A new version of the YUI Rich Text Editor in MovableType is available, this version adds a new button to your toolbar that will search...

  • Adding YUI RTE in MoveableType Community Solution

    On certain sites, you may want to allow your users a little more freedom with their comments, or if you're using the community templates in...

  • YouTube lightbox

    For a while now I have been toying with making my own JavaScript libraries built around the YUI libraries, as there were things out there...

  • New Host

    After the balls up the other day, I've been rushing to get the site transferred over to a new host and sort out the templates,...

  • I've been a fool!

    Made a classic, school-boy error last night...Was moving a movabletype installation from 2 recently decommissioned dedicated servers to a cloud hosting environment and noticed that...