Monday, January 2, 2012

[YouTube-API] Loading a dynamic playlist into SWFObject at page/embed load

Hi folks, first post, love the API.

Background: Links to youtube videos that are posted to an IRC chatroom are scraped by a bot, then added to a comma-delimited server-side txt file of video IDs.  Ideally, when the site loads, the embedded SWFObject will automatically load the playlist file IDs, effectively playing the latest videos linked from the chatroom.  Currently I cannot get the SWFObject to *start* with the loaded playlist, though setting the playlist with a Javascript href works fine.  Source is available on this page (please excuse the political content, if it's not your thing):

http://eggage.info/ronpaul/

This link is attached to the Big Red "top videos" button at the top of the page...

<a href="javascript:ytplayer.loadPlaylist({id:ytplayer,playlist:'<?php echo file_get_contents('playlist.txt'); ?>'})"><img src="../img/playlist.jpg"></img></a>

... and works as expected.  However, I can't seem to find a way to get the SWFObject to accept a .loadPlaylist() call immediately when it loads, which results in the object loading a single static (hard-coded) video initially, and requiring the user click the above link to load the dynamic playlist, to see the latest videos.

I suspect that I'm simply not understanding how the SWFObject loads, or maybe I'm attempting to use the loadPlaylist() finction before the player is ready.  For example, this doesn't work...

<body onload="javascript:playlist();">

... where playlist() is a JS function that essentially performs the same call as the href loadPlaylist() function in the first link.  This fails silently.

Can anyone provide insight into what I'm doing wrong?  Does SWFObject not support PRE-loading a list of video IDs?  Does SWFObject issue a callback function when it is loaded and ready to accept commands, so that I could place the playlist loading logic in the callback?  Any tips are greatly appreciated, and Thanks In Advance.  :)

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To view this discussion on the web visit https://groups.google.com/d/msg/youtube-api-gdata/-/dPaop4T4maoJ.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.

No comments:

Post a Comment