Capturing sound from TV Card with C#
Asked Answered
M

2

6

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);
} 
Marni answered 1/9, 2011 at 12:0 Comment(4)
You are getting the error because the SetCooperativeLevel method is expecting a windows forms control and you are passing it a WPF window.Fabric
thanks for your reply.What should I do?Marni
There is no "fix" for that you cant turn a wpf window into a winforms control.Fabric
@Selo: Can you shed any light on this timeline? meta.stackexchange.com/questions/105969/wheres-my-bounty-goneBurse
K
4

Try this:

var windowInteropHelper = new WindowInteropHelper(this);
soundDevice = new DS.Device();
soundDevice.SetCooperativeLevel(windowInteropHelper.Handle, CooperativeLevel.Priority);
Kitchenware answered 1/9, 2011 at 12:27 Comment(0)
D
0

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

Dagny answered 1/9, 2011 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.