Monday, April 20, 2009

Embed flash movies with gnash in your gtk apps

Has been a week full of hacking fun since I started to work on a Gnash gtk widget. Some frustration as well because it's the first time I deal with C++ code using boost and modern stuff like std_ptr and, of course, libtool and friends. This bit of work comes in line with my earlier posts about embedding Evince, Abiword and Mozilla.

But the effort has born its fruits, and now we can run all of Gnash as a gtk widget inside a Sugar activity:


And this is the code:

import os

import gtk
import gnash

from sugar.activity import activity

class EatBoomActivity(activity.Activity):
def __init__(self, handle, browser=None):
activity.Activity.__init__(self, handle)

toolbox = activity.ActivityToolbox(self)
self.set_toolbox(toolbox)
toolbox.show()

view = gnash.View()
view.load_movie(os.path.join(activity.get_bundle_path(), 'EatBoom.swf'))
view.start()
self.set_canvas(view)
view.show()


For non-Sugar-enabled gtk people, you will be able to embed gnash doing something like this:

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

view = gnash_view_new ();

gtk_container_add (GTK_CONTAINER (window), view);
gtk_widget_show (view);

gtk_widget_show (window);

gnash_view_load_movie(GNASH_VIEW(view), argv[1]);
gnash_view_start(GNASH_VIEW(view));

This is without using GtkPlug and, of course, running inside the same process. So by adding methods to the C widget we can control all of the Gnash engine and expose it trivially to python with pygtk. And through the use of Gnash extensions, we can extend the ActionScript class library with Sugar specifics so it integrates well with the rest of the environment.

This is still a proof of concept, but plan to start working right now in finding a way to integrate it in upstream Gnash.

6 comments:

Anonymous said...

Please NO, the world needs less Flash. Flash deserves a horrible death.

Tomeu Vizoso said...

> Why gnash and not swfdec-gnome?

Because: Rob Savoye got in touch with us about making gnash work as well as possible on Sugar and OLPC, and also because I was under the impression that swfdec was targeted to play video embedded in flash movies and not generic flash movies.

But anyway, I think that because Sugar Labs isn't Apple and cannot chose one project and put lots of money behind it, we need to track competing projects so we can benefit from the best of them without having to go through the pain of backing one and then having to drop support for it and switch to the other.

I think that we'll have to offer activity authors the possibility to use both gnash and swfdec, and both mozilla and webkit.

Tomeu Vizoso said...

> Please NO, the world needs less Flash. Flash deserves a horrible death.

I don't really know what Flash deserves, but we have hundreds of thousands of kids wanting to use flash content, and people interested in bringing their educative content to Sugar if it doesn't involve rewriting in pygtk or pygame.

So we decided to bite the bullet and get to work on good flash support in Sugar. We still believe open standards should be the goal, so we are also going to be working on that. See the link below for a rationale:

http://www.olpcnews.com/software/applications/happy_activity_designers_part_2.html

Anonymous said...

Hello, there. Is it there any progress in Gtk implementation? I'll be wery appretiate if you share anything. Army of AS coders who likes Linux and wont to create standalone apps waiting for that! :)

Tomeu Vizoso said...

> Hello, there. Is it there any progress in Gtk implementation? I'll be wery appretiate if you share anything. Army of AS coders who likes Linux and wont to create standalone apps waiting for that! :)

All the work is already upstreamed in Gnash. Right now there isn't a tremendous momentum for Flash in Sugar, but everybody is welcome to use the Gnash widget to make a framework for developing in SWF for the desktop.

nzo said...

Hi,
I'm trying to do the opposite: insert an X window into my swf
like Xming X Server for Windows.