使用 C# 从电视卡捕获声音
我编写了一个 WPF 应用程序,它通过 C# 代码捕获电视卡的显示和声音。我可以从电视卡获得显示,但无法从电视卡获得任何声音。顺便说一句,我正在使用 .NET Framework 3.5 和 Visual Studio 2010。我的问题是如何从电视卡获取声音?
最后,我通过使用 DirectX 的 DirectSound 库尝试了如下所示的操作。但是,我收到以下错误。
- 最佳重载方法匹配
'Microsoft.DirectX.DirectSound.Device.SetCooperativeLevel(System.Windows.Forms.Control, Microsoft.DirectX.DirectSound.CooperativeLevel)'
有一些无效的 论据。 - 参数 1:无法从
'Wpfvideo.MainWindow'
转换为'System.Windows.Forms.Control'
代码:
private DS.Device soundDevice;
private SecondaryBuffer buffer;
private ArrayList soundlist = new ArrayList();
private void InitializeSound()
{
soundDevice = new DS.Device();
soundDevice.SetCooperativeLevel(this, CooperativeLevel.Priority);
BufferDescription description = new BufferDescription();
description.ControlEffects = false;
buffer = new SecondaryBuffer(CaptureDeviceName, description, soundDevice);
buffer.Play(0, BufferPlayFlags.Default);
SecondaryBuffer newshotsound = buffer.Clone(soundDevice);
newshotsound.Play(0, BufferPlayFlags.Default);
}
I have written a WPF application which is capturing display and sound from TV Card from with through C# code. I can get the display from TV card, but I can't get any sound from TV Card. BTW, I'm using .NET framework 3.5 with Visual Studio 2010. My question is how can I get the sound from the TV card?
Lastly, I tried anything like below by using DirectSound library of DirectX. However, I got the following errors.
- The best overloaded method match for
'Microsoft.DirectX.DirectSound.Device.SetCooperativeLevel(System.Windows.Forms.Control,
has some invalid
Microsoft.DirectX.DirectSound.CooperativeLevel)'
arguments. - Argument 1: cannot convert from
'Wpfvideo.MainWindow'
to'System.Windows.Forms.Control'
Code:
private DS.Device soundDevice;
private SecondaryBuffer buffer;
private ArrayList soundlist = new ArrayList();
private void InitializeSound()
{
soundDevice = new DS.Device();
soundDevice.SetCooperativeLevel(this, CooperativeLevel.Priority);
BufferDescription description = new BufferDescription();
description.ControlEffects = false;
buffer = new SecondaryBuffer(CaptureDeviceName, description, soundDevice);
buffer.Play(0, BufferPlayFlags.Default);
SecondaryBuffer newshotsound = buffer.Clone(soundDevice);
newshotsound.Play(0, BufferPlayFlags.Default);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
对
soundDevice.SetCooperativeLevel(...)
的调用需要一个 winforms 控件作为它的第一个参数,并且您尝试为其提供一个 WPF 窗口(不是 winforms 控件)。The call to
soundDevice.SetCooperativeLevel(...)
is expecting a winforms control as it's first parameter, and you're trying to give it a WPF window (which is not a winforms control).