0

Below is my code.I want a web application that I can access my local microphone and record. Then save it to my local files.I tried to run this code on visual studio 2017. The interface works fine. But it doesn't return me a .wav file. May I know if there's any problem with my code?

public partial class _Default : System.Web.UI.Page
{

    [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
    public static extern int mciSendString(
    string lpstrCommand,
    string lpstrReturnString,
    int uReturnLength,
    int hwndCallback
    );
    protected 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);
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        mciSendString("stop movie", "", 0, 0);
        mciSendString("save movie 1.wav", "", 0, 0);
        mciSendString("close movie", "", 0, 0);
    }
}
Jojo Hung
  • 15
  • 1
  • 6
  • 1
    In a *web* application recording is performed by the *browser* in Javascript, not the server. You posted *MCI commands* though that can only be used to *play* audio or movies using Media Player, only on desktop applications, on the local machine. Either the server started playing that tune or `mciSendString` returned an error – Panagiotis Kanavos Dec 19 '18 at 09:04
  • If you want the *browser* to play something, use the appropriate HTML tags like [ – Panagiotis Kanavos Dec 19 '18 at 09:05

0 Answers0