Html5视频不能用awesome播放
html5 video not playing with awesomium
我无法让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
任何想法?谢谢! !
由Awesomium 1.7.0安装程序自动安装的示例项目"Sample_gdi"的代码,可在C:Users[user]DocumentsVisual Studio 2010ProjectsAwesomium1.7.0.5BuildSamplesBuildSamples中获得。sln :
Main.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);
}
. ./共同/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_
. ./共同/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_
看起来我在其他计算机上部署时无法重现该错误。我的电脑上应该有什么东西坏了,阻止了awesomium正确播放html5视频…
我花了一天的时间在这个问题上,对我来说,它最终是一个音频连接问题。我不得不使用HDMI线或插入式扬声器连接我的电脑。一旦我这样做了,视频就不会冻结。我的问题是由于使用DVI电缆而没有插入任何东西到我的音频输出。
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- SFML纹理像播放器
- 根据用户回答声明"Players"。用户选择玩家数量。播放器是结构体
- 如何收听Windows当前正在播放的声音?
- GStreamer在开始任何播放之前进行搜索
- (SFML)按下键时,播放器构造函数未使用正确的动画进行更新
- 如何使用libav编写.mov文件,如果文件未正确完成,则可以播放
- C++新手,想知道如何使用VS code 2019播放音频文件
- 在C++不适用于猜数字游戏的情况下再次播放选项
- 按列随机播放 2D 矢量
- 如何以编程方式将音频从任何录制设备路由到任何播放设备
- 使用 IMFSinkWriter 编码的视频的播放速度会根据宽度而变化
- 测试驱动开发 c++:如何将对象添加到向量中,将歌曲添加到播放列表并对其进行测试
- 如何在C++中播放声音?
- 旋转播放器模型以指向一个点
- 大声音频无法播放
- 怎么可能只让设备使用 pjsua2 捕获或播放
- 播放器未在程序中的"X"和"O"之间切换
- 为什么这个函数会循环播放?
- Html5视频不能用awesome播放