Playing 2 sounds together at same time

前端 未结 3 934
野趣味
野趣味 2021-01-05 02:18

Designing a game for any laptop:

I want to play 2 sounds at the same time! A background music and a sound when pressing on a button!

Using System.Media

3条回答
  •  再見小時候
    2021-01-05 03:15

    Using (WMPLib) Windows Media Player Library you can do this easily. Keep Your file in Debug/Sound folder and follow the following code. This will run 2 file simultaneously. To Add WMPLib in your project add it by NuGet Package Manager.

     WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
     WMPLib.WindowsMediaPlayer wplayer2 = new WMPLib.WindowsMediaPlayer();     
     string play_string = "be.mp3";
     wplayer.URL = @"SOUND/" + play_string;
     wplayer.controls.play();
     string play_string2 = "ba.mp3";
     wplayer2.URL = @"SOUND/" + play_string2;
     wplayer2.controls.play();
    

提交回复
热议问题