![](/img/trans.png)
[英]I can't find the System.Media namespace in Visual Studio 2019
[英]Trying to add System.Media namespace to a Visual Studio Code Project
我目前正在從事一個小型游戲項目,目標是使用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örnuniversity \\ Project Folder \\ Csharp Projects \\ RandomProjects \\ AntFightingSim \\ AntFightingSim的.csproj]
但是關於如何將所述程序集引用獲取到Visual Studio Code中,我絲毫沒有任何線索。 到目前為止,Google只給了我2004-2015年Visual Studio的結果。
這把我引到這里。 出於絕望,我第一次在StackOverflow中撰寫並發布了一個問題。 有沒有一種方法可以添加所說的名稱空間/不同的名稱空間,還是在Visual Studio Code中是不可能的? 上帝的速度。
編輯:
經過一番搜索,我發現NuGet列表中不存在System.Media
命名空間及其程序集(PresentationCore.dll)。
由於我缺乏適當的程序集知識,可以幫助我實現目標,因此現在我需要詢問System.Media
及其播放音頻文件的能力。
您需要引用包含System.Media的程序集。 可以在這里找到詳細的指南: https : //stackoverflow.com/a/42399545/1621861
如果您的環境是.NET核心,則需要在.NET Framework中構建應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.