NAudio.Wave.IWavePlayer.Init的重载方法匹配

时间:2015-06-16 20:42:04

标签: c# naudio

我尝试使用以下链接中的代码在我的.net项目中播放声音 http://mark-dot-net.blogspot.co.uk/2014/02/fire-and-forget-audio-playback-with.html 并收到此错误 -

错误1最佳重载方法匹配' NAudio.Wave.IWavePlayer.Init(NAudio.Wave.IWaveProvider)'有一些无效的参数D:\ marathiTyping \ Marathi Typing \ Marathi Typing \ AudioPlaybackEngine.cs 26 9 Marathi Typing

错误2参数' 1':无法转换为' NAudio.Wave.SampleProviders.MixingSampleProvider' to' NAudio.Wave.IWaveProvider' D:\ marathiTyping \ Marathi Typing \ Marathi Typing \ AudioPlaybackEngine.cs 27 27 Marathi Typing 代码看起来像 -

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 个答案:

答案 0 :(得分:0)

您想要的Init版本是NAudio.Wave命名空间中的扩展方法,允许您传入ISampleProvider而不是IWaveProvider。如果代码没有编译,可能你使用的是旧版本的NAudio。