I have a program where the user can select the output device and play a sound. I am using NAudio, because it was the easiest way to have a way to select the output device. However it seems too hard for me to find a way to loop the sound in NAudio. Here's my code:
Dim xa() As Byte = IO.File.ReadAllBytes("/path") 'Your Buffer
Dim Wave1 As New NAudio.Wave.WaveOut 'Wave out device for playing the sound
Dim data As New IO.MemoryStream(xa) 'Data stream for the buffer
Dim deviceEnum = New MMDeviceEnumerator()
Dim devices = deviceEnum.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active).ToList()
Dim i = 0
Dim outputIndex = 0
For Each d As MMDevice In devices 'select output device index
If d.ToString = MediaOutputDevice Then
outputIndex = i
End If
i = i + 1
Next
Wave1.DeviceNumber = outputIndex
Wave1.Init(New NAudio.Wave.WaveFileReader(data))
Wave1.Play()
Any help for the sound alert loop in Naudio? I know I could play the sound with
Sub PlayLoopingBackgroundSoundFile()
My.Computer.Audio.Play("C:\Waterfall.wav",
AudioPlayMode.BackgroundLoop)
End Sub
but then I can't choose the output device.