Hi Mark,
i think this worth notice: the below code works fine (despite the audio is set to "dataflow.render" mode , rather than "dataflow.capture" mode) as per the discussion in the above link.
the only thing i noticed is : when calling the "wasapi.stoprecording method, the software freezes, i am still working on it.
the code now looks as follows:
Imports naudio
Imports naudio.wave
Imports NAudio.CoreAudioApi
Public Class Form1
Dim WithEvents Wasapi As WasapiLoopbackCapture
Dim Writer As WaveFileWriter
Dim mmdev As MMDeviceEnumerator
Dim Audio As MMDevice
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mmdev = New MMDeviceEnumerator
'Audio.AudioClient.Initialize(AudioClientShareMode.Shared, AudioClientStreamFlags.Loopback, 10000000, 0, Audio.AudioClient.MixFormat, System.Guid.Empty)
Audio = mmdev.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)
Wasapi = New WasapiLoopbackCapture(Audio)
Writer = New WaveFileWriter("E:\4.wav", Audio.AudioClient.MixFormat)
Wasapi.WaveFormat = Audio.AudioClient.MixFormat
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Application.Exit()
End Sub
Private Sub Wasapi_DataAvailable(sender As Object, e As WaveInEventArgs) Handles Wasapi.DataAvailable
Writer.Write(e.Buffer, 0, e.BytesRecorded)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Wasapi IsNot Nothing Then
Wasapi.StartRecording()
End If
''''
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If Wasapi IsNot Nothing Then
Wasapi.StopRecording()
Wasapi.Dispose()
Wasapi = Nothing
End If
''
''
If Writer IsNot Nothing Then
Writer.Flush()
Writer.Close()
Writer.Dispose()
Writer = Nothing
End If
''
End Sub
Private Sub Wasapi_RecordingStopped(sender As Object, e As EventArgs) Handles Wasapi.RecordingStopped
'''''
If Writer IsNot Nothing Then
Writer.Flush()
Writer.Close()
Writer.Dispose()
Writer = Nothing
End If
''''
If Wasapi IsNot Nothing Then
Wasapi.StopRecording()
Wasapi.Dispose()
Wasapi = Nothing
End If
''''
End Sub
End Class