C# Can';t播放“我的参考资料”文件夹中的声音
我知道这很简单,但这让我发疯。我已将wave文件加载到我的应用程序资源/引用文件位置。我只想播放这个波形文件5秒钟。我在互联网上到处搜索,没有人有一个简单的解决方案。我看得不够仔细,还是比看上去更复杂? 以下是我的代码示例:C# Can';t播放“我的参考资料”文件夹中的声音,c#,C#,我知道这很简单,但这让我发疯。我已将wave文件加载到我的应用程序资源/引用文件位置。我只想播放这个波形文件5秒钟。我在互联网上到处搜索,没有人有一个简单的解决方案。我看得不够仔细,还是比看上去更复杂? 以下是我的代码示例: if (attempts == win) { label1.Text = "Great job!"; level += 1; i = 0; attempts = ""; win = ""; cheaterLabel.Text
if (attempts == win)
{
label1.Text = "Great job!";
level += 1;
i = 0;
attempts = "";
win = "";
cheaterLabel.Text = "";
}
我在VisualStudio2008工作。谢谢大家! 这个例子就是这样的
这比你想象的还要容易
if (attempts == win)
{
playSimpleSound();
label1.Text = "Great job!";
level += 1;
i = 0;
attempts = "";
win = "";
cheaterLabel.Text = "";
}
private void playSimpleSound()
{
SoundPlayer simpleSound = new SoundPlayer(@"c:\SomeFile\someSound.wav");
simpleSound.Play();
}
既然您说您的应用程序资源中有您的文件,那么您应该能够使用SoundPlayer执行类似的操作。我通过转到项目-->属性-->资源添加了该文件
SoundPlayer sp = new SoundPlayer(Properties.Resources.chord); \\Change to what ever the name of your resource is
sp.Play();
也许这有帮助这段代码不是关于声音。我是说。。。一点也不,声音在哪里?我明白了。。。标签..数字..另一个数字(可能是INT)、两个字符串和另一个标签。