我想使用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文件。它显示一个空白框,但如果我右键单击该框架,它将显示弹出菜单关于Adobe Flash Player 11.8.800.94 ...
任何人都可以告诉我我在做错的地方吗?
我真的想要显示我的空白框图像,但我没有10个声誉来显示该图像。对不起但任何人都可以帮助我吗? 任何有关为何发生这种情况的见解都将非常感激。
感谢。
答案 0 :(得分:1)
我只是将它添加到LLS_MediaPlay.cpp:
Connect(ID_MEDIACTRL1, wxEVT_ACTIVEX, (wxObjectEventFunction)&LLS_MediaPlay::OnplayvideoButtonClick);
和OnplayvideoButtonClick方法,我添加:
mediaplayer->Play();
所以,就像那样!现在我可以在Windows平台上播放我的swf文件了。