Saturday, March 26, 2011

Advanced mediaservice and plugins. Part II: mediaservice

"Welcome the task that makes you go beyond yourself." (Frank Mcgee) [1]

...and also welcome back to this second part of Advanced mediaservice and plugins. In the first part, I introduced the the interface each plugin must implement and also showed how to write a provider plugin for the mediaservice. In this part I will show a little bit of what has been done so far and talk about further plans.
But first something I forgot to mention in the previous post.
Since we know now how to build the skeleton of our little plugin called MyProvider we still cannot tell what it should do. For that matter the mediaservice comes with some libraries that helps you query your provider more easily.

  • The file stdutils.js has some functions that makes it easy to do requests and build urls.
  • mediaapi.js contains the whole API for media and mediacollections. An error API was added for better error handling.

  • xmldom.js, xmlsax.js and xmlw3cdom.js are libraries that are able to parse xml documents. Since (right now) all of the plugins receive xml documents from their providers, these libraries are the ones parsing them. For more documentation about the xml libraries see [3].
If we pick up our example MyProvider again, the requesting and receiving information would look like this:

MyProvider.prototype.searchMedia = function(queryParams)
  // get the paramters from the service
  var text = queryParams['text'];
  var maxResults = queryParams['max-results'];
  var page = queryParams['page'];
  // build the url, result will be:
  var url = buildUrl("",
       "text" : text,
       "per-page" : maxResults,
       "page" : page

  // we want to save the response
  var result = "";
  // make the request
  doRequest(engine, url, 
    function(job, data)
       result += data.valueOf();
      // showing the result in the terminal
      // parse result here with the xml libraries
The two functions buildUrl() and doRequest() are included in the stdutils.js library. 

The code of the mediacenter is in [4]. Feel free to check out what we've been done so far. The code on the mediaservice is in dataengines/javascript/service/ and the plugins find themselves in dataengines/addons/.

Further plans
Right now, there hasn't been much activity in plasma-mediacenter-land and I hope that we continue more intensely on this project in the future.

However, a particular idea for this years Google summer of Code has been posted, which includes porting graphical elements to QML [2] and I am looking forward to see someone implementing it. A good way to make the mediaservice "useful" is to integrate it in that idea. I, myself was a little impatient to see something like that, so I implemented a little QML-plasmoid that connects to the mediaservice and queries a plugin (in that case it was flickr). Here is a little screenshot:

Thats all from here. Thank you for reading.