Reputation: 1218
I use this code for playing single mp3 audio file and i used MediaElement:
Uri Path = new Uri("AudioFiles/music.mp3", UriKind.Relative);
SoundPlayer.Source = Path;
SoundPlayer.Play();
but i got this error :
An exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll but was not handled in user code
Additional information: The given System.Uri cannot be converted into a Windows.Foundation.Uri.
what is wrong with that ?
Thanks
Upvotes: 0
Views: 149
Reputation: 29792
Depending on the location of your file, you may need a different Uri scheme. Try:
SoundPlayer.Source = new Uri(@"ms-appdata:///local/AudioFiles/music.mp3"); // if your file is in IsolatedStorage
SoundPlayer.Source = new Uri(@"ms-appx:///AudioFiles/music.mp3"); // if your file is a Build-in content
Note also that you don't need SoundPlayer.Play()
if SoundPlayer.Autoplay
is set to true (default setting). In case it's false - you will have to start to play manually in MediaOpened
event not just after setting the Source
.
Upvotes: 1
Reputation: 932
Uri Path = new Uri("/AudioFiles/music.mp3", UriKind.Relative);
You are forgetting a "/" before AudioFiles.
Upvotes: 1