我们需要构建一个应用程序,它应该一次记录我们的桌面和来自麦克风的音频。该文件需要自动保存在指定路径中。我们尝试使用 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.");
}