技术开发 频道

Windows Mobile多媒体开发总结之Media Player Plugins(续)

 【第三步】实现IWMPPluginUI等接口

 

  class CMediaPlayerPlugin:

 public IWMPPluginUI

 在上一篇文章中我列出了这个接口下的方法:

 

  STDMETHODIMP Create(HWND hwndParent, HWND * phwndWindow);

 STDMETHODIMP Destroy();

 STDMETHODIMP DisplayPropertyPage(HWND hwndParent);

 STDMETHODIMP GetProperty(LPCWSTR wszName, VARIANT * pvarProperty);

 STDMETHODIMP SetCore(IWMPCore * pCore);

 STDMETHODIMP SetProperty(LPCWSTR wszName, const VARIANT * pvarProperty);

 STDMETHODIMP TranslateAccelerator(MSG * pMsg);

 对于这些方法,实现你需要的,不感兴趣的仅仅让它为空即可,比如:

 

  HRESULT CMediaPlayerPlugin::Create(HWND hwndParent, HWND * phwndWindow)

 {

 // As per the IWMPPluginUI documentation, this method will never be called

 // because we're a background plugin (our registry Capabilities flags include

 // PLUGIN_TYPE_BACKGROUND = 0x00000001).

 return E_NOTIMPL;

 }

 SetCore是个关键方法,因为我们需要通过它获得操作WMP的接口指针,这里我们把获得的指针存放在m_pCore中:

 

  HRESULT CMediaPlayerPlugin::SetCore(IWMPCore * pCore)

 {

 // This method is called shortly after this instance is created, and allows

 // us to hook up to Windows Media Player. Save the interface pointer.

 //

 // When WMP is shutting down, it calls SetCore(NULL) so we have to handle that

 // as well.

 if (m_pCore != NULL)

 {

 m_pCore->Release();

 }

 m_pCore = pCore;

 if (m_pCore != NULL)

 {

 m_pCore->AddRef();

 }

 return S_OK;

 }

 然后我们可以像这样进一步通过m_pCore获得其它接口指针,类似这里的get_contronls方法的还有get_settings等,更详细的可以查看附件的项目。

 

  VOID CMediaPlayerPlugin::ControlPlayer(UINT uMsg)

 {

 IWMPControls *  pControls;

 // Get the 'IWMPControls' interface.

 if (SUCCEEDED(m_pCore->get_controls(&pControls)))

 {

 switch (uMsg)

 {

 // for the toggle message

 case WM_WMPTOGGLE:

 WMPPlayState wmpps;

 // get the current state

 if (SUCCEEDED(m_pCore->get_playState(&wmpps)))

 {

 // if it playing a track, pause it

 if (wmpps == wmppsPlaying)

 {

 pControls->pause();

 }

 // otherwise try to play the track

 else

 {

 pControls->play();

 }

 }

 break;

 case WM_WMPPREVIOUS:

 pControls->previous();

 break;

 case WM_WMPNEXT:

 pControls->next();

 break;

 default:

 break;

 }

 pControls->Release();

 }

 }

 文章上个星期就写的差不多了,一直拖到现在才发布,实在抱歉。下一篇文章我总结下Today Plugin的开发。随便介绍下通过Today Plugin控制WMP。希望对你有所帮助,我的QQ是3423 6777 6,如果你需要什么帮助,或者跟我讨论的话。

查看原文地址

0
相关文章