问题
I'm using NAudio
with
WaveOutEvent Klangwiedergabegeraet;
private void Play(string Dateiname)
{
Klangwiedergabegeraet = new WaveOutEvent();
Klangwiedergabegeraet.DeviceNumber = comboBox1.SelectedIndex;
ISampleProvider StueckchenHalter = null;
StueckchenHalter = CreateInputStreamS(Dateiname);
Klangwiedergabegeraet.Init(new SampleToWaveProvider(StueckchenHalter));
Klangwiedergabegeraet.Play();
}
private void Cancel()
{
if (Klangwiedergabegeraet != null)
{
Klangwiedergabegeraet.Stop();
Klangwiedergabegeraet.Dispose();
}
}
When running Cancel()
, it won't stop. When I used
WaveOut Klangwiedergabegeraet;
private void Play(string Dateiname)
{
Klangwiedergabegeraet = new WaveOut();
...
}
private void Cancel()
{
if (Klangwiedergabegeraet != null)
{
Klangwiedergabegeraet.Stop();
Klangwiedergabegeraet.Dispose();
}
}
It worked. Why is this and what to change?
P.S I am using WaveOutEvent
instead of WaveOut
because WaveOut
does not have the property DeviceNumber
.
回答1:
If you are running on a non-GUI thread, then WaveOutEvent
is the recommended way to do things, not WaveOut
as that will choose function callbacks which can be unreliable on some soundcards. Also, WaveOut
does have a DeviceNumber
property.
来源:https://stackoverflow.com/questions/13208271/waveout-versus-waveoutevent