Play simultaneously sound in C#

谁说胖子不能爱 提交于 2019-12-14 00:28:04

问题


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.


回答1:


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




回答2:


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:


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



来源:https://stackoverflow.com/questions/1438377/play-simultaneously-sound-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!