如何编写 Windows Mobile Smartphone 录音程序
2007-03-26 15:30
435 查看
录音是很实用的功能,我们可以用它录制语音笔记和电话通话,还可以用它来开发简单的语音聊天软件。当然,录音的用途不仅仅只有这些。
今天要介绍大家如何开发一个简单的 Windows Mobile Smartphone 录音程序,这个小程序包含录音和播放录音两个功能,还可以通过数字键盘的5键来控制录音和停止录音。
实现原理:OpenNETCF 已经封装好了一个录音机类和一个播放器类,我们把这两个类配合起来使用,就可以制作出一个简单的录音程序。这两个类在 OpenNETCF.Multimedia.Audio 命名空间下,通过引用 OpenNETCF.dll 就可以使用 Recorder 和 Player 这两个类。我使用的是 v1.4 版。
录音:
Recorder recorder = new Recorder();
// stream 必须是 recorder 所在类的字段,seconds 是录音的最长时间
recorder.RecordFor(stream, seconds, SoundFormats.Mono8bit11kHz);
停止录音:
recorder.Stop();
播放:
Stream s = File.OpenRead(file);
Player player = new Player();
player.Play(s);
停止播放:
player.Stop();
实现原理:如何注册键盘的5键为录音快捷键呢?Windows CE 提供了 RegisterHotKey 函数用于注册系统级的快捷键,而 UnregisterHotKey 函数则用于注销系统级快捷键。
[DllImport("coredll.dll", EntryPoint = "RegisterHotKey", SetLastError = true)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers Modifiers, int key);
[DllImport("coredll.dll", EntryPoint = "UnregisterHotKey", SetLastError = true)]
private static extern bool UnRegisterHotKey(IntPtr hWnd, int key);
注册了系统级的快捷键后,我们要在 WndProc 方法中截取 WM_HOTKEY 消息,并进行相应的按键事件处理。但是 .NET CF 并没有像 .NET 完整版那样,将 WndProc 方法放在 System.Windows.Forms.Form 类中,而是放在了 Microsoft.WindowsCE.Forms.MessageWindow 类中。因此我们需要继承 MessageWindow,并实现 WM_HOTKEY 消息的截取。我们可以把注册快捷键这个功能封装到一个类里面。
录音程序效果如下:
![](http://www.cnblogs.com/images/cnblogs_com/upto/mobile/voice_recorder/2007-03-17_160255.PNG)
![](http://www.cnblogs.com/images/cnblogs_com/upto/mobile/voice_recorder/2007-03-17_160420.PNG)
源代码:VoiceRecorder.rar
在 OpenNETCF 2.0 的官方示例中提供了一个叫 MobileVoiceNotes 的示例,也是使用 Recorder 和 Player 类实现的。
用到的工具和组件在这里找:Windows Mobile Development Tools and Resources
今天要介绍大家如何开发一个简单的 Windows Mobile Smartphone 录音程序,这个小程序包含录音和播放录音两个功能,还可以通过数字键盘的5键来控制录音和停止录音。
实现原理:OpenNETCF 已经封装好了一个录音机类和一个播放器类,我们把这两个类配合起来使用,就可以制作出一个简单的录音程序。这两个类在 OpenNETCF.Multimedia.Audio 命名空间下,通过引用 OpenNETCF.dll 就可以使用 Recorder 和 Player 这两个类。我使用的是 v1.4 版。
录音:
Recorder recorder = new Recorder();
// stream 必须是 recorder 所在类的字段,seconds 是录音的最长时间
recorder.RecordFor(stream, seconds, SoundFormats.Mono8bit11kHz);
停止录音:
recorder.Stop();
播放:
Stream s = File.OpenRead(file);
Player player = new Player();
player.Play(s);
停止播放:
player.Stop();
实现原理:如何注册键盘的5键为录音快捷键呢?Windows CE 提供了 RegisterHotKey 函数用于注册系统级的快捷键,而 UnregisterHotKey 函数则用于注销系统级快捷键。
[DllImport("coredll.dll", EntryPoint = "RegisterHotKey", SetLastError = true)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers Modifiers, int key);
[DllImport("coredll.dll", EntryPoint = "UnregisterHotKey", SetLastError = true)]
private static extern bool UnRegisterHotKey(IntPtr hWnd, int key);
注册了系统级的快捷键后,我们要在 WndProc 方法中截取 WM_HOTKEY 消息,并进行相应的按键事件处理。但是 .NET CF 并没有像 .NET 完整版那样,将 WndProc 方法放在 System.Windows.Forms.Form 类中,而是放在了 Microsoft.WindowsCE.Forms.MessageWindow 类中。因此我们需要继承 MessageWindow,并实现 WM_HOTKEY 消息的截取。我们可以把注册快捷键这个功能封装到一个类里面。
录音程序效果如下:
源代码:VoiceRecorder.rar
在 OpenNETCF 2.0 的官方示例中提供了一个叫 MobileVoiceNotes 的示例,也是使用 Recorder 和 Player 类实现的。
用到的工具和组件在这里找:Windows Mobile Development Tools and Resources
相关文章推荐
- 如何编写 Windows Mobile Smartphone 录音程序
- 如何编写 Windows Mobile Smartphone 录音程序
- 如何编写 Windows Mobile Smartphone 录音程序
- 如何编写 Windows Mobile Smartphone 录音程序
- 如何编写 Windows Mobile Smartphone 录音程序
- QT for android编写的程序如何输出调试信息到android的log日志
- 如何组织编写模板程序
- 如何编写和调用java的jni程序
- 如何编写 Windows 服务程序
- 如何在 Windows Mobile 程序中获得包含 Millisecond 的 DateTime
- 如何在smartphone程序中指定textbox控件的输入法
- 如何编写一个高效的Java表达式求值程序
- 如何编写100% cache miss的C程序
- 用myeclipse如何编写java程序
- 通过学习学生信息管理系统软件,C程序中,如何设计和编写一个应用系统
- 如何编写AS程序——初学者第一课
- [摘自互联网]VB下如何编写CRC校验程序
- 如何用C#编写程序监测某个文件夹内是否有文件进行了增,删,改的动作?
- [C/C++]_[初级]_[如何编写简单有效代码,提高程序运行效率和性能]
- 如何编写C++程序