我只想在audioOutput_PlaybackStopped中显示消息框。有人可以帮忙吗?我用了Naudio。
这是我的代码:
public void playRecordedUser()
{
pcm = new WaveChannel32(new WaveFileReader(@"D:\2.wav"));
//.PadWithZeroes = false;
reductionStream = new BlockAlignReductionStream(pcm);
waveOutDevice = new DirectSoundOut();
waveOutDevice.PlaybackStopped += new EventHandler<StoppedEventArgs>(audioOutput_PlaybackStopped);
waveOutDevice.Init(reductionStream);
waveOutDevice.Play();
// pcm.Close();
// waveOutDevice.Dispose();
}
void audioOutput_PlaybackStopped(object sender, StoppedEventArgs e)
{
MessageBox.Show("hey");
waveOutDevice.Stop();
reductionStream.Close();
waveOutDevice.Dispose();
waveOutDevice = null;
pcm.Close();
}
答案 0 :(得分:0)
问题是WaveChannel32
继续在您提供的流的末尾返回数据,因此输出将继续播放。
而不是您当前的WaveFileReader
- &gt; WaveChannel32
- &gt; BlockAlignReductionStream
链,试试WaveFileReader
- &gt; BlockAlignReductionStream
- &gt; Wave16ToFloatProvider
喜欢这样:
var reduce = new BlockAlignReductionStream(new WaveFileReader(@"D:\2.wav"));
var provider = new Wave16ToFloatProvider(reduce);
waveOutDevice = new DirectSoundOut();
waveOutDevice.PlaybackStopped += new EventHandler<StoppedEventArgs>(audioOutput_PlaybackStopped);
waveOutDevice.Init(provider);
waveOutDevice.Play();
这将播放到波形文件的末尾,然后表示播放结束。
请勿忘记在播放完成后处理reduce
对象。