2013-02-26 21 views
0

我有Windows Phone 8应用程序,其中我想包括我自己的10个MP3。我将之列入/资产,但像哪里是我的静态内容在Windows Phone 8应用程序?

通话
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
    songs = store.GetFileNames("*.mp3").ToList(); 
    Console.WriteLine("Found {0} files ", songs.Count()); 
} 

保持返回该MP3音乐在我的商店#0

我试图把MP3歌曲的内涵,资产,资源和设定一直拷贝选项,但无济于事。

任何帮助将不胜感激。

+0

可能重复[如何从项目文件夹读取文件?(http://stackoverflow.com/问题/ 6531968 /如何读取文件从项目文件夹) – MarcinJuraszek 2013-02-26 20:57:33

+0

感谢指出,但我不能得到那个工作..这里是我使用的示例代码:string resourcePath = @“/ PhoneApp1; component /资源/“;装配组件= Assembly.GetExecutingAssembly(); string [] resources = assembly.GetManifestResourceNames(); 列表 files = new List (); 的foreach(在resourcePath字符串资源) { 如果(resource.EndsWith( “MP3”)){ // } } 我 – techtinkerer 2013-02-26 22:48:17

回答

1

,如果你设置你的文件为“嵌入的资源”,你可以得到的文件列表在运行时。

这里是你如何能做到这一点:

  1. 设置你的文件生成操作为“嵌入的资源”。
  2. 使用Assembly.GetCallingAssembly()。GetManifestResourceNames()来枚举资源名称

    string[] GetResourcesNames() 
    { 
        return Assembly.GetCallingAssembly().GetManifestResourceNames(); 
    } 
    
+0

此解决方案的缺点是文件被嵌入在DLL中,所以如果您拥有大量文件,则应用程序加载时间可能需要一段时间: - ( – 2013-02-26 22:48:27

+0

工作表示感谢。因此,如果我的应用程序将打破100或200个文件,那么最理想的方式是什么? – techtinkerer 2013-02-26 22:56:08

0

的文件不会被复制到独立存储为您的应用程序,但你可以通过URI让他们:

var mymp3file = new Uri("Assets/HomersDoh.mp3", UriKind.RelativeOrAbsolute); 
+0

需要加载了一堆的MP3。我的mp3列表可能会从10到50.所以,我不想通过文件名加载每个列表。我需要一个负载:“Assets/*。mp3”类型的解决方案 – techtinkerer 2013-02-26 22:33:28

相关问题