Archive for the video Category

According to the Microsoft documentation, there are two dirty ways to catch such objects DOM events :

Here are two exemples using the "PlayStateChange" event :

HTML:
  1. <!-- integrate the WMP object -->
  2. <object id="Player" type="application/x-ms-wmp" width="300" height="200">
  3. <param name="URL" value="c:\MediaFiles\Seattle.wmv"/>
  4.  
  5. </object><!-- the first one -->
  6. <script for="Player" event="PlayStateChange(newState)">
  7. console.log("newState: " + newState);
  8. </script>
  9.  
  10. <!-- the second one -->
  11. <script>
  12. function OnDSPlayStateChangeEvt(newState) {
  13. console.log("newState: " + newState);
  14. }
  15. </script>

The two script tag properties "for" and "event" don't appear in the HTML standards, nevertheless that way works fine with Internet Explorer 6, 7 and Firefox 2, but doesn't with Firefox 3 .
The second one works on all those browsers, but a problem appears when several player instances are running. How to know which one has fired the event ?

An alternate way is using DOM level 2 events. However, the WMP plugin for Firefox doesn't fire its events in the DOM. Instead of it, the plugin probably look for matching script tags and eval the content it found.

Then, on Internet Explorer, and contrary to all other events in this browser, the ones from WMP objects are not prefixed by "on" (like "onMouseOut", "onClick" ...).
Since the javascript libraries like mootools or prototype follow that Microsoft "standard", their event listeners on DOM elements are useless.

So, the good syntax (which does work only with IE) is :

JAVASCRIPT:
  1. document.getElementById('Player').attachEvent("PlayStateChange",function(newState) {
  2. console.log("newState: " + newState);
  3. }

Click to continue reading

We had a really great camp at the Cantine on April 19th. More then 80 persons came from your friendly neighborhood drupal rockstar to people who just wanted to see what the fuss was all about. Great sessions and realy good atmosphere.

I'd really like to thank all those that came. First all of the French guys that were really cool about having the sessions in English so all of our international guests would be able to participate!

Then special Kudos to the Krimson guys and especially Joeri who did 3 sessions of introduction to Drupal, that people simply loved!
And lastly to the Drupal Core guys that came from all over the planet to hold the testing sprint and were nice enough to participate in some of the sessions and do a very informative sesssion on how to write tests for Drupal.

When I find time I will make a more detailed write up. So people if you have videos, session notes or photos please post them on your respective Blogs flickr Tags (drupalcampparis2) and such.

This whole thing started at the Boston DrupalCon.. so for those that weren't there .... and as a tribute, here is a short video of the Code Sprint at the MIT Stata Center on March 7th 2008 ...

Drupal Code Sprint MIT Stata Center

Click to continue reading

I looked for a nice clean class implementation in PHP for embedding videos from youtube and such and could not find anything that was nice enough. So here is my take on embedding videos in php.
As the embed code is reconstructed it should be safe enough put probably some more checks need to be done after extracting the id to see there is nothing hostile there.

Configuration:
This class requires the SpyC library to read the cobnfiguration file. The library is assumed to be in the SITEBASE/include/yaml/ directory.

PHP:
  1. define('SITEBASE', '/var/www/mysite'); // path to the root of the site (not forcefully public)
  2. define('VIDEO_EMBED_CONFIG_FILE', SITEBASE.'/config/video_embed.yaml'); //path of video embed config file
  3. define('DEBUG', true); //to activate debug mode and false for production usage. it will write to a log file when something goes wrong but should not produce exceptions in production enviroment

USAGE
note: The embed code may either be embed or url

PHP:
  1. $embed='http://www.youtube.com/watch?v=h2EUW_rgDVo';
  2. $videoEmbed = new VideoEmbed($embed); //optional width and height may be passed to the constructor
  3. print($videoEmbed->embed);
  4. $videoEmbed->width = 240; // resize
  5. $videoEmbed->height = 120;
  6. print($videoEmbed->embed); // resized video
  7. print($videoEmbed->thumb); // get thumb url

the other public properties are: ->id, ->type, ->url, ->width and ->height
note that magic getters and setters are used to make ->id, ->type, ->url read only

TODO: thumbnails should be cached locally
TODO: Create unit tests (for the moment test_VideoEmbed(); does some testing)

The video services are configured in the configuration file (video_embed.yaml), form:

---
embedTemplate: default embed template
defaultWidth: default width
defaultHeight: default height
services:
    servicename:
        urlPattern: pattern to distinguis between services
        embedUrlTemplate: template (used with sprintf) for construvting the player url
        thumbnailUrlTemplate: template to find thumnbail by video ID (used with sprintf)
        thumbnailUrlExtractPattern: if present the thumbnailUrlTemplate is assumed to be a text resource, and this is a regexp to extract the thumnbail from it
        extractPattern: regexp pattern to extract
        apiUrl: api url (not used for the currently supported services)
        defaultWidth: service default width
        defaultHeight: service default height
		embedTemplate: specific embed template (not used for the current supported services)

Example configuration file for google video youtube and dailymotion (if you configure it for other services please post the config)... :)

---
embedTemplate: <object width="%2$s" height="%3$s" ><param name="movie" value="%1$s"></param><param name="wmode" value="transparent"></param><embed src="%1$s" type="application/x-shockwave-flash" wmode="transparent" width="%2$s" height="%3$s"></embed></object>
defaultWidth: 425
defaultHeight: 350
services:
    youtube:
        urlPattern: youtube.com
        embedUrlTemplate: http://www.youtube.com/v/%1$s&rel=1
        thumbnailUrlTemplate: http://i.ytimg.com/vi/%1$s/default.jpg
        extractPattern: /youtube\.com\/(v\/|watch\?v=)([\w\-]+)/
        apiUrl: http://www.youtube.com/api2_rest
        defaultWidth: 425
        defaultHeight: 350
    google:
        urlPattern: video.google
        extractPattern: /docid=([^&]*)/i
        embedUrlTemplate: http://video.google.com/googleplayer.swf?docId=%1$s
        thumbnailUrlTemplate: http://video.google.com/videofeed?docid=%s
        thumbnailUrlExtractPattern: '/

And here is the code :Complete class code with readme and configuration file

The code referes to a debug function, you can use:

PHP:
  1. function debug_log($msg, $file = "debug")
  2. {
  3.     $dbg = "";
  4.     if (SITE != '[PROD]') {
  5.         $bts = debug_backtrace();
  6.         foreach($bts as $bt) {
  7.             $path = str_replace(SITEBASE, '', $bt ['file']);
  8.             $dbg .= $path . " line " . $bt['line'] . " (function " . $bt['function'] . ")\n";
  9.         }
  10.         $handle = fopen(SITEBASE . "/../log/{$file}.log", "a");
  11.         fwrite($handle, strftime("%Y-%m-%d %H:%M:%S  ") . $dbg . $msg . "\n------------------\n");
  12.         fclose($handle);
  13.     }
  14. }

Click to continue reading

Creative Commons License
This work is licensed under a Creative Commons Attribution 2.0 License.