The smallest Flash player possible

Some people have recently asked me for how to get started coding in Swfdec. As Swfdec doesn’t have any examples and I know we’re far too laz^Wbusy to keep it up to date, I’d just thought I might post somethig in my blog. Blog stuff is allowed to get outdated. So here goes my minimal example simple-swfdec.c to get a window up that plays a Flash file using Swfdec:

#include <libswfdec-gtk/swfdec-gtk.h>
int
main (int argc, char **argv)
{
  GtkWidget *window, *widget;
  SwfdecPlayer *player;

  gtk_init (&argc, &argv);
  swfdec_init ();

  if (argc < 2) {
    g_print ("usage: %s URL\n", argv[0]);
    return 1;
  }
  player = swfdec_gtk_player_new_from_uri (argv[1]);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  widget = swfdec_gtk_widget_new (player);
  gtk_container_add (GTK_CONTAINER (window), widget);
  gtk_widget_show_all (window);
  swfdec_gtk_player_set_playing (SWFDEC_GTK_PLAYER (player), TRUE);

  gtk_main ();

  return 0;
}


Compile with:

gcc -Wall `pkg-config --cflags --libs swfdec-gtk-0.5` simple-swfdec.c -o simple-swfdec


After that you can run Flash files by giving simple-swfdec the full URL like so:

./simple-swfdec http://www.onemorelevel.com/games2/tennis.swf


And now have fun integrating Flash into your apps.

1 comment so far ↓

#1 Pablo Rodríguez on 11.01.07 at 08:27

How about including it with the swfdec code as simple-swdec-player?

So it would be easier to test Flash files with swfdec (and report bugs).

Congratulations for your excellent work,

Pablo