How play a .mp3 (or other) file in a UWP app?

Paule Paul picture Paule Paul · Sep 15, 2015 · Viewed 8.7k times · Source

I try this:

PlayMusic = new MediaElement();
PlayMusic.AudioCategory = Windows.UI.Xaml.Media.AudioCategory.Media;

PlayMusic.Source = new Uri(@"C:\Users\UserName\Desktop\C:\Users\user\Desktop\Kill The Alarm - Begin Again.mp3");
PlayMusic.Play();

No more error messages appear on the display (try catch runs clean through).

Sorry for the short description... I can read and understand English very well but it is difficult for me to talk and write.

Answer

Paule Paul picture Paule Paul · Sep 16, 2015

Every Windows Store App has three folders. A Local folder, a Roaming folder and a Temp folder. Each is accessed the same way. Local is meant to store assets in a local, application-specific folder.

Here is the answer:

StorageFolder Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                Folder = await Folder.GetFolderAsync("MyFolder");
                StorageFile sf = await Folder.GetFileAsync("MyFile.mp3");
                PlayMusic.SetSource(await sf.OpenAsync(FileAccessMode.Read), sf.ContentType);
                PlayMusic.Play();

MfG.