尝试将 System.Media 命名空间添加到 Visual Studio 代码项目中



我目前正在做一个小型游戏项目,目标是使用 CSharp 制作一个程序。

该项目是一个控制台应用程序,具有基于文本的菜单和启动屏幕,我目前的目标是在应用程序启动时添加音频播放。

我已经研究了我需要什么才能播放音乐,但我缺乏这样做的组装。

这是我的代码:

using System;
using System.Media;
namespace AntFightingSim
{
class Program
{
public static string[] menuButtons = new string[] { " Fight!(Press Space) ", " Exit The Game!(Press Escape)" };
public static bool appRunning = true;
public static string path;
public static int buttonCount = 0;
static void Main(string[] args)
{
path = "C:/Users/Spyros/OneDrive - Södertörn university/Project Folder/Csharp Projects/RandomProjects/AntFightingSim/Resources/Dragon Ball FighterZ - OST - Loading Theme.wav";
MenuMethod();
}
static void MenuMethod()
{
while (appRunning && buttonCount != 1)
{
SoundPlayer player = new SoundPlayer();
player.SoundLocation = path;
player.Load();
player.PlayLooping();
Console.WriteLine("ANT INVESTMENT SIMULATOR");
Console.WriteLine("Press any key to start");
Console.Write("n");
Console.Write("n");
Console.ReadKey(true);
Console.Write(menuButtons[0]);
Console.Write(menuButtons[1]);
ConsoleKeyInfo info = Console.ReadKey(true);
if (info.Key == ConsoleKey.Spacebar)
StartGame();
else if (info.Key == ConsoleKey.Escape)
{
buttonCount++;
}
}
while (appRunning && buttonCount == 1)
{
Console.Write("n");
Console.Write("n");
Console.WriteLine("Are you sure about that?(Press Escape Again)");
ConsoleKeyInfo info = Console.ReadKey(true);
if (info.Key == ConsoleKey.Escape)
{
appRunning = false;
}
}
}

static void StartGame()
{
buttonCount = 1;
}
}
static class Ant
{
public static int strength;
public static int dexterity;
public static int agility;
public static string name;
public static bool gender;
}
}

我用谷歌搜索了错误:

命名空间"系统"中不存在类型或命名空间名称"媒体"(是否缺少程序集引用?( [C:\Users\Spyros\OneDrive - Södertörn university\Project Folder\Csharp Projects\RandomProjects\AntFightingSim\AntFightingSim.csproj]

但我对如何将所述程序集引用获取到 Visual Studio 代码中一无所知。到目前为止,谷歌只给了我2004-2015年的Visual Studio结果。

这让我来到这里。我第一次出于绝望在StackOverflow上写并发布了一个问题。有没有办法添加所述命名空间/不同的命名空间,还是在Visual Studio Code中是不可能的?神速。

编辑:

经过一番搜索,我发现 NuGet 列表中不存在System.Media命名空间及其程序集 (PresentationCore.dll(。

由于我缺乏帮助我实现目标的正确程序集的知识,我现在需要要求一个 altenative 来System.Media及其播放音频文件的能力。

您需要引用包含 System.Media 的程序集。详细指南可以在这里找到:https://stackoverflow.com/a/42399545/1621861

如果你的环境是.NET core,你想在.NET Framework中构建应用程序。

最新更新