我想使用 wxMediaCtrl 在 wxWidgets 中播放 swf 文件。所以我在互联网上搜索,发现这个链接wxMediaCtrl backend for flash.ocx。然后我安装了 adobe shockwaveflash 和 adobe flash,并在 mysample 项目上实现,但它没有显示 wxMediaCtrl 播放 swf 文件。(对不起我之前的英语),现在我正在使用代码块 10_05 和 wxWidgets-2.8.12,所以这是我的代码:
LLS_MediaPlay.h 上的代码
#include "wx/mediactrl.h"
#include "wx/msw/ole/activex.h" // wxActiveXContainer
#include "wx/msw/ole/automtn.h" // wxAutomationObject
const IID IID_Flash = {0xD27CDB6C,0xAE6D,0x11CF,{0x96,0xB8,0x44,0x45,0x53,0x54,0x00,0x00}};
const CLSID CLSID_Flash = {0xD27CDB6E,0xAE6D,0x11cf,{0x96,0xB8,0x44,0x45,0x53,0x54,0x00,0x00}};
class WXDLLIMPEXP_MEDIA wxFlashMediaBackend : public wxMediaBackendCommonBase
{
public:
wxFlashMediaBackend() : m_pAX(NULL) {}
virtual ~wxFlashMediaBackend()
{
if(m_pAX)
{
m_pAX->DissociateHandle();
delete m_pAX;
}
}
virtual bool CreateControl(wxControl* ctrl, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name)
{
IDispatch* pDispatch;
if( ::CoCreateInstance(CLSID_Flash, NULL, CLSCTX_INPROC_SERVER, IID_Flash, (void**)&pDispatch) != 0)
return false;
m_PDF.SetDispatchPtr(pDispatch); // wxAutomationObject will release itself
if (!ctrl->wxControl::Create(parent, id, pos, size,(style & ~wxBORDER_MASK) | wxBORDER_NONE, validator, name))
return false;
m_ctrl = wxStaticCast(ctrl, wxMediaCtrl);
m_pAX = new wxActiveXContainer(ctrl, IID_Flash, pDispatch);
wxFlashMediaBackend::ShowPlayerControls(wxMEDIACTRLPLAYERCONTROLS_NONE);
return true;
}
virtual bool Play()
{
return true;
}
virtual bool Pause()
{
return true;
}
virtual bool Stop()
{
return true;
}
virtual bool Load(const wxString& filename)
{
m_PDF.CallMethod(_T("LoadFile"),"1",filename);
NotifyMovieLoaded();
wxSizeEvent event;
m_pAX->OnSize(event);
return true;
}
virtual bool Load(const wxURI& location)
{
return m_PDF.CallMethod(_T("LoadFile"), location.BuildUnescapedURI()).GetBool();
}
virtual bool Load(const wxURI& WXUNUSED(location), const wxURI& WXUNUSED(proxy))
{
return false;
}
virtual wxMediaState GetState()
{
return wxMEDIASTATE_STOPPED;
}
virtual bool SetPosition(wxLongLong where)
{
m_PDF.CallMethod(_T("setCurrentPage"), wxVariant((long)where.GetValue()));
return true;
}
virtual wxLongLong GetPosition()
{
return 0;
}
virtual wxLongLong GetDuration()
{
return 0;
}
virtual void Move(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(w), int WXUNUSED(h))
{
}
virtual wxSize GetVideoSize() const
{
return wxDefaultSize;
}
virtual double GetPlaybackRate()
{
return 0;
}
virtual bool SetPlaybackRate(double)
{
return false;
}
virtual double GetVolume()
{
return 0;
}
virtual bool SetVolume(double)
{
return false;
}
virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags)
{
if(flags)
{
m_PDF.CallMethod(_T("setShowToolbar"), true);
m_PDF.CallMethod(_T("setShowScrollbars"), true);
}
else
{
m_PDF.CallMethod(_T("setShowToolbar"), false);
m_PDF.CallMethod(_T("setShowScrollbars"), false);
}
return true;
}
wxActiveXContainer* m_pAX;
wxAutomationObject m_PDF;
DECLARE_DYNAMIC_CLASS(wxFlashMediaBackend)
};
class LLS_MediaPlay: public wxFrame
{
public:
LLS_MediaPlay(wxWindow* parent,wxWindowID id=wxID_ANY);
virtual ~LLS_MediaPlay();
void OnplayvideoButtonClick(wxCommandEvent& event);
wxMediaCtrl *mediaplayer;
//(*Declarations(LLS_MediaPlay)
//*)
protected:
//(*Identifiers(LLS_MediaPlay)
//*)
private:
//(*Handlers(LLS_MediaPlay)
//*)
static const long ID_MEDIACTRL1;
DECLARE_EVENT_TABLE()
};
以及 LLS_MediaPlay.cpp 上的这段代码:
mediaplayer = new wxMediaCtrl(this, ID_MEDIACTRL1, _T("G:\\hendy\\animation\\gas.swf"), wxPoint(5,5), wxSize(1000,400), 0, _T("wxFlashMediaBackend"), wxDefaultValidator, _T("SWF Player"));
Connect(ID_MEDIACTRL1, wxEVT_MEDIA_PLAY, (wxObjectEventFunction)&LLS_MediaPlay::OnplayvideoButtonClick);
void LLS_MediaPlay::OnplayvideoButtonClick(wxCommandEvent& event)
{
// is it mediaplayer->Show(); ??
}
当我编译此代码但没有显示 wxFlashMediaBackend 播放 gas.swf 文件时没有错误。它显示一个空的白框,但是如果我右键单击该框,它将显示弹出菜单 About Adobe Flash Player 11.8.800.94 ...
谁能告诉我我在哪里做错了?
我真的很想展示我的空白白框图像,但我没有 10 显示该图像的声誉。对此感到抱歉。但有人可以帮助我吗?任何有关为什么会发生这种情况的见解将不胜感激。
谢谢。