简体   繁体   English

NAudio-停止WaveOut播放

[英]NAudio - Stop WaveOut playback

I am using Naudio for a winform project, when the first form loads it basically call another form and initialize a WaveOut object passing the form handle to the constructor. 我正在将Naudio用于winform项目,当第一个窗体加载时,它基本上会调用另一个窗体并初始化将窗体句柄传递给构造函数的WaveOut对象。

//in form 1
{
   Form2 frm2 = new Form2();
   frm2.InitializeWaveOut(this.Handle);
   frm2.Show();
} 

//in form 2
public void InitializeWaveOut(IntPtr wHandle)
{
  WaveOut wo = new WaveOut(wHandle);
  wo.DeviceNumber = 0;

  // etc...
}

Form2_Load()
{
  wo.Play();
}

All is working, and the sounds are played correctly, but i need to be able to click a button to stop (pause) the audio for a limited time and then resume it. 一切正常,并且声音可以正确播放,但是我需要能够单击按钮以在有限的时间内停止(暂停)音频,然后恢复它。 Once again this is working correctly but only if i load one instance of form2, as soon as I load a second instance of it and try to stop the audio on the first created instance of form2, it hangs, while the second one keeps functioning. 再次,它可以正常工作,但前提是我加载了一个form2实例,一旦我加载了它的第二个实例并尝试停止在第一个创建的form2实例上的音频,它就会挂起,而第二个实例仍能正常运行。 I need a way to stop the audio on a form without hanging the other, on the same devicenumber. 我需要一种方法来停止窗体上的音频,而又不将其挂在同一设备编号上。

不要将句柄传递到WaveOut -默认构造函数将为每个实例创建一个单独的句柄,因此不会混淆其消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM