我想问一下如何将waw声音保存到变量中。在程序中我有3个按钮,当点击我想播放不同的声音。现在我得到了它
`SoundPlayer playDeath = new SoundPlayer(Properties.Resources.death);
playDeath.Play();`
我尝试将音频保存到变量并播放,但它不起作用。
SoundPlayer player = new SoundPlayer ();
Bitmap sound;
sound = Properties.Resources.death;
player.Play(sound);
有没有办法通过单击按钮来保存变量声音。例如
SoundPlayer player = new SoundPlayer ();
private void button1_Click(object sender, EventArgs e)
{
sound = Properties.Resources.death;
player.Play(sound);
}
private void button2_Click(object sender, EventArgs e)
{
sound = Properties.Resources.levelUp;
player.Play(sound);
}
由于
答案 0 :(得分:2)
您必须为正在使用的资源使用适当的变量类型。对于.wav文件,Bitmap肯定不是正确的类型。您可能希望使用System.IO.Stream
作为类型:
System.IO.Stream sound = Properties.Resources.death;
player.Play(sound);