Windows Mobile和Wince下使用WTL进行Windows Media Player开发
2009-06-30 09:05
645 查看
简介
本文讲述如何使用WTL在Windows Mobile和Wince下进行Windows Media Player的开发。背景
随着3G网络的普及,Windows Mobile在网络方面应用的需求会越来越大,本文讲述是网络多媒体播放应用的开发。实现
前奏
本文是下面两篇文章的延续,关于WTL及其界面的开发请参考下面两篇文章。Windows Mobile和Wince(Windows Embedded CE)下的WTL(Windows Template Library)开发
Windows Mobile 和 Wince(Windows Embedded CE) 下的 WTL(Windows Template Library) 界面(UI)开发
方案
使用native c++进行Windows Media Player的开发可以使用ATL或者插入ActiveX控件的方式。MS提供了一个详细的例子实现ATL的方式。例子见 C:\Program Files\Windows Mobile 6 SDK\Samples\PocketPC\CPP\ATL\wmpsample在本文介绍的方案中,使用了插入ActiveX控件的方式,ActiveX控件可以使用在WTL和MFC下,本文使用WTL来实现。
实现
在PC的WTL下,可以直接在Dialog下插入ActiveX控件(Insert ActiveX Control),可是在Windows Mobile,如果使用直接插入ActiveX控件的方式,程序在运行时生成该控件的时候会失败,所以使用另外一种方式实现,实现方式如下:1.在Dialog下增加名字叫做IDC_WMP的Group-box Control
图1
2.在stdafx.h文件里引入"wmp.h",该文件存放于MS的例子中,C:\Program Files\Windows Mobile 6 SDK\Samples\PocketPC\CPP\ATL\wmpsample
#include "wmp.h"
3.在MobileRadioView增加Windows Media Player的定义
private: CComQIPtr<IWMPPlayer> spWMPPlayer; CAxWindow wndWMP;
spWMPPlayer是指向Windows Media Player的智能指针,IWMPPlayer的定义见wmp.h,wndWMP是一个存放ActiveX控件的窗口(AX host window)。
4.生成和释放Windows Media Player。
LRESULT CMobileRadioView::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { CWindow wndPlaceholder = GetDlgItem ( IDC_WMP ); CRect rc; // Get the rect of the placeholder group box, then destroy // that window because we don't need it anymore. wndPlaceholder.GetWindowRect ( rc ); ScreenToClient ( rc ); wndPlaceholder.DestroyWindow(); // Create the AX host window. wndWMP.Create ( *this, rc, _T("{6BF52A52-394A-11d3-B153-00C04F79FAA6}"), WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN ); wndWMP.QueryControl(&(spWMPPlayer)); return TRUE; } LRESULT CMobileRadioView::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { // TODO: Add your message handler code here and/or call default if (spWMPPlayer) { spWMPPlayer->close(); spWMPPlayer.Release(); } wndWMP.Detach(); return 0; }
在OnInitDialog()函数中生成Windows Media Player对象,该对象存放在wndWMP里,而wndWMP使用了Placeholder(IDC_WMP)的位置。wndWMP生成时必须使用"{6BF52A52-394A-11d3-B153-00C04F79FAA6}", 该ID表示Windows Media Player。
5.播放
spWMPPlayer->put_URL(CComBSTR(http://streaming.mytalk.com.au/2ue));
只要把ASX(Advanced Stream Redirector)文件的设置到put_URL()函数就可以进行播放。那样不仅可以播放声音,而且可以播放图像。ASX可以参考http://en.wikipedia.org/wiki/Advanced_Stream_Redirector
OK,使用WTL开发Windows Media Player就那么简单,下一篇讲述tinyXML,使用tinyXML存储播放的配置数据,敬请期待。^_^
下面为在Windows Mobile 6.5的运行效果。
关于Mobile Radio - Internet Radio Software for Windows Mobile项目
目前(2009年9月份)这个项目基本功能已经完成,只是界面方面需要改进,提高用户体验。我把项目host到Mobile Radio - Internet Radio Software for Windows Mobile了,我会持续改进,主要是提高用户体验方面。需要了解项目最新动态,可以访问Mobile Radio - Internet Radio Software for Windows Mobile 和我的Blog 精简开发 无线生活。
源代码: 查看Mobile Radio最新源代码
环境:VS2008 + WM 6 professional SDK + WTL 8.1 + TinyXML
相关文章推荐
- 在Windows Mobile和Wince(Windows Embedded CE)下进行WTL开发,如何加入超链接(HyperLink)
- 在Windows Mobile和Wince(Windows Embedded CE)下使用.NET Compact Framework进行GPS NMEA data数据分析的开发
- 在Windows Mobile和Wince(Windows Embedded CE)下使用.NET Compact Framework进行GPS NMEA data数据分析的开发
- Windows Mobile和Wince下使用TinyXML进行Native C++的开发
- Windows Mobile和Wince(Windows Embedded CE )下使用.NET Compact Framework下注册表导出工具的开发
- Windows Mobile, WinCe使用 .NET Compact Framework 进行3G和RAS应用的开发
- 在Windows Mobile和Wince(Windows Embedded CE)下进行Native C++开发,如何取出资源文件中的版本信息
- 在Windows Mobile和Wince(Windows Embedded CE)下如何使用.NET Compact Framework开发进程管理程序
- Windows Mobile和Wince(Windows Embedded CE)下的WTL(Windows Template Library)开发
- Windows Moible, Wince 使用.NET Compact Framework的进行蓝牙(Bluetooth)开发 之 Windows Embedded Source Tools for Bluetooth
- 在Windows Mobile下使用WTL进行Native C++开发,如何显示等待图标
- 在Windows Mobile和Wince(Windows Embedded CE)下进行Native C++开发,如何取出当前执行文件的路径和调用模块的路径
- 在Windows Mobile和Wince(Windows Embedded CE)下如何使用.NET Compact Framework开发进程管理程序
- Windows Mobile, WinCe使用 .NET Compact Framework 进行3G和RAS应用的开发
- 如何使用Windows Azure Media Service进行开发(1)
- 在WinCE中使用Windows Media Player 控件
- 如何使用Windows Azure Media Service进行开发(2)
- 在Windows Mobile和Wince(Windows Embedded CE)下进行Win32开发,取出窗口句柄的方法
- Windows Moible, Wince 使用.NET Compact Framework的进行蓝牙(Bluetooth)开发 之 Windows Embedded Source Tools for Bluetooth
- Windows Mobile 和 Wince(Windows Embedded CE) 下的 WTL(Windows Template Library) 界面(UI)开发