Reputation: 3279
I am using VS2010,C# to develop a Silverlight web based game. I want to play mp3 and this is my existing code:
StreamResourceInfo sri = Application.GetResourceStream(new Uri("/TennisSL;component/Images/idle.mp3", UriKind.Absolute));
m.SetSource(sri.Stream);
Scene.Children.Add(m);
m.Play(); // Plays the sound
The above code does not play as no sound is heard! What could be wrong? Is there anything missing?
This is my MediaElement object declaration at the top of program:
MediaElement m = new MediaElement();
Upvotes: 1
Views: 721
Reputation: 817
Add the following code :
m.Position = new TimeSpan(0,0,0);
then :
m.Play();
Thay way, you put the stream back to the start position and you can play the sound.
Upvotes: 2