HTML5视频无法使用WebKit Gtk播放

时间:2015-10-31 12:45:42

标签: video webkit gtk

视频无法在Webkit中播放,但它确实在使用Ubuntu 12.04的Firefox浏览器中播放

$ firefox --version Mozilla Firefox 23.0

$ uname -a Linux用户3.8.0-29-通用#42~precision1-Ubuntu SMP Wed 8月14日15:31:16 UTC 2013 i686 i686 i386 GNU / Linux

C代码如下

#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), 1024, 700);

    // 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://localhost/video.html");

    webkit_web_view_load_uri(webView, "http://v4e.thewikies.com/");
    //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;
}

我试图在&#34; http://localhost/video.html&#34;上播放视频 但它没有用,虽然我可以通过Firefox播放相同的video.html

怀疑我的video.html我选择直接从网上播放 webkit_web_view_load_uri(webView,&#34; http://v4e.thewikies.com/&#34;); 但结果是一样的。

video.html

<!DOCTYPE html> 
<html> 
<body> 

<div style="text-align:center"> 
  <button onclick="windowClose();">Close</button>
  <button onclick="playPause()">Play/Pause</button> 
  <button onclick="makeBig()">Big</button>
  <button onclick="makeSmall()">Small</button>
  <button onclick="makeNormal()">Normal</button>
  <br><br>

Source Code

<!-- "Video For Everybody" http://camendesign.com/code/video_for_everybody -->
<video controls="controls" autoplay="autoplay" poster="http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg" width="640" height="360">
    <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" />
    <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.webm" type="video/webm" />
    <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" type="video/ogg" />
    <img alt="Big Buck Bunny" src="http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg" width="640" height="360" title="No video playback capabilities, please download the video below" />
</video>



</div> 

<script> 
var myVideo = document.getElementById("video1"); 

function playPause() { 
    if (myVideo.paused) 
        myVideo.play(); 
    else 
        myVideo.pause(); 
} 

function makeBig() { 
    myVideo.width = 560; 
} 

function makeSmall() { 
    myVideo.width = 320; 
} 

function makeNormal() { 
    myVideo.width = 420; 
} 
function windowClose() { 
window.open('','_parent',''); 
window.close();
} 
</script> 

</body> 
</html>

0 个答案:

没有答案