[英]Array of sounds in c#
我正在尝试制作一个程序,以像幻灯片一样显示图像,并且每次显示图片时,当前图像都会播放声音,每个图像都会播放不同的声音。 如何使用带有声音的阵列并播放阵列中的声音?
string[] sounds = new string[] { "nero", "fai", "mpanio", "tv1", "volta",
"sleep1" };
private int currentAudioIndex = 0;
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Stop();
try
{
timer1.Interval = 5000; // Next time, wait 5 secs
button1.BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject(arr1[currentImageIndex]);
new SoundPlayer(Properties.Resources.nero).Play();// plays only one sound "nero"
currentImageIndex++;
}
finally
{
if (currentImageIndex < arr1.Length)
timer1.Start();
}
}
我假设您有名为“ nero.wav”,“ fai.wav”等的wav文件资源...
从那里,您可以将资源作为Stream
加载,然后将流传SoundPlayer
构造函数:
Stream stream = Properties.Resources.ResourceManager.GetStream(arr1[currentImageIndex] + ".wav");
new SoundPlayer(stream).Play();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.