I was not very happy about the existing implementation for displaying multimedia content in the aggregator. It only supported a few media formats and was pretty much hard-coded. I decided it deserved something better.
I was already using the browser widget to present the article content.
Since this would in practice be an embedded XUL runner, Firefox or MSIE it should already be capable of presenting a variety of media formats as long as a suitable plug-in has been installed. The problem is that RSS feeds with multimedia content typically look something like this:
<item> <author>rss@youtube.com (avrtvtube)</author> <title>AVR saves aviator lives</title> <link>http://youtube.com/?v=h2XBsPASik8</link> ... <media:player url="http://youtube.com/?v=h2XBsPASik8" /> <media:thumbnail url="https://i1.ytimg.com/vi/h2XBsPASik8/default.jpg" width="120" height="90" /> <media:title>AVR saves aviator lives</media:title> <enclosure url="http://youtube.com/v/h2XBsPASik8.swf" duration="296" type="application/x-shockwave-flash"/> </item>
Notice that there is no code to format the media element in the browser and there is no guarantee that the browser could figure out what to do simply on the basis of the URL.
The solution I ended up with is quite simple: Detect the media type of the content, match it against a database of content handlers and generate suitable HTML code to wrap around. Now, this database must be easily maintainable and it must use a flexible, open format. What could be better than the Eclipse extension point mechanism?
The following is an example of a content-handler declaration that handles the example shown above.
<extension point="no.resheim.aggregator.core.ui.contentHandlers"> <handler name="Flash animation" suffix="swf" type="application/x-shockwave-flash"> <code> <body style="margin:0px;"> <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="100%" HEIGHT="100%"><PARAM NAME=movie VALUE="${content}"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="${content}" quality=high bgcolor=#FFFFFF WIDTH="100%" HEIGHT="100%" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT></body> </code> </handler> </extension>
Note that the “<” and “>” characters inside code
are normally escaped. They are shown here for readability
Basically you declare a handler with a name, MIME type and file name suffix followed by the HTML code required to embed the player inside a web page. The ${content}
string will in this case be replaced with the enclosure URL.
This feature is now used to the full. All content shown in the aggregator is rendered in this way. The Eclipse extension point mechanism has once again shown it’s value.