Playing a file using MCI
-
I have a small form for trying to record but I can't get it to work properly. I have the code below and I can record and play the created file in this application and other media players. The code creates a 8bit 11kHz mono. The problem is when I try to use the "set" parameters, any of them, then I can only play it back in this application, not with any other players. Am I doing something wrong?
using Microsoft.VisualBasic.Devices; using Microsoft.VisualBasic; using System.Runtime.InteropServices; using System.Windows.Forms; namespace Recorder { public partial class Form1 : Form { [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback); public Form1() { InitializeComponent(); } private void buttRecord_Click(object sender, System.EventArgs e) { // record from microphone mciSendString("open new Type waveaudio Alias recsound", "", 0, 0); mciSendString("format tag pcm", "", 0, 0); //mciSendString("set recsound bitspersample 8", "", 0, 0); //mciSendString("set recsound samplespersec 32000", "", 0, 0); mciSendString("set recsound channels 2", "", 0, 0); mciSendString("record recsound", "", 0, 0); } private void buttSaveStop_Click(object sender, System.EventArgs e) { // stop and save mciSendString("save recsound c:\\record.wav", "", 0, 0); mciSendString("close recsound ", "", 0, 0); Computer c = new Computer(); c.Audio.Stop(); } private void buttPlay_Click(object sender, System.EventArgs e) { Computer computer = new Computer(); computer.Audio.Play("c:\\record.wav", AudioPlayMode.Background); } } }
http://johanmartensson.se - Home of MPEG4Watcher