sawass sawass

sawass sawass

  • NA
  • 36
  • 23.7k

repeat playback of a sound file with Naudi

May 25 2011 3:55 PM
hello,
I have a function that allows me play a sound file located in a database in all sound cards installed in my pc.I uses Naudio library.
How can I
repeat reading this file sound automatically and thank you in advance for your helpers
Here is my code:
private void PlaySoundInDevice(int deviceNumber, string fileName)
{
if (outputDevices.ContainsKey(deviceNumber))
{
outputDevices[deviceNumber].WaveOut.Dispose();
outputDevices[deviceNumber].WaveStream.Dispose();
}
var waveOut = new WaveOut();
waveOut.DeviceNumber = deviceNumber;
WaveStream waveReader = new WaveFileReader(fileName);
// hold onto the WaveOut and WaveStream so we can dispose them later
outputDevices[deviceNumber] = new PlaybackSession { WaveOut = waveOut, WaveStream = waveReader };

waveOut.Init(waveReader);
waveOut.Play();
}

private Dictionary<int, PlaybackSession> outputDevices = new Dictionary<int, PlaybackSession>();

class PlaybackSession
{
public IWavePlayer WaveOut { get; set; }
public WaveStream WaveStream { get; set; }
}
private void DisposeAll()
{
foreach (var playbackSession in outputDevices.Values)
{
playbackSession.WaveOut.Dispose();
playbackSession.WaveStream.Dispose();
}
}
public void PlayInAllAvailableDevices(string fileName)
{
int waveOutDevices = WaveOut.DeviceCount;
for (int n = 0; n < waveOutDevices; n++)
{
PlaySoundInDevice(n, fileName);
}
}


Answers (4)