I have Windows Phone 8 app in which I want to include my own 10 MP3s. I included them in /Assets, but a call like

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

keeps returning that the # of MP3s in my store is 0.

I tried putting the MP3s in Content, Assets, Resources and set Copy Always option, but to no avail.

Any help will be appreciated.

有帮助吗?

解决方案

if you set your files as "Embedded Resource", you can get a list of files at runtime.

Here is how you can do this:

  1. Set the Build Action of your files as "Embedded Resource".
  2. Use Assembly.GetCallingAssembly().GetManifestResourceNames() to enumerate the resources names

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

其他提示

The files is not copied to isolated store for your app, but you can get them by the uri:

var mymp3file = new Uri("Assets/HomersDoh.mp3", UriKind.RelativeOrAbsolute);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top