2011-09-01 49 views
6

我已經寫了一個WPF應用程序,它通過C#代碼從電視卡捕獲顯示和聲音。我可以從電視卡上獲得顯示,但是我無法從電視卡獲得任何聲音。順便說一句,我在Visual Studio 2010中使用.NET framework 3.5。我的問題是如何從電視卡中獲取聲音?從C#的電視卡捕捉聲音#

最後,我使用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); 
} 
+0

因爲SetCooperativeLevel方法需要一個Windows窗體控件你所得到的錯誤,你是傳遞一個WPF窗口。 –

+0

感謝您的回覆。我該怎麼辦? – Selo

+0

沒有「修復」,你不能把一個wpf窗口變成一個winforms控件。 –

回答

4

試試這個:

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

soundDevice.SetCooperativeLevel(...)呼叫期待一個WinForms控制,因爲它是第一個參數,你想給它一個WPF窗口(它不是一個winforms控件)。