单击按钮打开Windows录音机 [英] Open Windows sound recorder on button click

查看:202
本文介绍了单击按钮打开Windows录音机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想在我的应用程序中包含一个功能,以便当用户单击按钮时,用户应该能够记录语音,而在停止时,应该保存声音.这是我为开始和停止"按钮编写的内容

Hi,
I want to include a functionality in my application such that when the user clicks on a button, the user should be able to record the voice, and when stopped, the sound should be saved. Here''s what I wrote for the Start and Stop button

int i=0;
private void button1_Click(object sender, EventArgs e)
    {
      Button btnStrtStop = (Button)sender;
      if (i == 0)
      {
        //Record code
        btnStrtStop.BackgroundImage = System.Drawing.Image.FromFile("RecordPressed.png");
        toolTip1.SetToolTip(button1, "Stop");
        mciSendString("Open new type waveaudio alias RecSound", "", 0, 0);
        mciSendString("Record Recsound", "", 0, 0);
        //Button3.BackgroundImage = System.Drawing.Image.FromFile(ofdButtonPicture.FileName)
        i = 1;
      }
      else
      {
        //Stop Code
string strAppDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
        btnStrtStop.BackgroundImage = System.Drawing.Image.FromFile("RecordHot.png");
        toolTip1.SetToolTip(button1, "Record");
        mciSendString("Save RecSound" + strAppDir + "record.wav", "", 0, 0);
        mciSendString("Close RecSound", "", 0, 0);
        i = 0;
      }
    }


我面临的问题是背景图像找不到开始停止"按钮的背景图像.我没有使用打开文件"对话框,但在项目目录本身中有两个png文件.

对于播放按钮,我使用了


The problem I am facing is that the background image is not find the backgournd image for Start Stop button. I am not using the Open File Dialog but I have the two png files in the project directory itself.

For the play button, I have used

System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
myPlayer.SoundLocation = @"c:\file.wav";
myPlayer.Play();



我将不得不从调试文件夹中的相同路径加载文件.如何指定?
此外,与文件名中的先前代码不同,文件名中的常量是"file.wav",我想为我们保存的每个文件提供自定义文件名.



I would have to load the file from the same path in the debug folder. how to specify that?
Also, unlike the previous code in the filename is constant "file.wav ", I want to provide a custom filename for each file we save.

推荐答案

你说被保存在项目目录中.

当您运行或编译应用程序时,它将最终移至其他位置,例如bin \ debug或其他位置.

该应用程序将不存在图像的位置的概念.您需要指定在IDE中将文件复制为输出",或将图像作为某种形式的嵌入式资源包含在项目exe中.

另一个选择是添加2个图像控件,将图像源指向文件,然后根据需要显示/隐藏这些图像.这样可以确保图像包含在应用程序中.
The images as you say are being kept in the project directory.

When you run or compile the application it will end up in another location e.g. bin\debug or some other location.

The app will have no concept of where the images exist. You will need to specify the files are ''copied to output'' in the IDE, or include the images as some form of embedded resource within the project exe.

Another option is to add 2 image controls, point the image source to the files, and then show/hide these to images as required. That will ensure the images are included within the application.


这篇关于单击按钮打开Windows录音机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