using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace MCI_record_play
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
[DllImport("winmm.dll")]
public static extern int mciSendString(
string lpszCommand,
string lpszReturnString,
uint cchReturn,
IntPtr hwndCallback
);
// MCIERROR mciSendString(
// LPCTSTR lpszCommand,
// LPTSTR lpszReturnString,
// UINT cchReturn,
// HANDLE hwndCallback
// );
private System.Windows.Forms.Button buttonBeginRecord;
private System.Windows.Forms.Button buttonEndRecord;
private System.Windows.Forms.Button buttonBeginPlay;
private System.Windows.Forms.Button buttonEndPlay;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonBeginRecord = new System.Windows.Forms.Button();
this.buttonEndRecord = new System.Windows.Forms.Button();
this.buttonBeginPlay = new System.Windows.Forms.Button();
this.buttonEndPlay = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// buttonBeginRecord
//
this.buttonBeginRecord.Location = new System.Drawing.Point(16, 64);
this.buttonBeginRecord.Name = "buttonBeginRecord";
this.buttonBeginRecord.Size = new System.Drawing.Size(104, 23);
this.buttonBeginRecord.TabIndex = 0;
this.buttonBeginRecord.Text = "Begin Recording";
this.buttonBeginRecord.Click += new System.EventHandler(this.buttonBeginRecord_Click);
//
// buttonEndRecord
//
this.buttonEndRecord.Enabled = false;
this.buttonEndRecord.Location = new System.Drawing.Point(160, 64);
this.buttonEndRecord.Name = "buttonEndRecord";
this.buttonEndRecord.Size = new System.Drawing.Size(96, 23);
this.buttonEndRecord.TabIndex = 1;
this.buttonEndRecord.Text = "End Recording";
this.buttonEndRecord.Click += new System.EventHandler(this.buttonEndRecord_Click);
//
// buttonBeginPlay
//
this.buttonBeginPlay.Location = new System.Drawing.Point(16, 128);
this.buttonBeginPlay.Name = "buttonBeginPlay";
this.buttonBeginPlay.Size = new System.Drawing.Size(96, 23);
this.buttonBeginPlay.TabIndex = 2;
this.buttonBeginPlay.Text = "Begin Playback";
this.buttonBeginPlay.Click += new System.EventHandler(this.buttonBeginPlay_Click);
//
// buttonEndPlay
//
this.buttonEndPlay.Enabled = false;
this.buttonEndPlay.Location = new System.Drawing.Point(160, 128);
this.buttonEndPlay.Name = "buttonEndPlay";
this.buttonEndPlay.Size = new System.Drawing.Size(96, 23);
this.buttonEndPlay.TabIndex = 3;
this.buttonEndPlay.Text = "End Playback";
this.buttonEndPlay.Click += new System.EventHandler(this.buttonEndPlay_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.buttonEndPlay,
this.buttonBeginPlay,
this.buttonEndRecord,
this.buttonBeginRecord});
this.Name = "Form1";
this.Text = "Audio Recorder and Player";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
void mciExecute(string s_cmd)
{
mciSendString(s_cmd, null, 0, IntPtr.Zero);
}
private void buttonBeginRecord_Click(object sender, System.EventArgs e)
{
mciExecute("open new type waveaudio alias mysound");
mciExecute("record mysound");
buttonBeginRecord.Enabled = false;
buttonEndRecord.Enabled = true;
buttonBeginPlay.Enabled = false;
buttonEndPlay.Enabled = false;
}
private void buttonEndRecord_Click(object sender, System.EventArgs e)
{
mciExecute("stop mysound");
mciExecute("save mysound record1.wav");
mciExecute("close mysound");
buttonBeginRecord.Enabled = true;
buttonEndRecord.Enabled = false;
buttonBeginPlay.Enabled = true;
buttonEndPlay.Enabled = false;
}
private void buttonBeginPlay_Click(object sender, System.EventArgs e)
{
mciExecute("open record1.wav alias mysound");
mciExecute("play mysound");
buttonBeginRecord.Enabled = false;
buttonEndRecord.Enabled = false;
buttonBeginPlay.Enabled = false;
buttonEndPlay.Enabled = true;
}
private void buttonEndPlay_Click(object sender, System.EventArgs e)
{
mciExecute("stop mysound");
mciExecute("close mysound");
buttonBeginRecord.Enabled = true;
buttonEndRecord.Enabled = false;
buttonBeginPlay.Enabled = true;
buttonEndPlay.Enabled = false;
}
}
}