overloaded method match for NAudio.Wave.IWavePlayer.Init

563 views Asked by At

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();
  }
1

There are 1 answers

0
Mark Heath On BEST ANSWER

The version of Init you want is an extension method in the NAudio.Wave namespace allowing you to pass in an ISampleProvider instead of an IWaveProvider. If the code doesn't compile, maybe you are using an old version of NAudio.