WaveOut versus WaveOutEvent

只谈情不闲聊 提交于 2019-12-24 03:08:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!