0

我无法让 Awesomium 1.7.0 播放 html5 视频(webm 格式),即使示例项目随 SDK (sample_gdi) 一起提供。示例页面:http ://www.webmfiles.org/demo-files/

看起来视频帧已正确加载,但播放器卡在第一帧。虽然如果我手动移动进度条,我可以浏览视频帧......

我尝试使用 webViewType 窗口和屏幕外,并启用了 enable_gpu_acceleration 和 enable_web_gl,但每次都没有成功......

我的规格:VS2010,Windows 7

有任何想法吗?谢谢!!

示例项目“Sample_gdi”中的代码由 Awesomium 1.7.0 安装程序自动安装,位于C:\Users[user]\Documents\Visual Studio 2010\Projects\Awesomium\1.7.0.5\BuildSamples\BuildSamples.sln 中

主.cc

#include "../common/application.h"
#include "../common/view.h"
#include <Awesomium/WebCore.h>
#include <Awesomium/STLHelpers.h>
#ifdef _WIN32
#include <Windows.h>
#endif

using namespace Awesomium;

class GDISample : public Application::Listener {
  Application* app_;
  View* view_;
 public:
  GDISample() 
    : app_(Application::Create()),
      view_(0) {
    app_->set_listener(this);
  }

  virtual ~GDISample() {
    if (view_)
      app_->DestroyView(view_);
    if (app_)
      delete app_;
  }

  void Run() {
    app_->Run();
  }

  // Inherited from Application::Listener
  virtual void OnLoaded() {
    view_ = View::Create(800, 600);
    view_->web_view()->LoadURL(WebURL(WSLit("http://www.google.com")));
  }

  // Inherited from Application::Listener
  virtual void OnUpdate() {
  }

  // Inherited from Application::Listener
  virtual void OnShutdown() {
  }
};

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, wchar_t*, 
  int nCmdShow) {

  GDISample sample;
  sample.Run();

  return 0;
}

application_win.cc

#include "application.h"
#include "view.h"
#include <Awesomium/WebCore.h>
#include <Awesomium/STLHelpers.h>
#include <string>

using namespace Awesomium;

class ApplicationWin : public Application {
  bool is_running_;
 public:
  ApplicationWin() {
    is_running_ = true;
    listener_ = NULL;
    web_core_ = NULL;
  }

  virtual ~ApplicationWin() {
    if (listener())
      listener()->OnShutdown();

    if (web_core_)
      web_core_->Shutdown();
  }

  virtual void Run() {
    Load();

    // Main message loop:
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0) && is_running_) {
      web_core_->Update();
      TranslateMessage(&msg);
      DispatchMessage(&msg);
      if (listener())
        listener()->OnUpdate();
    }
  }

  virtual void Quit() {
    is_running_ = false;
  }

  virtual void Load() {
      WebConfig config;
     web_core_ = WebCore::Initialize(config);

    if (listener())
      listener()->OnLoaded();
  }

  virtual View* CreateView(int width, int height) {
    return View::Create(width, height);
  }

  virtual void DestroyView(View* view) {
    delete view;
  }

  virtual void ShowMessage(const char* message) {
    std::wstring message_str(message, message + strlen(message));
    MessageBox(0, message_str.c_str(), message_str.c_str(), NULL);
  }
};

Application* Application::Create() {
  return new ApplicationWin();
}

view_win.cc

#include "view.h"
#include <Awesomium/WebCore.h>
#include <Awesomium/STLHelpers.h>
#include <vector>

class ViewWin;

static bool g_is_initialized = false;
static std::vector<ViewWin*> g_active_views_;
const wchar_t szWindowClass[] = L"ViewWinClass";
const wchar_t szTitle[] = L"Application";
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

using namespace Awesomium;

