0

I am trying to play html5 video in a program that use webkitgtk and written in C.

In order to test the html5 video I set up a server with a webpage:

<!DOCTYPE html>
<html>
 <head>
</head>
<body>
<video autoplay="autoplay" >
<source src="./movie.ogv" type="video/ogg">
Your browser does not support the video tag.
</video> 
</body>
</html>

and it works in firefox, but when I use my program to display that webpage, the vide doesn't work.

My C program:

#include <gtk/gtk.h>
#include <webkit/webkit.h>


static void destroyWindowCb(GtkWidget* widget, GtkWidget* window);
static gboolean closeWebViewCb(WebKitWebView* webView, GtkWidget* window);

int main(int argc, char* argv[])
{
    // Initialize GTK+
    gtk_init(&argc, &argv);

    // Create an 800x600 window that will contain the browser instance
    GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_decorated(main_window, false);
    gtk_window_move(main_window,0,0);
    gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);

    // Create a browser instance
    WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());

    // Create a scrollable area, and put the browser instance into it
    GtkWidget *scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
            GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_container_add(GTK_CONTAINER(scrolledWindow), GTK_WIDGET(webView));

    // Set up callbacks so that if either the main window or the browser instance is
    // closed, the program will exit
    g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL);
    g_signal_connect(webView, "close-web-view", G_CALLBACK(closeWebViewCb), main_window);

    // Put the scrollable area into the main window
    gtk_container_add(GTK_CONTAINER(main_window), scrolledWindow);

    // Load a web page into the browser instance
    webkit_web_view_load_uri(webView, "http://localhost/");
    //webkit_web_view_load_uri(webView, "http://www.shastaherps.org/sampleHTML5.html#multimedia");

    // Make sure that when the browser area becomes visible, it will get mouse
    // and keyboard events
    gtk_widget_grab_focus(GTK_WIDGET(webView));

    // Make sure the main window and all its contents are visible
    gtk_widget_show_all(main_window);

    // Run the main GTK+ event loop
    gtk_main();

    return 0;
}


static void destroyWindowCb(GtkWidget* widget, GtkWidget* window)
{
    gtk_main_quit();
}

static gboolean closeWebViewCb(WebKitWebView* webView, GtkWidget* window)
{
    gtk_widget_destroy(window);
    return TRUE;
}

Any sugestion?

Thanks.

P.D I install libwebkitgtk from Ubuntu repository.

RdlP
  • 1,366
  • 5
  • 25
  • 45
  • I solved it. The problem was the video format.. But now I get another error. I put "loop" in video tag but when the video finish it crash. Any suggestion? thanks – RdlP Nov 20 '13 at 20:01
  • I solved it again. It was a codecs problema I run the follow commands: sudo apt-get -y install ubuntu-restricted-extras gstreamer1.0-* And it works. – RdlP Nov 25 '13 at 16:21

1 Answers1

-1

support from resource files:

~$ sudo apt-get install libgtk-3-dev libwebkitgtk-3.0-dev

~$ gcc -Wall -o videoplayer main.c pkg-config gtk+-3.0 --cflags --libs pkg-config webkitgtk-3.0 --cflags --libs

example:

‹source src="./movie.ogv"type="video/ogg"›

‹source src="file:///movie.ogv" type="video/ogg"›

/* not avaliable in webkit2gtk-4.0 */

‹source src="resource:///movie.ogv" type="video/ogg"›

not support from resource files:

~$ sudo apt-get install libgtk-3-dev libwebkit2gtk-4.0-dev

~$ gcc -Wall -o videoplayer main.c pkg-config gtk+-3.0 --cflags --libs pkg-config webkit2gtk-4.0 --cflags --libs

SHENOISZ
  • 31
  • 5