【问题标题】:How to set the path of file stored in resources?如何设置存储在资源中的文件的路径?
【发布时间】:2014-04-01 14:44:31
【问题描述】:

我在我的应用程序的资源文件夹中存储了一个音频文件,但是当我使用以下路径时,我得到一个文件未找到异常。

有人可以解释这是否是在资源中引用文件的正确方法,还是我需要以不同方式设置路径?

这是将音频文件作为参数的代码:

SoundPlayer player = new SoundPlayer("Resources/Audio/punchSound.wav");
player.Load();
player.Play();

【问题讨论】:

    标签: c# wpf resources filepath


    【解决方案1】:

    你可以使用资源字符串:

    var music = Properties.Resources.punchSound;
    

    然后像这样使用 SoundPlayer:

    var player = new SoundPlayer(new MemoryStream(music));
    

    【讨论】:

    • 我试过这个但我得到这个错误:Error 3 Argument 1: cannot convert from 'System.IO.UnmanagedMemoryStream' to 'byte[]
    • 如果你取出new MemoryStream并传递路径变量就可以了。
    • 是的,我认为你的文件有FileType=binary
    猜你喜欢
    • 1970-01-01
    • 2013-03-23
    • 2023-01-27
    • 2019-12-14
    • 1970-01-01
    • 2013-02-09
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    相关资源
    最近更新 更多