本文介绍了使用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);
}
} 

推荐答案

public static void Loop(int sampleNumber, bool Loop)
{
    Sample[sampleNumber].SetLoop(Loop);
}



这篇关于使用Naudio重复播放声音文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:22
查看更多