我有这段代码:
MediaPlayer player = new System.Windows.Media.MediaPlayer();
bool playing = false;
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.D1)
{
if (label5.Text == "Waiting 01.wav")
{
MessageBox.Show("No wav loaded");
return;
}
pictureBox6.Image = Form1.Properties.Resources.white_square_button;
try
{
player.Open(new Uri(label37.Text));
player.Volume = (double)trackBar4.Value / 100;
playing = true;
player.Play();
}
catch (FileNotFoundException)
{
MessageBox.Show("File has been moved." + "\n" + "Please relocate it now!");
}
}
}
private void Window_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.D1)
{
pictureBox6.Image = Form1.Properties.Resources.black_square_button;
player.Stop();
player.Close();
playing = false;
}
}
问题是 .wav 文件不能完整播放,只是其中的一小部分。
当按下 D1 键直到它被释放时,它应该播放完成。
我究竟做错了什么?