使用Naudio重复播放声音文件 [英] repeat playback of a sound file with Naudio
本文介绍了使用Naudio重复播放声音文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有一个功能,可以播放电脑中安装的所有声卡中位于数据库中的声音文件.我使用 Naudio库 [ ^ ].
如何重复自动读取此文件?并先感谢您的支持
这是我的代码:
hello,
I have a function that allows me play a sound file located in a database in all sound cards installed in my pc.I use Naudio library[^].
How can I repeat reading this file automatically? and thank you in advance for your support
Here is my code:
private void PlaySoundInDevice(int deviceNumber, string fileName)
{
if (outputDevices.ContainsKey(deviceNumber))
{
outputDevices[deviceNumber].WaveOut.Dispose();
outputDevices[deviceNumber].WaveStream.Dispose();
}
var waveOut = new WaveOut();
waveOut.DeviceNumber = deviceNumber;
WaveStream waveReader = new WaveFileReader(fileName);
// hold onto the WaveOut and WaveStream so we can dispose them later
outputDevices[deviceNumber] = new PlaybackSession { WaveOut = waveOut, WaveStream = waveReader };
waveOut.Init(waveReader);
waveOut.Play();
}
private Dictionary<int, PlaybackSession> outputDevices = new Dictionary<int, PlaybackSession>();
class PlaybackSession
{
public IWavePlayer WaveOut { get; set; }
public WaveStream WaveStream { get; set; }
}
private void DisposeAll()
{
foreach (var playbackSession in outputDevices.Values)
{
playbackSession.WaveOut.Dispose();
playbackSession.WaveStream.Dispose();
}
}
public void PlayInAllAvailableDevices(string fileName)
{
int waveOutDevices = WaveOut.DeviceCount;
for (int n = 0; n < waveOutDevices; n++)
{
PlaySoundInDevice(n, fileName);
}
}
推荐答案
我从未使用过Naudio库,所以也许这不是您想要的,但是我认为您可以在本文中找到答案:
http://opensebj.blogspot.com/2009/03/naudio-tutorial- 3-sample-properties.html
它提到了有关循环的内容:
I have never used Naudio library, so perhaps this is not what you are looking for, but I think you can find the answer in this article:
http://opensebj.blogspot.com/2009/03/naudio-tutorial-3-sample-properties.html
It mentions something about looping:
public static void Loop(int sampleNumber, bool Loop)
{
Sample[sampleNumber].SetLoop(Loop);
}
感谢Ruard的帮助.
我还有一个问题.我的项目还允许广播直接语音消息.我想在扩散消息开始之前添加提示音功能.该功能吸引人们的注意力,就像我们在机场听到的声音一样(丁董).您能帮我做这个功能吗,谢谢您.
Thanks Ruard for your help.
I have another problem.My project allows also broadcast a direct voice message .I want to add a chime function before the start of diffusion message.It is a function that attracts people''s attention like the tone we listen in an airport (ding dong). Will you help me to do this function.and thanks in advance.
这篇关于使用Naudio重复播放声音文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文