Before you start playing sound, you should be familiar with the PlaySound () function of the Win32 API.
private SoundPlayer player = new SoundPlayer();
private void AsyncBtn_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
player.LoadCompleted += new AsyncCompletedEventHandler(LoadCompleted);
player.SoundLocation = openFileDialog1.FileName;
player.LoadAsync();
}
}
private void LoadCompleted(object sender, AsyncCompletedEventArgs args)
{
player.Play();
}
source
share