Flash Media Server 3.0 is out

Flash Media Server 3.0 is out, check out. It seems, licensing has got easier and better.
BTW! Who cares about FMS when we have Red 5 as an option ;-)

Technorati tags: , streaming, , fms

Getting Dailymotion Video (FLV) URL

Some developers asked me, if it is easy to get dailymotion flv URL? I thought, I would post how to do that.

If you know the dailymotion video-id, believe me it's very simple to do that. In case, you don't know how to get dailymotion video-id?  Let me give you some hints, highlighted text is the video-id:-

Once you have video-id, you can use the following php-script (dailymotion.php.txt) to do either of two things:-

  • Get flv and thumbnail-url
    • http://yourserver/dailymotion.php?video_id=&redirect=false</li>
      • Returns: flv=thumbnail= </li> </ul> </li> </ul>
      • Redirect to dailymotion flv-url directly. It can be used directly from Netstream's play () instance method
        • http://yourserver/dailymotion.php?video_id=&redirect=true</li>
          • Redirects (HTTP 303) to flv_url.
          </li> </ul> </li> </ul>


          // Above invocation would return:-
          // flv=&thumbnail=
          // Example:-
          // URL: http://server/dailymotion.php?video_id=x44ls3&redirect=false
          // Result:-
          // flv=http://www.dailymotion.com/get/15/320x240/flv/6933315.flv?key=69f63205c80b5b5d188a10e0b7656a421316ee3&previewURL=http://limelight-315.static.dailymotion.com/dyn/preview/320x240/6933315.jpg?20080122041
          // 2) For redirection to flv i.e. video_id to flv
          // http://server/dailymotion.php?video_id=&redirect=true
          // Above invocation would redirect to dailymotion flv URL
          if (isset ($_GET ['video_id']) == FALSE)
          echo "video_id is required";
          // Requires dailymotion video_id
          $url = 'http://www.dailymotion.com/swf/' . $_GET['video_id'];
          if (isset($_GET['redirect']) == FALSE)
          $redirect = 'true';
          //Start the Curl session
          $session = curl_init($url);
          curl_setopt($session, CURLOPT_HEADER, true);
          curl_setopt($session, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20071025 Firefox/');
          curl_setopt($session, CURLOPT_FOLLOWLOCATION, false);
          curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
          // Make the call
          $response = curl_exec($session);
          $error = curl_error($session);
          $result = array( 'header' => '',
          'body' => '',
          'curl_error' => '',
          'http_code' => '',
          'last_url' => '');
          if ( $error != "" )
          $result['curl_error'] = $error;
          $header_size = curl_getinfo($session,CURLINFO_HEADER_SIZE);
          $result['header'] = substr($response, 0, $header_size);
          $result['body'] = substr( $response, $header_size );
          $result['http_code'] = curl_getinfo($session, CURLINFO_HTTP_CODE);
          $result['last_url'] = curl_getinfo($session, CURLINFO_EFFECTIVE_URL);
          list($header,  $result['header']) = explode("\n\n",  $result['header'], 2);
          $matches = array();
          preg_match('/Location:(.*?)\n/', $header, $matches);
          $urlInfo = parse_url(trim(array_pop($matches)));
          //$newUrl = $urlInfo['scheme'] . '://' . $urlInfo['host'] . $urlInfo['path'] . ($urlInfo['query']?'?'.$urlInfo['query']:'');
          parse_str($urlInfo['query'], $output);
          $flvURL = $output ['url'];
          $thumbnailURL = $output['previewURL'];
          if ($redirect == "true")
          header ("Location: ". $flvURL, TRUE, 303);
          echo sprintf ("flv=%s&thumbnail=%s", $flvURL, $thumbnailURL);


          Let me tell you, you can do the entire thing on client-side without using any server-side script, though logic remains same. Look at this post and learn what technique to use :-). Another hint, if you are consuming dailymotion rss-feed(s), you don't need any php script to construct flv-url, you can just replace "80x40" text by "320x240" in media:content url.

          As always, please look at the code, change, optimize and fix it to meet your requirements. I wrote it in ten minutes and just as a proof-of-concept, this is no way the best method and php-code can be much better.

          Technorati Tags: , ,

as3httpclientlib - a better http-client in ActionScript by Gabe

Gabriel Handford left a comment with as3httpclientlib link, this is a very well written http-client, with TLS support, in ActionScript 3.0.

Let me clear some points here, as3httpclientlib is not as3httpclient. The as3httpclient, let's call it my-project in rest of the post, was a better version of HTTPURLLoader. HTTPURLLoader was a proof-of-concept work to deal with various limitations in Flash Player APIs.

my-project doesn't have cleaner api and it also lacks various thing, honestly speaking, I could never spend enough time to make it better. Thanks to Erik (aka eecolor) for refactoring HTTPURLLoader and adding more features.

I was planning to add TLS support, after I heard about Metal Hurlant's work on TLS. Now, I am not planning to do any further work on my-project (as3httpclient) except cleaning the code a bit for those who are already using it.

I find, as3httpclientlib (Gabe's project) is much better and very complete. I spent sometime looking at the code base, it's api reminds me of jakarta-commons-httpclient, which I always liked for it's simplicity. With as3httpclientlib, you can do pretty much everything (DELETE, GET, HEAD, POST, PUT - http-methods, multipart uploads etc) you were able to do with my-project (as3httpclient).

If you have been using my-project (as3httpclient), I suggest you to look at as3httpclientlib.

As we know, Flash Player Socket API has some security-restrictions, so any socket based http-client would work for AIR projects but not for Flex projects, unless you can afford special-setup on your server to serve special policy-file required for socket-connection to any port below 1024. Gabe has developed as3httpclientlib library for AIR based projects, however, I am sure it can be used in Flex projects as long as server is setup (as mentioned above in this paragraph).

Check out various examples/tests in as3httpclientlib project, you would find things like amazon-s3-tests, upload-tests etc

Thanks for reading a post full of similar names - as3httpclient and as3httpclientlib :-)

