/* gcc `pkg-config --cflags --libs webkit-1.0` main.c -o jamendo-player */
#include <gtk/gtk.h>
#include <webkit/webkit.h>
#define URL_FORMAT "http://widgets.jamendo.com/fr/playlist/?playertype=2008&playlist_id=%s"
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *webview;
gchar *url;
gchar *playlist_id = argv[1];
if (argc < 2)
{
playlist_id = g_strdup ("65196");
g_message ("Loading the default playlist %s", playlist_id);
}
url = g_strdup_printf (URL_FORMAT, playlist_id);
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
gtk_window_set_icon_name (GTK_WINDOW (window), "multimedia-player");
gtk_window_set_title (GTK_WINDOW (window), "Jamendo Player");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
webview = webkit_web_view_new ();
gtk_widget_set_size_request (webview, 200, 300);
gtk_container_add (GTK_CONTAINER (window), webview);
webkit_web_view_open (WEBKIT_WEB_VIEW (webview), url);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
The result is pleasing, the flash application has nice colors, and is something I would never be able to do with GTK+ :-)
If you like the code, feel free to extend it and send patches, I will enjoy any contribution. For now I will just leave a desktop file inside my applications directory to open it when I am bored again of my music :-p
Update: I hacked a little on the program to handle the links inside the Flash application. This means it is possible to change the playlist, which was one the thing that started to annoy me very much.
However, this update requires WebKit 1.0.3 and GLib 2.16.
This time I'm making the code available here instead of pasting it as it has grown up to 120 lines.
Can't compile it. I don't know anything about compiling, so I made:
ReplyDelete$ gcc `pkg-config --cflags --libs webkit-1.0` main2.c -o jamendo-player
And it says:
main2.c:3:9: error: #include expects "FILENAME" or FILENAME
main2.c:4:9: error: #include expects "FILENAME" or FILENAME
main2.c: In function 'main':
main2.c:10: error: 'GtkWidget' undeclared (first use in this function)
main2.c:10: error: (Each undeclared identifier is reported only once
main2.c:10: error: for each function it appears in.)
main2.c:10: error: 'window' undeclared (first use in this function)
main2.c:11: error: 'webview' undeclared (first use in this function)
main2.c:12: error: 'gchar' undeclared (first use in this function)
main2.c:12: error: 'url' undeclared (first use in this function)
main2.c:13: error: 'playlist_id' undeclared (first use in this function)
main2.c:21: error: 'GTK_WINDOW_TOPLEVEL' undeclared (first use in this function)
main2.c:22: error: 'gtk_main_quit' undeclared (first use in this function)
main2.c:22: error: 'NULL' undeclared (first use in this function)
main2.c:25: error: 'FALSE' undeclared (first use in this function)
I edited the ouput in FILENAME to pass the coments filter.
Prior I installed (in Debian/Lenny) libwebkit-dev and his dependencies.
Thanks. in advance. Martintxo.
Heh, you should try again. When I made the post I didn't realize there was a problem with the #includes, in fact the #include <gtk/gtk.h> and <webkit/webkit.h> were read as HTML tags.
ReplyDeletecompile okay but when run, it says:
ReplyDeleteGLib-ERROR **: The thread system is not yet initialized.
The same stuff using Vala:
ReplyDelete// valac --pkg gtk+-2.0 --pkg webkit-1.0 -o jamendo-player jamendo.vala
using Gtk;
using WebKit;
public class JamendoPlayer : Gtk.Window {
private WebView webWidget;
public JamendoPlayer(string playlist) {
this.destroy += Gtk.main_quit;
this.icon_name = "multimedia-player";
this.title = "Jamendo Player";
this.resizable = false;
set_size_request (200, 300);
webWidget = new WebView();
webWidget.open("http://widgets.jamendo.com/de/playlist/?playertype=2008&playlist_id="+playlist);
add(webWidget);
}
public static int main (string[] args) {
string playlist = "65196";
JamendoPlayer player;
Gtk.init(ref args);
if (args.length == 2)
playlist = args[1];
player = new JamendoPlayer(playlist);
player.show_all();
Gtk.main();
return 0;
}
}
@lawcp: Weird. Maybe this indicates that you have a different version of gtk+/glib. Try adding g_thread_init(NULL); before the gtk_init() line.
ReplyDeleteNice shot with the vala code :)
I was just told that the error with the thread is caused by webkit build with libsoup, and that it is going to be mandatory to init the thread system.
ReplyDeleteHm... Nice work, but:
ReplyDelete(jamendo-player:31703): GLib-GObject-WARNING **: /build/buildd/glib2.0-2.16.6/gobject/gsignal.c:1669: signal `create-web-view' is invalid for instance `0x66f000'
I bet you do not have webkit 1.0.3 or higher
ReplyDeleteYes, u're right. My fault, sorry.
ReplyDeleteI've compiled it successfuly, but it shows nothing on start. what is the problem? do you have any idea?
ReplyDeleteThat's because Jamendo always changes its players. You might wish to try the Shoutcast player.
ReplyDeleteOtherwise you can always search on Jamendo for a player.
Rrright, the shoutcast-radio also shows a blank page. But given their website, it looks like they totally dropped the Flash player.
ReplyDeleteI've checked URL_FORMAT against the jamendo latest widget script and they are still exactly same. I've checked your shoutcast player, too but same result unfortunately :( They doesn't show :$ Strange!
ReplyDeleteBy the way, i'm aware of other player posibilities, but i'm another C programmer like you and that's why, i'm interested in your code. I want to see it's working (:. Thanks anyway, good to discover your blog. (:
ReplyDeleteverdim şukunu süper olmuş ;)
ReplyDeleteNot sure why this is happening, I will have to ask a WebKit colleague (although I don't really care to know). Loading a Flash "page" does not work, it has to be done through an intermediate HTML page.
ReplyDeletehttp://pastebin.com/YXCQKtUY
Btw, I really don't know what "şukunu" means!
ReplyDeleteThank you Mike, It's working now. I liked webkit and i'll work on it a bit more. Actually, i dont care why this is happening indeed. (:
ReplyDeleteAnd about "şukunu", he is a friend of mine. I asked him and he said that it's an idiom and it means something like +1 rep. He tried to say "i liked it". Not so important. He is a little bit crazy. (:
You welcome.
ReplyDelete