winmm.dll 录音

2018-01-22  本文已影响175人  萧非子

using System.Runtime.InteropServices;

    [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
    public static extern int mciSendString(
     string lpstrCommand,
     string lpstrReturnString,
     int uReturnLength,
     int hwndCallback
    );
    private void button1_Click(object sender, EventArgs e)
    {
        mciSendString("set wave bitpersample 8", "", 0, 0);

        mciSendString("set wave samplespersec 20000", "", 0, 0);
        mciSendString("set wave channels 2", "", 0, 0);
        mciSendString("set wave format tag pcm", "", 0, 0);
        mciSendString("open new type WAVEAudio alias movie", "", 0, 0);

        mciSendString("record movie", "", 0, 0);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        mciSendString("stop movie", "", 0, 0);
        mciSendString("save movie 1.wav", "", 0, 0);
        mciSendString("close movie", "", 0, 0);
    }

button1是开始录音,button2是结束录音。你当然也可以通过逻辑判断来只使用一个button。

上一篇下一篇

猜你喜欢

热点阅读