这个问题来自我之前的帖子Play mp3 from internet without FileOpenDialog
我真的希望有人知道这件事。我被告知要使用WebRequest启动一个下载流,然后播放该流,而不是播放本地存储的文件。但是,尝试使用PlayMp3FromUrl中的代码时会出现以下错误:
"'NAudio.Wave.WaveOut‘不包含接受'3’参数的构造函数“
在下面这一行编译失败:
using (WaveOut waveOut = new WaveOut(0, 500, null))这是完整的代码:
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);
}
}
}
}
}有人能帮我找出WaveOut采用了哪些参数吗?
编辑:你可能想看看WaveOut.cs,它很长。看一下这里,WaveOut.cs
发布于 2009-08-31 19:24:15
我从来没有使用过waveout类,如果可以的话,我建议您使用DirectX。
using (IWavePlayer directOut = new DirectSoundOut(300))
{
directOut.Init(blockAlignedStream);
directOut.Play();
while (blockAlignedStream.Position < blockAlignedStream.Length)
{
System.Threading.Thread.Sleep(100);
}
}发布于 2009-09-01 06:37:06
只需使用默认构造函数(无参数)即可。最新的NAudio代码具有WaveOut类的属性,而不是具有3个参数的旧构造函数。如果它导致了很多问题,我可能会把旧的构造函数放回去,并用过时属性标记它。
第一个参数是设备编号。0表示使用默认设备。
第二个是延迟。500ms是我们预先缓冲的音频量。这是一个非常保守的数字,应该可以确保播放时没有毛刺。
第三个是关于waveOut的回调机制。不幸的是,没有万能的解决方案。如果您传递null,NAudio将使用函数回调,但这可能在某些音频芯片组上挂起。如果可能的话,最好是传递一个窗口句柄。
发布于 2009-08-31 16:56:21
您向WaveOut构造函数传递了三个参数: 0,500,null,但是WaveOut类上没有接受这么多参数的构造函数。
为什么要向WaveOut构造函数传递三个参数?
https://stackoverflow.com/questions/1358018
复制相似问题