本代码特点:不用DirectX ,对于C/S 、B/S都适用。
方法:
[csharp]class="Apple-converted-space"> view plaincopy
- [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
- private static extern int mciSendString(
- string lpstrCommand,
- string lpstrReturnString,
- int uReturnLength,
- int hwndCallback);
-
- private static void mciSendString(String cmd)
- {
- mciSendString(cmd, "", 0, 0);
- }
-
- private static void StartRecord()
- {
- mciSendString("close movie");
- mciSendString("open new type WAVEAudio alias movie");
- mciSendString("record movie");
- }
-
- private static void StopRecord(string filename)
- {
- mciSendString("stop movie");
- mciSendString("save movie " + filename);
- mciSendString("close movie");
- }
用法举例:
[csharp] view plaincopy
- protected void btStart_Click(object sender, EventArgs e)
- {
-
- StartRecord();
- }
-
- protected void btStop_Click(object sender, EventArgs e)
- {
-
- StopRecord(@"C:\test.wav");
- }
-
- protected void btPlay_Click(object sender, EventArgs e)
- {
-
- SoundPlayer sp = new SoundPlayer(@"c:\test.wav");
- sp.PlaySync();
- }