2013-05-07 25 views
-1

我知道這很簡單,但這讓我瘋狂。我已經將我的wave文件加載到我的應用程序資源/參考文件位置中。我想要做的就是播放這個波形文件5秒鐘。我在整個互聯網上搜索過高和低,沒有人有簡單的解決方案。我看起來不夠努力,還是比看起來更復雜? 這裏是我的代碼示例:無法播放位於我的參考文件夾中的聲音

if (attempts == win) 
{ 
    label1.Text = "Great job!"; 
    level += 1; 
    i = 0; 
    attempts = ""; 
    win = ""; 
    cheaterLabel.Text = ""; 
} 

我與Visual Studio 2008年的工作,謝謝!

+0

也許這有助於http://stackoverflow.com/questions/1900707/how-to-play-audio-from-resource – V4Vendetta 2013-05-07 05:45:32

+2

這段代碼是不是聲音。 。 。我的意思是......根本不是 – phadaphunk 2013-05-07 05:46:03

+0

聲音在哪裏?我seeeee ...一個標籤..一個數字..另一個數字(可能是一個INT),兩個字符串和另一個標籤。 – Scotch 2013-05-07 05:49:50

回答

0

示例來自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(); 
} 
0

既然你說你有你的文件在你的應用程序資源中,你應該可以使用SoundPlayer做這樣的事情。我通過進入項目 - >屬性 - >資源來添加文件。

SoundPlayer sp = new SoundPlayer(Properties.Resources.chord); \\Change to what ever the name of your resource is 
sp.Play();