0
我有這個功能,我必須使用MediaPlayer,因爲我必須一起播放更多聲音。這段代碼可以工作,但聲音並不停止在關鍵幀上(我嘗試了一些代碼,但沒有工作)。我怎樣才能做到stopSound功能? Thank'you!如何用MediaPlayer c停止聲音#
private void Form1_KeyDown(object sender, KeyPressEventArgs e)
{
[...] // Other code
playSound(key, name);
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
[...] // Other code
stopSound(key, name);
}
private void playSound(string name)
{
[...] // Other code
string url = Application.StartupPath + "\\notes\\" + name + ".wav";
var sound = new System.Windows.Media.MediaPlayer();
sound.Open(new Uri(url));
sound.play();
}
private void stopSound(string name)
{
???
}
入住這https://msdn.microsoft.com/en-us/library/system.windows.media.mediaplayer.stop(v=vs.110).aspx – PiLHA
當然,該代碼有效。但現在我不得不改變上面的代碼(由於線程),所以你的代碼不再工作。看看我的最後一個問題。 – Poppo