I'm trying to play sounds in my .net project using code from link below http://mark-dot-net.blogspot.co.uk/2014/02/fire-and-forget-audio-playback-with.html and getting this error-
Error 1 The best overloaded method match for 'NAudio.Wave.IWavePlayer.Init(NAudio.Wave.IWaveProvider)' has some invalid arguments D:\marathiTyping\Marathi Typing\Marathi Typing\AudioPlaybackEngine.cs 26 9 Marathi Typing
Error 2 Argument '1': cannot convert from 'NAudio.Wave.SampleProviders.MixingSampleProvider' to 'NAudio.Wave.IWaveProvider' D:\marathiTyping\Marathi Typing\Marathi Typing\AudioPlaybackEngine.cs 27 27 Marathi Typing The code looks like-
using NAudio.Wave;
using NAudio.Wave.SampleProviders;
public int sampleRate, channelCount;
public AudioPlaybackEngine()
{
sampleRate = 44100;
channelCount = 2;
outputDevice = new WaveOutEvent();
mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount));
mixer.ReadFully = true;
outputDevice.Init(mixer);
outputDevice.Play();
}
public AudioPlaybackEngine(int sRate, int cCount)
{
sampleRate = sRate;
channelCount = cCount;
outputDevice = new WaveOutEvent();
mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount));
mixer.ReadFully = true;
outputDevice.Init(mixer);
outputDevice.Play();
}
The version of
Inityou want is an extension method in theNAudio.Wavenamespace allowing you to pass in anISampleProviderinstead of anIWaveProvider. If the code doesn't compile, maybe you are using an old version of NAudio.