Playing a .wav file using naudio, playback stops after 1 sec

前端 未结 1 1737
被撕碎了的回忆
被撕碎了的回忆 2021-01-18 18:45

I\'m using the naudio lib in C# and want to play a simple file. The problem is, the playback stops after 1 second. I cant figure out the reason why it does that.

<         


        
1条回答
  •  粉色の甜心
    2021-01-18 19:21

    You need to make sure you are using function callbacks if you are trying to play audio from a console app, since the default for WaveOut is to use window callbacks.

    new WaveOut(WaveCallbackInfo.FunctionCallback())
    

    Update: With newer versions of NAudio I now recommend that you avoid function callbacks, as they can cause deadlocks with certain drivers. Instead, WaveOutEvent which uses event callbacks and a background thread is the preferred mechanism:

    new WaveOutEvent()
    

    0 讨论(0)
提交回复
热议问题