Wordastic for Windows 8 is close to completion. As a part of enhancing the app, I updated word count from 5k to 25k. I also added some sounds. Bach in the background and some sounds depending upon correct user guess.
So I did it all and I came to the sounds… figured out how to play background music but was not how to play multiple sounds. Here’s what I did
I added an instance of MediaElement and set the source to sound 1.
Set another 2 instance and set the source to sound 2 and sound 3.
And all I do is enable it / play it in code behind.
<MediaElement Name="mediaControl" IsLooping="True" AutoPlay="False" Height="0" Width="0" Source="Assets/bach-bwv848a-grant.mp3" /> <MediaElement Name="meYahoo" IsLooping="False" AutoPlay="False" Height="0" Width="0" Source="Assets/Yahoo.wav" /> <MediaElement Name="meSlip" IsLooping="False" AutoPlay="False" Height="0" Width="0" Source="Assets/FunnySlip.wav" />
mediaControl.AutoPlay = WordasticConfig.PlaySounds;
if(WordasticConfig.PlaySounds)
{
if (bValidWord)
meYahoo.Play();
else
meSlip.Play();
}
These links should help
Quickstart: Creating a media player app (Metro style apps using C#/VB/C++ and XAML)
Note: SoundEffect and SoundEffectInstance in WPDev etc where exposed by XNA. Windows 8 doesn’t directly support XNA so this is the only mechanism in Win RT unless you want to play with Direct X. If you want do so do, please have a look at Sharp DX which provides DX wrapper for .NET
Pingback: Windows 8 Developer Links – 2012-07-10Dan Rigby | Dan Rigby
Pingback: Play Sounds in Metro-style Applications