你能在c控制台上同时播放多首音轨吗



我正试图使用visual studio控制台制作一个rpg,但我无法让声音重叠。我希望我的背景音乐在上播放攻击声音或选择声音时播放

一个例子:

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
}

但我希望s继续比赛,而b在上比赛

使用SoundPlayer很难同时播放两个声音。

最简单的选择是依靠windows媒体播放器为您播放音频。添加对"Windows Media Player"的引用,然后使用以下代码:

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();
}
}

最新更新