无法播放位于我的参考文件夹中的声音
问题描述:
我知道这很简单,但这让我疯狂。我已经将我的wave文件加载到我的应用程序资源/参考文件位置中。我想要做的就是播放这个波形文件5秒钟。我在整个互联网上搜索过高和低,没有人有简单的解决方案。我看起来不够努力,还是比看起来更复杂? 这里是我的代码示例:无法播放位于我的参考文件夹中的声音
if (attempts == win)
{
label1.Text = "Great job!";
level += 1;
i = 0;
attempts = "";
win = "";
cheaterLabel.Text = "";
}
我与Visual Studio 2008年的工作,谢谢!
答
示例来自MSDN article。
好吧,它比你想象的还要容易。
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();
也许这有助于http://*.com/questions/1900707/how-to-play-audio-from-resource – V4Vendetta 2013-05-07 05:45:32
这段代码是不是声音。 。 。我的意思是......根本不是 – phadaphunk 2013-05-07 05:46:03
声音在哪里?我seeeee ...一个标签..一个数字..另一个数字(可能是一个INT),两个字符串和另一个标签。 – Scotch 2013-05-07 05:49:50