Mehdi Bugnard
Mehdi Bugnard

Reputation: 3979

How set source of mediaElement in metro app c#?

I need set source of mediaElement control in my metro app for Windows 8 !

Here is my code :

string requestUrl = "ms-appx://ArcadiaDJ/Musique/test.mp3");
mediaElement_SoundEffect.Source = new Uri(requestUrl);   
mediaElement_SoundEffect.play();                       

I can set source but the mediaElement work not on play.. No music

i have found this solution but i need set source on loading page dynamically

var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

openPicker.SuggestedStartLocation =Windows.Storage.Pickers.PickerLocationId.MusicLibrary;

openPicker.FileTypeFilter.Add(".mp3");
openPicker.FileTypeFilter.Add(".wav");
file = await openPicker.PickSingleFileAsync();

mediaControl.SetSource(stream, file.ContentType);

Thank you

Upvotes: 0

Views: 8196

Answers (1)

JP Alioto
JP Alioto

Reputation: 45127

There are a couple things odd about your code. You set the Source property on an object called mediaElement_SoundEffect and then you call the .Play method on an object called mediaElement. So you should either fix your code or fix your example to be more accurate of what you're doing.

Also check out this answer I wrote a while back ... you should add the mediaElement to the Visual Tree.

Upvotes: 1

Related Questions