Embedded Video How To - Start Youtube mid-video

Here is a simple trick that I learned while creating a small, fun video site on a whim. The main problem is that we wanted to start some Youtube videos at a specific interval in the video, say 30 seconds in. We were already use the Embedded Media Field set of modules of CCK (http://drupal.org/project/emfield, with the video/youtube addon modules), but mid-video starts aren't supported (yet as I will submit a patch shortly to add this functionality to the options array).

I will write more about the full site build at a later time, but here is what I did to tackle this issue. I am assuming that you are familiar with CCK, EM Field modules and a bit of knowledge to theme a node template.

Here is what I did:

1) Create the embedded video field for youtube ('field_song_video' in my implementation).
2) Create am integer field to hold the number of seconds into the video to start ('field_song_start' in my implementation).
3) Remove from Display on the node both of these fields.
4) Updated my node-songs.tpl.php (replace with your appropriate node template file).
5) Where I wanted my video to be embedded I placed the following code:

<?php print theme('emvideo_youtube_flash', $node->field_song_video[0]['value'] .'&start='.$node->field_song_start[0]['value'], 450, 350, 0); ?>

The main part to notice is the '&start=...' part. The theming function for the youtube player will add the start variable to the Youtube request URL which will start the video at a later place than the beginning. The other arguments are the size of the player (450px by 350px) and the auto-start flag.

NOTE: The API has changed a bit since my site implementation so the new code would look like this (replace 'emvideo_youtube_flash' with 'video_cck_youtube_flash').

<?php print theme('video_cck_youtube_flash', $node->field_song_video[0]['value'] .'&start='.$node->field_song_start[0]['value'], 450, 350, 0); ?>