Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 诺迪奥';WaveOut';不包含采用';3';论据_C#_Constructor_Arguments_Naudio - Fatal编程技术网

C# 诺迪奥';WaveOut';不包含采用';3';论据

C# 诺迪奥';WaveOut';不包含采用';3';论据,c#,constructor,arguments,naudio,C#,Constructor,Arguments,Naudio,这个问题源于我以前的思路 我真希望有人知道这件事。我被告知使用WebRequest启动下载流,然后播放流,而不是播放本地存储的文件。 但是,尝试使用PlayMp3FromUrl中的代码时会出现以下错误: “'NAudio.Wave.WaveOut'不包含接受'3'参数的构造函数” 在这一行编译失败: using (WaveOut waveOut = new WaveOut(0, 500, null)) 这是完整的代码: public static void PlayMp3FromUrl(st

这个问题源于我以前的思路

我真希望有人知道这件事。我被告知使用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);
                    }
                }
            }
        }
    }
publicstaticvoidplaymp3fromURL(字符串url)
{
使用(MemoryStream ms=new MemoryStream())
{
使用(Stream=WebRequest.Create(url)
.GetResponse().GetResponseStream())
{
字节[]缓冲区=新字节[32768];
int-read;
而((read=stream.read(buffer,0,buffer.Length))>0)
{
ms.Write(缓冲区,0,读取);
}
}
ms.Position=0;
使用(WaveStream blockAlignedStream)=
新BlockAlignReductionStream(
波形转换流。创建PCMStream(
新的Mp3FileReader(ms)))
{
使用(WaveOut WaveOut=新的WaveOut(0500,空))
{
waveOut.Init(blockAlignedStream);
waveOut.Play();
while(blockAlignedStream.Position
有人能帮我找出WaveOut采用的论点吗

编辑:你可能想看看WaveOut.cs,它很长。
在这里看一下

您正在向WaveOut构造函数传递三个参数:0500,null,但是WaveOut类上没有接受那么多参数的构造函数


为什么要将三个参数传递给WaveOut构造函数?

我从未使用WaveOut类,如果可以,我建议使用DirectX

using (IWavePlayer directOut = new DirectSoundOut(300))               
{                    
   directOut.Init(blockAlignedStream);                    
   directOut.Play();                    
   while (blockAlignedStream.Position < blockAlignedStream.Length)
   {                       
      System.Threading.Thread.Sleep(100);                    
   }                
}
使用(IWavePlayer directOut=新的DirectSoundOut(300))
{                    
directOut.Init(blockAlignedStream);
directOut.Play();
while(blockAlignedStream.Position
只需使用默认构造函数(无参数)。最新的NAudio代码具有WaveOut类的属性,而不是具有3个参数的旧构造函数。如果它引起很多问题,我可能会把旧的构造函数放回去,并用[Observe]属性标记它

第一个参数是设备编号。0表示使用默认设备

第二个是延迟。500ms是我们预先缓冲的音频量。这是一个非常保守的数字,应确保无故障播放


第三个是waveOut的回调机制。不幸的是,没有一刀切的解决方案。如果传递null,NAudio将使用函数回调,但这可能挂起在某些音频芯片组上。如果可能的话,最好传递一个窗口句柄。

这是因为代码看起来像是由编写它的人编写的,在这个Stackoverflow链接中:我猜WaveOut.cs已经改变了,或者从那以后发生了什么。但是我不知道应该传递哪些参数。哇,这确实有效:)但是程序仍然冻结(在播放mp3文件时),是什么导致了这个问题?调试似乎也很困难,因为代码中发生了很多事情。我真的不知道是什么原因造成的。你的while循环阻塞了你的程序。将播放器设为一个类字段,并在其中运行start-stop命令,或者在另一个线程中处理它。好的,我不知道如何做到这一点。它需要很多改变吗?还有一件事,你知道流是如何存储在本地的吗?我会播放下载的缓存还是再次下载?我真的想要一些缓存。就像OpenFileDialog本身一样。据你所知,这可能吗?是的,我在C#很烂。。我试图用VB.NET来实现这一点,但遇到了困难。所以我想我应该试试C#原始来源。嗨,马克!我已经尝试过不使用任何参数。这会导致窗体完全冻结。而且播放似乎也不起作用。使用DirectSoundOut也会冻结表单,但播放会在大约3-4秒后工作。不幸的是,我是个十足的白痴,所以我不知道如何通过窗户把手。我想我知道这意味着什么,你已经在文档或类似的地方写了一些关于它的东西。但由于上述原因,我不知道如何做到这一点。