class ViewWin : public View,
                public WebViewListener::View {
public:
  ViewWin(int width, int height) {
    PlatformInit();
    WebPreferences webPref;
    WebSession *session =  WebCore::instance()->CreateWebSession(ToWebString(""),webPref);
    web_view_ = WebCore::instance()->CreateWebView(width,
                                           height,
                                           session,
                                           Awesomium::kWebViewType_Window);

    web_view_->set_view_listener(this);

    // Create our WinAPI Window
    HINSTANCE hInstance = GetModuleHandle(0);
    hwnd_ = CreateWindow(szWindowClass,
              szTitle,
              WS_OVERLAPPEDWINDOW,
              CW_USEDEFAULT,
              CW_USEDEFAULT,
              width + 20,
              height + 40, 
              NULL,
              NULL,
              hInstance,
              NULL);

    if (!hwnd_)
      exit(-1);

    web_view_->set_parent_window(hwnd_);

    ShowWindow(hwnd_, SW_SHOWNORMAL);
    UpdateWindow(hwnd_);

    SetTimer (hwnd_, 0, 15, NULL );

    g_active_views_.push_back(this);
  }

  virtual ~ViewWin() {
    for (std::vector<ViewWin*>::iterator i = g_active_views_.begin();
        i != g_active_views_.end(); i++) {
      if (*i == this) {
        g_active_views_.erase(i);
        break;
      }
    }

    web_view_->Destroy();
  }

  HWND hwnd() { return hwnd_; }

  static void PlatformInit() {
    if (g_is_initialized)
      return;

    WNDCLASSEX wc;

    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = GetModuleHandle(0);
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = szWindowClass;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc)) {
      exit(-1);
    }

    g_is_initialized = true;
  }

  static ViewWin* GetFromHandle(HWND handle) {
    for (std::vector<ViewWin*>::iterator i = g_active_views_.begin();
        i != g_active_views_.end(); i++) {
      if ((*i)->hwnd() == handle) {
        return *i;
      }
    }

    return NULL;
  }

  // Following methods are inherited from WebViewListener::View

  virtual void OnChangeTitle(Awesomium::WebView* caller,
                             const Awesomium::WebString& title) {
    std::string title_utf8(ToString(title));
    std::wstring title_wide(title_utf8.begin(), title_utf8.end());

    SetWindowText(hwnd_, title_wide.c_str());
  }

  virtual void OnChangeAddressBar(Awesomium::WebView* caller,
    const Awesomium::WebURL& url) { }

  virtual void OnChangeTooltip(Awesomium::WebView* caller,
    const Awesomium::WebString& tooltip) { }

  virtual void OnChangeTargetURL(Awesomium::WebView* caller,
    const Awesomium::WebURL& url) { }

  virtual void OnChangeCursor(Awesomium::WebView* caller,
    Awesomium::Cursor cursor) { }

  virtual void OnChangeFocus(Awesomium::WebView* caller,
    Awesomium::FocusedElementType focused_type) { }

  virtual void OnShowCreatedWebView(Awesomium::WebView* caller,
                                    Awesomium::WebView* new_view,
                                    const Awesomium::WebURL& opener_url,
                                    const Awesomium::WebURL& target_url,
                                    const Awesomium::Rect& initial_pos,
                                    bool is_popup) { }

    virtual void OnAddConsoleMessage(Awesomium::WebView* caller,
                                   const Awesomium::WebString& message,
                                   int line_number,
                                   const Awesomium::WebString& source) { }

 protected:
  HWND hwnd_;
};

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  ViewWin* view = ViewWin::GetFromHandle(hWnd);

  switch (message) {
  case WM_COMMAND:
    return DefWindowProc(hWnd, message, wParam, lParam);
    break;
  case WM_TIMER:
    break;
  case WM_SIZE:
    view->web_view()->Resize(LOWORD(lParam), HIWORD(lParam));
    break;
  case WM_DESTROY:
    PostQuitMessage(0);
    break;
  case WM_QUIT:
    break;
  default:
    return DefWindowProc(hWnd, message, wParam, lParam);
  }
  return 0;
}

View* View::Create(int width, int height) {
  return new ViewWin(width, height);
}

../common/application.h

#ifndef COMMON_APPLICATION_H_
#define COMMON_APPLICATION_H_

class View;

namespace Awesomium {
class WebCore;
}

// Common class that sets up an application, creates the WebCore, handles
// the Run loop, and abstracts platform-specific details.
class Application {
 public:
  // Listener interface to be used to handle various application events.
  class Listener {
   public:
    virtual ~Listener() {}

    // Event is fired when app (and WebCore) have been loaded.
    virtual void OnLoaded() = 0;

    // Event is fired for each iteration of the Run loop.
    virtual void OnUpdate() = 0;

    // Event is fired when the app is shutting down.
    virtual void OnShutdown() = 0;
  };

  virtual ~Application() {}

  // Platform-specific factory constructor
  static Application* Create();

  // Begin the Run loop.
  virtual void Run() = 0;

  // Ends the Run loop.
  virtual void Quit() = 0;

  // Create a platform-specific, windowed View
  virtual View* CreateView(int width, int height) = 0;

  // Destroy a View
  virtual void DestroyView(View* view) = 0;

  // Show a modal message box
  virtual void ShowMessage(const char* message) = 0;

  // Get the WebCore
  virtual Awesomium::WebCore* web_core() { return web_core_; }

  // Get the Listener.
  Listener* listener() { return listener_; }

  // Set the Listener for various app events.
  void set_listener(Listener* listener) { listener_ = listener; }

 protected:
  Application() { }

  virtual void Load() = 0;

  Listener* listener_;
  Awesomium::WebCore* web_core_;
};

#endif  // COMMON_APPLICATION_H_

../common/view.h

#ifndef COMMON_VIEW_H_
#define COMMON_VIEW_H_

namespace Awesomium {
class WebView;
}

// Common class that implements a windowed WebView, handles all input/display,
// and abstracts away all the platform-specific details.
class View {
 public:
  virtual ~View() {}

  // Platform-specific constructor
  static View* Create(int width, int height);

  // Get the associated WebView
  Awesomium::WebView* web_view() { return web_view_; }

 protected:
  View() { }

  Awesomium::WebView* web_view_;
};

#endif  // COMMON_VIEW_H_
4

2 回答 2

0

我在这个问题上花了一天时间,对我来说它最终是一个音频连接问题。我不得不使用 HDMI 电缆或将扬声器插入计算机。一旦我这样做了,视频就没有冻结。我的问题是由于使用 DVI 电缆而没有将任何东西插入我的音频输出。

于 2013-10-24T19:04:16.907 回答
0

看起来我在其他计算机上部署时无法重现该错误。我的电脑上应该有什么东西坏了,阻止 awesomium 正确播放 html5 视频......

于 2013-04-26T07:42:26.247 回答