winform项目中播放音频文件

OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Audio Files (.wav)|*.wav";


if(dialog.ShowDialog() == DialogResult.OK)
{
    string path = dialog.FileName;

playSound(path);

}

private void playSound(string path)
{
    System.Media.SoundPlayer player =  new System.Media.SoundPlayer();
    player.SoundLocation = path;
    player.Load();
    player.Play();
}

你可能感兴趣的:(WinForm)