| From | Sent On | Attachments |
|---|---|---|
| Patrick Wright | Mar 23, 2008 1:30 pm | .png |
| Subject: | Experiment: embedding Flash in Flying Saucer | |
|---|---|---|
| From: | Patrick Wright (pdou...@gmail.com) | |
| Date: | Mar 23, 2008 1:30:49 pm | |
| List: | net.java.dev.xhtmlrenderer.users | |
| Attachments: | ||
So, one of the great Swing/UI programmers out there, Chris Deckers, has been working on a project called DJ Native Swing (http://djproject.sourceforge.net/ns/index.html). Among other features, this lets you embed a Flash player (via a browser component) inside a Swing app. Check out the project site; there's a WebStart demo. Windows should just work, Linux requires XULRunner installed, and OS X doesn't work for the moment (SWT limitation).
I ran a quick test to see if this would be possible to use in Flying Saucer. I embedded three YouTube videos within a page (see attached)--I sized them small (actually wanted to see if that worked, plus wanted to test floats and tables). You can actually start them running (at the same time), which in this case (Monty Python), is pretty funny.
Generally, it just works, though there are some issues: - there's a classic heavy/lightweight component issue that shows up in this case, inside a scrollpane: one of these embedded elements will try to paint itself over the border. Chris gave the his workaround for this, which is either a per-instance or global property you set, where his library works around the issue. there is some flickering when the flash goes "under" the border, and this would be one issue to play with - at least in my demo, resizing the page caused the videos to start again. one could probably work around that to some extent
Some notes on how I did this--I'm not planning on working on this at the moment, and because of the deployment issues (which are there because we're relying on native components) don't think we will officially support this. However, if some enterprising users of FS go the extra mile to get this working, that would be great, and it could be documented, samples shown, etc.
Since I wanted a quick hack, I added a condition in the SwingReplacedElementFactory } else if (isFlash(e)) { NativeComponent.getNextInstanceOptions().setFiliationType(NativeComponent.Options.FiliationType.COMPONENT_PROXYING); JFlashPlayer player = new JFlashPlayer(); player.setSize(100, 100); final String srcUrl = e.getAttribute("src"); player.setURL(srcUrl);
context.getCanvas().add(player); return new SwingReplacedElement(player) { public boolean isRequiresInteractivePaint() { return false; } };
} else {
isFlash() in this case doesn't do the right thing--I'm using an element named "flash" instead of an object or embed tag. The right thing to do would be to use the object or embed tag, handle the size, etc. from there.
That's it. Kudos go to Chris Deckers for such a great library. Patrick






.png