Technorati tags: , , , , , ,

Flex framework has God objects?

Adobe Flex framework has God Objects, UIComponent is one those. I am not sure, if there is something called God methods, but there are some methods which either do/assume more. Manish's post shows one such case and you can figure out more by looking at the code ;-)
Flex 4 is going to be better.

Silverlight and HTTP API

While talking to Arul about various limitations (a few HTTP methods/verbs supported) in Adobe Flash Player's HTTP APIs (URLLoader/URLStream etc) and my previous posts, he suggested me to look at Silverlight, what kind of support it has got?

I don't know, if I can develop Silverlight applications on MacOSX, I would figure out a way using Mono/DotGNU later? But for now, I searched MSDN and quite surprised to see it does support more HTTP methods (DELETE, GET, POST, PUT), at-least in some Silverlight Streaming HTTP package? That means, it's easier to deal with REST web-services.

Thanks to Arul for giving this idea, I am going to spend sometime playing with Silverlight and try to compare the both Adobe Flash and Silverlight platforms, I am sure that way I can file more enhancement requests for Adobe Flash Player to make it better platform, yup! I love it and want it to be better and better over the time.

Technorati tags: , ,

Videos: Discipline in Thought by Dijkstra

A couple of months back, my manager sent us a video-link - "Discipline in Thought" by Dijkstra. After watching video, I thanked my manager for sharing the link. I noticed, next two part of series are now available, I thought of sharing it with you all.

It's worth spending sometime to watch these videos:-

Discipline in Thought - Part 1
Discipline in Thought - Part 2
Discipline in Thought - Part 3

Many of us would disagree on some points in the video, one of them is about not using iterative-development or ship complete product instead of dot releases etc. I am going to think about it and probably post my views in upcoming post (s), I have something to write about Apple and MS, kind of related to some points in the first video.

Technorati tags: ,

ECR for Flash Player: Allow Socket connection to HTTP servers without special setup

This is for Adobe Flash Player team, specially security guys, please allow us (developers) to use Socket API in creative ways, beyond you permit us. Atleast, for same-origin (domain), we don't need to have special policy file to allow socket-connection over http-port (80) or ssl-port (443)? This is totally doable?
Please, please tell us why don't you let us do it now?

Update (Jan 20, 2008): I filed an enhancement-request in Adobe JIRA bug-base. Vote for this enhancement, if you think it's useful. You can vote by visiting the following link:


Query-string in SWF URL is not good idea

Query-string in SWF URL is bad idea because swf would be downloaded again by browser/client instead of being loaded from browser-cache, it happens if URL becomes non-unique due to the presence of changing query-string in different requests.

Browser does cache data for all URL, unless HTTP response headers (for URL or other resources) instruct not to do caching. If URL is different, browser considers it a new requests and downloads the data again instead of consuming from cache.

We can try to avoid or optimize such cases. In past, developers have used the other way by having random (non-unique) query-string in SWF or XML/asset URL to force reloading of asset/resource instead of using the ones from browser-cache. Though, they could have done things by setting right HTTP headers.

I have noticed some websites where swf URL has a query-string i.e. http://yoursite.com/yourapp.swf?var1=somedata, where value of var1 is not constant rather changes? Obvious reason, I want to pass dynamic data most of time hence using query-string instead of hard-coding it in swf itself.

I also noticed some sites which are using SWFObject and still passing data via query-string instead of flashvars using addVariable (..) instance method of SWFObject.

Another place, I again noticed something similar, AVM+ application loads AVM- (SWF 8 or less) application, let's call it legacy-swf, and passes data via query-string, ok, that is understood there is no other way except writing a light-weight wrapper that uses LocalConnection or query-string approach?

  • It might not be worth writing wrapper in case of small-size legacy-swf but depends, if you are serving to thousands of users, every single HTTP request cost something.
  • If legacy-swf is large enough, it's worth writing a wrapper that loads the legacy-swf. This way at least legacy-swf would be loaded from browser cache in next session instead of being downloaded again from your server.

This is very basic thing in web-application development, user-experience can be improved by doing these little things. I hope to write some more observations, no matter how stupid/trivial it sounds to me or other programmers. It's good to post these things in context of flash/flex so beginners, who are not familiar with details of HTTP or other standards, can learn.

Technorati tags: , , , ,

Flash Platform (flex/flash/air/actionscript) blogs from India

I have been maintaining a list of flex/actionscript/air bloggers on flex_india group. I updated the list today and I would be updating it again next week.

It's nice to see more developers from India are blogging and sharing their knowledge with everyone. There are ( and always have been) very smart and cool developers in India but generally they maintain a low-profile or too busy with work or shy.

Check out the following list, I have used the names of bloggers instead of blog-title because it was for me to do so.

Flex/Flash/AIR bloggers from India

ActionScript compiler in ActionScript

Another interesting project from Metal, he has ported ActionScript compiler (which is part of Tamarin project) to an ActionScript 3.0 library.

He is still working on it, however, he has posted a demo and current version of code. I am sure, this would be pretty useful. I remember of reading a thread on flexcoders about creating mock-objects in ActionScript 3.0, eval-project might prove useful there.

Technorati Tags: , ,