1
votes

I'm trying to change Source property of MediaElement in my windows-phone application , I have two mp3 files in Assets file :

"/Assets/fail.mp3"

"/Assets/success.mp3"

when I set this proeperty in the designer to /Assets/success.mp3" for example, and invoke :

mediaElement.play(); 

the sound plays properly , but I want to change the source in my code and then play the sound again , I've tried these options :

mediaElement.Source = new Uri(BaseUri, "/Assets/fail.mp3");

mediaElement.Source = new Uri("ms-appx:///Assets/fail.mp3", UriKind.RelativeOrAbsolute);

mediaElement.Source = new Uri("/Assets/fail.mp3", UriKind.RelativeOrAbsolute);

mediaElement.Source = new Uri("/Assets/fail.mp3");

but none of them works I got no error with no sound !, any one have an Idea what to do ?

1
I could not reproduce your issue. I changed the source via mediaelement.Source = new Uri("ms-appx:///Assets/test.mp3");. It played well.Xie Steven
strange, did you immediately after this line tried , mediaelement.Play(); ?Karam Najjar
I even have not called Play() method. It also played successfully.Xie Steven
no I set autoplay=false, and tried to invoke Play() in codeKaram Najjar

1 Answers

0
votes

This is UWP? Maybe you need to update your resource strings as shown here: Uri syntax in ResourceDictionary Source (Universal Windows Platform)