A lazy way to write webpage components
At work I’ve been looking into how to play video in a browser reliably, and until both the world’s browser makers agree on supporting all common video formats and the institutions of the world move on to those modern browsers, you’re unfortunately stuck in the world of using something like Adobe Flash or Microsoft Silverlight to get multimedia content in your webpage. I’m all for HTML5 video, but as someone who has to deal with customers still stuck on IE6, it’s an ideal I can’t yet work with.
As part of some new features to Camvine webservice, I’ve been looking at how to play WMV and H.264 videos in a browser, and currently that means essentially using Silverlight – it has much better video support than Flash does currently, enabling me to produce a video plugin that’ll suit my needs. Or it would if I knew how to write any .net code.
This is the rub in doing web development – you need to be skilled in multiple languages at once. I’m already writing Python on the backend, and Javascript/HTML/CSS on the front end, and now I need to learn yet another language and set of frameworks just to play video? Or in my case, take an existing open source video player and make it do what I specifically need?
Perhaps not, thanks to a project called Gestalt, which both amazes and slight horrifies me at the same time :)
Gestalt essentially takes advantage of .net having support for two of the most common web development languages: Ruby and Python. It also takes advantage of something know as the DLR – Dynamic Language Runtime – to load code in .net applications as they run. Essentially, Gestalt lets you write Python and/or Ruby into your web page, just like you would Javascript, and then at run time dynamically places the code into a Silverlight plugin for execution without you having to do anything other than include some extra Javascript libraries. It’s amazing in both its technical swizzling and its simplicity to use.
So, if you use Python you could just start writing Silverlight style .net Python in your HTML like this:
<script type=“text/python”> import System def OnClick(s,e): window.Alert(“Hello, World!”)
document.say_hello.AttachEvent(‘onclick’,
System.EventHandler[System.Windows.Browser.HtmlEventArgs](OnClick))
</script>
And you can test this out here. Quite cunning, and very slickly implemented by the Gestalt guys – it’s very little effort (a few silly fixed paths in their code aside) to get up and running.
Now, I’m not about to throw away all my nice Javascript and use Gestalt with Python – although it’d mean one less language I’d still have to learn all the Silverlight frameworks, Gestalt seems a bit over the top for something that I can do natively in the browser. However, it does mean I can access the bits of Silverlight that can do things browsers can’t do (in my immediate case, play videos) by writing Python just like I’d write Javascript – no Visual Studio or other heavy tools required – it just fits into my existing workflow. Better yet, they’ve got some sample plugins for just this case that I’ve started to modify to suit my needs. It’s early days, but it looks like a great approach for such tasks.
- Next: Hipstamatic
- Previous: Engineered Skin
- Tags: Camvine, Geek, Python