简体   繁体   中英

Is there any way i can somehow have two sounds play at once in c# console app?

Im working on a text game in c#. But i wanted to have multiple sounds at once. So i tried to use SoundPlayer. But whenever i loaded up another sound, it just cut off the other one. If that makes sense. Im new to programming, so please try to explain like im 5!

If you have say 2 different sounds that you want to play together.

Below example is for Console.Beep, which can be extended to other sounds

You can replace Console.Beep() with other sounds that you want to play


using System.Threading;
using System.Threading.Tasks;

Add above 2 to your Namespace

//First sound you want to play

var first = await Task.Run(() => Console.Beep());

//Optional Delay
await Task.Delay(500); //Does not halt the current thread

//Second sound you want to play
var second = await Task.Run(() => Console.Beep(500,1000));

I had been struggling with the same issue.....

The short answer is you can't. The system will only permit one channel to the sound interface within any given process. As such, when you start a new sound, the previous one terminates.

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