使用 C# 从电视卡捕获声音

发布于 2024-12-02 08:35:58 字数 1124 浏览 0 评论 0原文

我编写了一个 WPF 应用程序,它通过 C# 代码捕获电视卡的显示和声音。我可以从电视卡获得显示,但无法从电视卡获得任何声音。顺便说一句,我正在使用 .NET Framework 3.5 和 Visual Studio 2010。我的问题是如何从电视卡获取声音?

最后,我通过使用 DirectX 的 DirectSound 库尝试了如下所示的操作。但是,我收到以下错误。

  1. 最佳重载方法匹配 'Microsoft.DirectX.DirectSound.Device.SetCooperativeLevel(System.Windows.Forms.Control, Microsoft.DirectX.DirectSound.CooperativeLevel)' 有一些无效的 论据。
  2. 参数 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.

  1. The best overloaded method match for
    'Microsoft.DirectX.DirectSound.Device.SetCooperativeLevel(System.Windows.Forms.Control,
    Microsoft.DirectX.DirectSound.CooperativeLevel)'
    has some invalid
    arguments.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

滴情不沾 2024-12-09 08:35:58

试试这个:

var windowInteropHelper = new WindowInteropHelper(this);
soundDevice = new DS.Device();
soundDevice.SetCooperativeLevel(windowInteropHelper.Handle, CooperativeLevel.Priority);

Try this:

var windowInteropHelper = new WindowInteropHelper(this);
soundDevice = new DS.Device();
soundDevice.SetCooperativeLevel(windowInteropHelper.Handle, CooperativeLevel.Priority);
瀟灑尐姊 2024-12-09 08:35:58

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文