[英]Naudio - 'WaveOut' does not contain a constructor that takes '3' arguments
this question derives from my previous thread Play mp3 from internet without FileOpenDialog 这个问题来自我之前的线程, 在没有FileOpenDialog的情况下从互联网播放mp3
I really hope someone knows anything about this. 我真的希望有人对此有所了解。 I was told to use a WebRequest to start a download stream and then play the stream instead of playing a locally stored file.
有人告诉我使用WebRequest启动下载流,然后播放流而不是播放本地存储的文件。 However, trying to use the code from PlayMp3FromUrl gives me this error:
但是,尝试使用PlayMp3FromUrl中的代码给我这个错误:
"'NAudio.Wave.WaveOut' does not contain a constructor that takes '3' arguments" “'NAudio.Wave.WaveOut'不包含采用'3'参数的构造函数”
Compiling failes at this line: 在此行编译失败:
using (WaveOut waveOut = new WaveOut(0, 500, null))
This is the full code: 这是完整的代码:
public static void PlayMp3FromUrl(string url)
{
using (MemoryStream ms = new MemoryStream())
{
using (Stream stream = WebRequest.Create(url)
.GetResponse().GetResponseStream())
{
byte[] buffer = new byte[32768];
int read;
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
}
ms.Position = 0;
using (WaveStream blockAlignedStream =
new BlockAlignReductionStream(
WaveFormatConversionStream.CreatePcmStream(
new Mp3FileReader(ms))))
{
using (WaveOut waveOut = new WaveOut(0, 500, null))
{
waveOut.Init(blockAlignedStream);
waveOut.Play();
while (blockAlignedStream.Position < blockAlignedStream.Length)
{
System.Threading.Thread.Sleep(100);
}
}
}
}
}
Can someone help me find out which arguments the WaveOut takes? 有人可以帮助我找出WaveOut采取哪些论点吗?
Edit: You probably want to look at the WaveOut.cs, and it's pretty long. 编辑:您可能想看一下WaveOut.cs,它很长。 So just have a look at it here WaveOut.cs
所以在这里看看它WaveOut.cs
I've never used the waveout class, I would suggest using DirectX if you could. 我从未使用过waveout类,如果可以的话,我建议使用DirectX。
using (IWavePlayer directOut = new DirectSoundOut(300))
{
directOut.Init(blockAlignedStream);
directOut.Play();
while (blockAlignedStream.Position < blockAlignedStream.Length)
{
System.Threading.Thread.Sleep(100);
}
}
Just use the default constructor (no parameters). 只需使用默认构造函数(无参数)。 The very latest NAudio code has properties on the WaveOut class instead of the old constructor with 3 parameters.
最新的NAudio代码具有WaveOut类的属性,而不是具有3个参数的旧构造函数。 If it causes lots of problems I might put the old constructor back though and mark it with the [Obsolete] attribute.
如果它引起很多问题,我可能会放回旧的构造函数,并用[Obsolete]属性标记它。
The first parameter was the device number. 第一个参数是设备编号。 0 means use the default device.
0表示使用默认设备。
The second was the latency. 第二个是等待时间。 500ms is the amount of audio we buffer up in advance.
500ms是我们预先缓冲的音频量。 This is a very conservative figure and should ensure glitch free playback.
这是一个非常保守的数字,应确保无干扰播放。
The third is to do with the callback mechanism for waveOut. 第三是与waveOut的回调机制有关。 Unfortunately there is no one-size-fits all solution.
不幸的是,没有一种适合所有解决方案的解决方案。 If you pass null, NAudio will use function callbacks, but this can hang on certain audio chipsets.
如果传递null,则NAudio将使用函数回调,但这可能会挂在某些音频芯片组上。 It's better to pass a window handle if at all possible.
最好尽可能传递一个窗口句柄。
You are passing three arguments to the WaveOut constructor: 0, 500, null but there is no constructor on the WaveOut class that takes that many arguments. 您正在将三个参数传递给WaveOut构造函数:0、500,null,但WaveOut类上没有构造函数接受那么多参数。
Why are you passing three arguments to the WaveOut constructor? 为什么要向WaveOut构造函数传递三个参数?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.