Naudio,如何判断回放已经完成

时间:2022-09-08 22:38:36

I am using the NAudio library to write a simple WinForms audio recorder/player. My problem is how can I tell that playback is completed? I need to close the wave stream after that.

我正在使用NAudio库编写一个简单的WinForms录音机/播放器。我的问题是,我怎么知道回放已经完成了?在那之后我需要关闭波浪流。

I knew there is a PlaybackStopped event listed below:

我知道下面列出了一个playbackstop事件:

wfr = new NAudio.Wave.WaveFileReader(this.outputFilename);
audioOutput = new DirectSoundOut();
WaveChannel32 wc = new NAudio.Wave.WaveChannel32(wfr); 
audioOutput.Init(wc);
audioOutput.PlaybackStopped += new EventHandler<StoppedEventArgs>(audioOutput_PlaybackStopped);
audioOutput.Play();

But this PlaybackStopped event seems can only be triggered by calling audioOutput.stop(), does anyone know how to determine if playback is completed?

但是,这个playbackstop事件似乎只能通过调用audioOutput.stop()来触发,有没有人知道如何确定回放是否已经完成?

I create an open source project for this question, you can find it here: https://code.google.com/p/stack-overflow-questions/

我为这个问题创建了一个开源项目,您可以在这里找到它:https://code.google.com/p/stack-overflow-questions/。

1 个解决方案

#1


7  

The PlaybackStopped event is raised when you either manually stop playing, or the Read method of the IWaveProvider you are using returns 0. The issue here is that WaveChannel32 does not stop returning data when it's source stream ends, so playback never ends. The PadWithZeroes property should be set to false to fix this.

当您手动停止播放或使用的IWaveProvider的Read方法返回0时,将引发PlaybackStopped事件。这里的问题是,WaveChannel32在源流结束时不会停止返回数据,因此回放永远不会结束。PadWithZeroes属性应该设置为false来修复这个问题。

#1


7  

The PlaybackStopped event is raised when you either manually stop playing, or the Read method of the IWaveProvider you are using returns 0. The issue here is that WaveChannel32 does not stop returning data when it's source stream ends, so playback never ends. The PadWithZeroes property should be set to false to fix this.

当您手动停止播放或使用的IWaveProvider的Read方法返回0时,将引发PlaybackStopped事件。这里的问题是,WaveChannel32在源流结束时不会停止返回数据,因此回放永远不会结束。PadWithZeroes属性应该设置为false来修复这个问题。