如何一次从麦克风录制桌面和音频?

时间:2013-02-25 09:47:28

标签: c# winforms

我们需要构建一个应该一次从麦克风录制桌面和音频的应用程序。此文件需要自动保存在指定的路径中。我们尝试使用DLL windows media Encoder构建应用程序。但是我们面临的问题是,会出现一个弹出窗口,将该部分手动保存到系统文件夹中。这工作正常。但是我们不需要显示弹出窗口,该部分应该自动保存到指定的路径。我们从这里尝试过,但保存的部分缺少音频的某些部分。任何人都可以帮助我们找到解决方案吗? 请检查以下代码,

     try
        {
            if (DesktopEncoder != null)
            {
                DesktopEncoder.Stop();
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Filter = "Video Files (*.wmv)|*.wmv";
                dialog.DefaultExt = "wmv";
                DialogResult res = dialog.ShowDialog();
                if (res != DialogResult.Cancel)
                {
                    if (File.Exists(DirectoryPath + "\\Demo\\tempScreenRecordVideo\\tempscreenvideo.wmv"))//ConfigurationSettings.AppSettings["demoTempScreenRecordVideo"]
                    {
                        recentRecordingsToolStripMenuItem1.DropDownItems.Add(dialog.FileName, null, recentRecordings_Click);
                        recentRecordingsToolStripMenuItem.DropDownItems.Add(dialog.FileName, null, recentRecordings_Click);
                        if (File.Exists(dialog.FileName))
                            File.Delete(dialog.FileName);

                        File.Copy(DirectoryPath + "\\Demo\\tempScreenRecordVideo\\tempscreenvideo.wmv", dialog.FileName);//ConfigurationSettings.AppSettings["demoTempScreenRecordVideo"]
                        if (DesktopEncoder.RunState != WMENC_ENCODER_STATE.WMENC_ENCODER_RUNNING && DesktopEncoder.RunState != WMENC_ENCODER_STATE.WMENC_ENCODER_PAUSED)
                        {
                            File.Delete(DirectoryPath + "\\Demo\\tempScreenRecordVideo\\tempscreenvideo.wmv");//ConfigurationSettings.AppSettings["demoTempScreenRecordVideo"]
                        }
                        if (File.Exists(DirectoryPath + "\\Demo\\ScreenRecordVideo\\screenvideo.wmv"))//ConfigurationSettings.AppSettings["demoScreenRecordVideo"]
                            File.Delete(DirectoryPath + "\\Demo\\ScreenRecordVideo\\screenvideo.wmv");//ConfigurationSettings.AppSettings["demoScreenRecordVideo"]
                        File.Copy(dialog.FileName, DirectoryPath + "\\Demo\\ScreenRecordVideo\\screenvideo.wmv");//ConfigurationSettings.AppSettings["demoScreenRecordVideo"]
                        File.Delete(dialog.FileName);
                    }
                }
                tmrRcCounter.Enabled = false;
                tsRecDuration.Text = "";
                tmrViewerCount.Enabled = false;
                if (this.Visible)
                {
                    notifyRecorder.Text = "Recorder is in Visible Mode.";
                }
                else
                {
                    notifyRecorder.Text = "Recorder is in Invisible Mode.";
                }
                //Windows Media Encoder EXE.
                Process[] ps = Process.GetProcessesByName("wmenc");
                if (ps.Length != 0)
                {
                    ps[0].Kill();
                }
                DesktopEncoder = null;
                tmrRcCounter.Enabled = false;
            }
        }
        catch
        {
            MessageBox.Show("Can't Stop it.Please,Save Current Recording and Restart Application.");
        }

0 个答案:

没有答案