1

I'm trying to make an rpg using visual studio console and I can't get sounds to overlap. I want my background music to play while an attack sound or a select sound plays over it

An example:

Console.ReadLine();
soundplayer s = new soundplayer('path here');
soundplayer b = new soundplayer('path here');
s.play();
string f = console.readline();
if(f = "has")
{
   b.play
}

but I want s to keep playing while b plays over it

JayRyDee
  • 11
  • 1
  • Same question could be found her [How to play multiple sounds at once in C#](https://stackoverflow.com/questions/51215385/how-to-play-multiple-sounds-at-once-in-c-sharp) – Ibram Reda Nov 23 '21 at 21:24
  • Does this answer your question? [How to play multiple sounds at once in C#](https://stackoverflow.com/questions/51215385/how-to-play-multiple-sounds-at-once-in-c-sharp) – R.Abbasi Nov 23 '21 at 21:48

1 Answers1

0

It is hard for us to play two sounds at once using SoundPlayer.

The simplest option would be to depend on windows media player to play the audio for you. Add a reference to 'Windows Media Player' then use the following code:

static void Main(string[] args)
    {
        var bgm = new WMPLib.WindowsMediaPlayer();
        bgm.URL = @"path here";
        Console.WriteLine("bgm is playing");
        string f = Console.ReadLine();
        SoundPlayer b = new SoundPlayer(@"path here ");
        if (f == "has")
        {
            b.Play();
            Console.ReadLine();
        }
    }
Jingmiao Xu-MSFT
  • 2,076
  • 1
  • 3
  • 10