C#、VB.NET 使用System.Media.SoundPlayer播放音乐

时间:2023-03-09 13:04:06
C#、VB.NET 使用System.Media.SoundPlayer播放音乐

原文:C#、VB.NET 使用System.Media.SoundPlayer播放音乐

同步播放:

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @"d:/music/happy.wav";
player.Load();
player.Play();

C#、VB.NET 使用System.Media.SoundPlayer播放音乐 异步播放:

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @"d:/music/happy.wav";
player.LoadAsync();
player.PlaySync();

C#、VB.NET 使用System.Media.SoundPlayer播放音乐 循环播放:

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @"d:/music/happy.wav";
player.Load();
player.PlayLooping();