在过去的10年里,移动技术已经取得了令人难以置信的进步和成就。应用Windows CE系统的移动设备也在应用和编程方面变得更加灵活和方便。最新的Windows CE设备中加入了Windows Media Player 10 Mobile,它提供了和PC上的WMP控件一样强大的功能。你可以为你的移动设备增加多媒体能力,包括播放视频、音频文件,展示图片等等。你可以在文后所附的段落中找到可用的SDK和资源等相关信息。
下面我们简单介绍WMP的一些实现技术。
慨述
WMP SDK提供了很多的接口,但不是所有都能应用到Windows Mobile平台上来。下面列出可用的一些并进行解释:
接口 描述
IWMPCore WMP对象模型的根接口。你可以由此获取其他接口的指针并且通过它访问其他空间的基本特性。
IWMPControls 允许一个应用程序访问Windows Media Player控件;如它的播放,停止和暂停按钮。
IWMPError 提供错误信息。
IWMPEvents 把由Windows Media Player控件产生的事件提供给一个可以反馈的嵌入式程序。
IWMPMedia,IWMPMediaCollection 管理媒体项的属性。
IWMPNetwork 设置和获取Windows Media Player所使用的网络连接
IWMPPlayer 控制Windows Media Player空间的用户接口的行为。
IWMPPlaylist,IWMPPlaylistArray,IWMPPlaylistCollection 播放列表操作。
IWMPSettings 设置或者获取Windows Media Player的设置。
如果你使用的手持设备没有WMP10,那事情还没有完。你仍然还可以使用WMP OCX版本8来为你的Pocket PC编程,虽然提供的功能特性少,好在也可以基本满足需要。我创建了一个简单的工程来展示它如何在MFC环境下工作。下面的代码段证明了它和ATL方式一样简单:
BOOL CWMP8SampleDlg::OnInitDialog(){ CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this // automatically when the application's main window is not // a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon CenterWindow(GetDesktopWindow()); // center to the hpc screen CRect rect; m_Panel.GetClientRect(&rect); if ( m_PlayerWnd.CreateControl(__uuidof(WMP),L"", WS_VISIBLE|WS_CHILD,rect, &m_Panel,AFX_IDW_PANE_FIRST) ) { LPUNKNOWN lpUnk = m_PlayerWnd.GetControlUnknown(); HRESULT hr = lpUnk->QueryInterface(__uuidof(IWMP),(void**) &m_spWMPPlayer); } else { AfxMessageBox(L"Failed to create WMP control"); ::PostQuitMessage(0); return 0; } if ( m_spWMPPlayer ) { m_WMPEvents.m_pMainDlg = (CWMP8SampleDlg*)this; CComPtr<IConnectionPointContainer> spConnectionContainer; HRESULT hr = m_spWMPPlayer-> QueryInterface( IID_IConnectionPointContainer, (void**)&spConnectionContainer ); if (SUCCEEDED(hr)) { hr = spConnectionContainer-> FindConnectionPoint( __uuidof(_IWMPEvents), &m_spConnectionPoint ); } if (SUCCEEDED(hr)) { hr = m_spConnectionPoint->Advise((IDispatch*)&m_WMPEvents, &m_dwAdviseCookie ); } else { AfxMessageBox(L"Failed to get WMP control events"); ::PostQuitMessage(0); return 0; } if ( FAILED(SetupWMP()) ) { AfxMessageBox(L"Failed to setup WMP control"); ::PostQuitMessage(0); return 0; }}m_spWMPPlayer->Stop();return TRUE;// return TRUE unless you set the focus to a// control=