简体   繁体   中英

How to play sound in a specific sound card

I'm developping in an application in Csharp and I want to read a sound file in an external sound card,is there a function which give me the possibility to play sound using the name of the sound card and the name of the audio file. So if I want to create 3 buttons and I have 3 sound cards and each button is related to a sound card (for example button1 is related to sound card1...) which code can help me to play an audio file in the specific sound card??? Please give me a code,because I'm preparing a general alarm and such code will help me alot.

Thank you in advance

I'm not aware of a way of doing this within .net framework. But you can use the direct sound api:

DirectSoundEnumerate to find available devices and then use the guid of the desired device in DirectSoundCreate .

Please, do not change the default device of the PC by messing around with the registry (or at all). This would be a major annoyance for your users.

Here 's some sample code for playing a sound in DirectX natively.

You could check out Managed DirectX and/or XNA. It may make life easier for you by providing you with a managed wrapper for DirectSound.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM