繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM