Play simultaneously sound in C#

2019-04-17 05:57发布

I want in the win Application (written in C#), the sound (Wav Format) play as Background Sound, and mouse over Control play small wav sound File, and when Click on Button, Stop Background Sound and ... .
Thanks For your guidance.

标签: c# wav
3条回答
放我归山
2楼-- · 2019-04-17 06:11

You could try look around in the System.Media namespace. There is a SoundPlayer which is able to play Wave files.

To play a wav file in a loop, you can use the following code:

string filename = @"C:\WINDOWS\Media\notify.wav";
System.Media.SoundPlayer player = new System.Media.SoundPlayer(filename);
player.PlayLooping();

To stop playing, you simple call Stop():

player.Stop();

Play around a bit, there's more if you need it.

查看更多
干净又极端
3楼-- · 2019-04-17 06:13

Did you try to play each of them in a separate thread ?

查看更多
干净又极端
4楼-- · 2019-04-17 06:30

you can use Windows Media Player:

reference C:\Windows\System32\wmp.dll in your project

to launch a wav file:

WMPLib.WindowsMediaPlayer wmp = new WMPLib.WindowsMediaPlayerClass();
wmp.URL = "[wav file path]";

//then control the player with :

wmp.controls.play(), stop(), ...

for the second wav file, do the same thing with another instance of WindowsMediaPlayer etc...

you can also use Managed DirectX : Managed DirectX Tutorial Part 2

查看更多
登录 后发表回答