Playing more than one MediaElement using Windows Phone 7 and Silverlight.

On Windows Phone 7, MediaElement is limited to a single instance. This means that if you were to create a game and you wished to play multiple sounds at the same time, some of the sounds will not play at all or the sounds will sound all scratchy. So to overcome this, just add the Microsoft.Xna.Framework.Audio namespace (in Microsoft.Xna.Framework.dll) and then in your code have something along these lines.

private void PlayNewFile(string media)
{
    var stream = TitleContainer.OpenStream(media);
    var effect = SoundEffect.FromStream(stream);
    effect.Play();
}

The one problem you will face though is that you are now limited to playing .wav files.

The final thing you need to do is to make sure you right click on your audio files then Properties and have the Build action to content and Copy to output directory set to copy to output folder.

Tags: ,
Categories: Silverlight

Permalink E-mail | Kick it! | DZone it! | del.icio.us Comments (0) Post RSSRSS comment feed

Welcome

This blog will serve as a basis for Windows Phone 7 tutorials and possibly in the future, Android tutorials, mostly concentrating on utilizing 2D within games using XNA and BOX2D (The XNA port). There is a lack of tutorials on the internet that focus on Windows Phone 7, so I thought why not create a blog and help others further understand the vast possibilties these applications have to offer. I will be providing concept tutorials with the occasional release of the source code for a couple of games I am working on. If you would like to see specific tutorials or want to know how to do something, feel free to contact me using the contact form and I’ll see what I can do.

Tags:
Categories: Misc

Permalink E-mail | Kick it! | DZone it! | del.icio.us Comments (0) Post RSSRSS comment feed