XUL and XULRunner (co-starring flash)

Like you probably noteiced I got more and more interest in XUL and experimenting Firefox extensions in the last days.
After my first extension I decided to try something different and first I created a little (this time nothing new at all) and lightweight extension for grabbing flv videos while visiting youtube.com or video.google.com. It simply creates a statusbar icon and when there are availables flv on the page it will get active. Clicking on it let you save the current playing flv. You can also change the options and tell the extension to open the video using you favourite Video Player (Like VLC or FLVPlayer)

Install the getvideo-0.1-fx.xpi Firefox extension

When I did this extension comes also in my mind the idea of creating a simple Flash video player, just for practice. I was doing it using python/wxPython as usual.. but then I wanted to try using XUL  and package it with XULRunner (a runtime XUL runner, which runs xul applications like standalone applications).
First of all I have to say thanks to Darron Schall for his article on how-to embed swf files in xul. I was going crazy to understand all the steps for creating a valid xulrunner package..
As usual opensource sofware has bad and incomplete documentation. I need to look into one of the examples (chatzilla) to understand how it works.

Once I undertood that a new problem arise, the damn flash security sandbox error! When the xulrunner application starts it prompt also the security warning.. Oh my god!

After various attempts and after reading various articles on FlashplayerTrust I managed to solve the problem (or at least I think I’ve solved…).
In the installer a file named flvideoplayer.cfg will be copied inside the Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust direcory, and it’s content is

chrome:\\flvideoplayer\content\flvideoplayer.xul

In this way the embed swf file should has the correct permissions to communicate with the xul page using fscommand. I thought that my experiment was finished, but when I shown it to a friend he  asked me to add also the possibility to convert the .flv video into other formats (avi, mpeg, etc).
Well, fortunately there’s ffmpeg which does this job for everyone 🙂

Thus I included ffmpeg to enable video conversion. What I did it’s a runtime .bat file which wil invoke ffmpeg:

function execute_batch(bat) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
try
{
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(bat.path);
var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(file);
process.run(true, {}, 0);
} catch(e)
{
alert(e);
}
}

Ok, how to install this application.
In order to run correctly this application you first have to:

  • download XULRunner (I did not included in the installer because it’s about 10Mb).
  • Once downloaded from a command prompt, run xulrunner.exe –register-global (to register for all users) or xulrunner.exe –register-user (to register for one user only).
  • To enable the flash plugin (the Firefox plugin isn’t used, so if you launch the application you won’t see the flash embed object) you have to copy:
    {programs}\Mozilla Firefox\plugins\NPSWF32.dll
    {programs}\Mozilla Firefox\plugins\flashplayer.xpt

    into your XULRunner\plugins\ folder
  • Now just download yougrab! and install it.

Install YouGrab! (sorry but currently Windows only)