Naudio,如何判断播放是否完成 [英] Naudio,how to tell playback is completed

查看:637
本文介绍了Naudio,如何判断播放是否完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NAudio库编写一个简单的WinForms音频记录器/播放器.我的问题是如何判断播放已完成?之后,我需要关闭波浪流.

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.

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

I knew there is a PlaybackStopped event listed below:

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();

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

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

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

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

推荐答案

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

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.

这篇关于Naudio,如何判断播放是否完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