I try this:
PlayMusic = new MediaElement();
PlayMusic.AudioCategory = Windows.UI.Xaml.Media.AudioCategory.Media;
PlayMusic.Source = new Uri(@\"C:\\Users\\Us
Put mySong.mp3 in your Assets folder. Then in Visual Studio, right click on your Assets folder and select "add existing item". Add mySong.mp3 FROM your Assets folder. In XAML, add a player:
<MediaElement x:Name="myPlayer"
AutoPlay="True" />
In c#, mySong.mp3 will play when you set the source:
Uri newuri = new Uri("ms-appx:///Assets/mySong.mp3");
myPlayer.Source = newuri;
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.
Register the MediaFailed-Event of the MediaElement and check if it gets raised. The ExceptionRoutedEventArgs passed to the method, should contain information about, why the file cannot be played.
You cannot just read any file on your file system like this with windows store applications.
If you just want to test it:
What you probably want to do is explained in the section, Read Local files w/o a Picker from this article. This might also be helpful.